Imported Upstream version 1.21.0
[platform/core/ml/nnfw.git] / compiler / luci / partition / src / Nodes / CircleSparseToDense.test.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *    http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "luci/ConnectNode.h"
18
19 #include "ConnectNode.test.h"
20
21 #include <luci/Service/CircleNodeClone.h>
22
23 #include <gtest/gtest.h>
24
25 namespace
26 {
27
28 using namespace luci::test;
29
30 class NodeGraphlet : public NodeGraphletT<luci::CircleSparseToDense>
31 {
32 public:
33   NodeGraphlet() = default;
34 };
35
36 class TestNodeGraph : public TestIsOGraph<4>, public NodeGraphlet
37 {
38 public:
39   TestNodeGraph() = default;
40
41 public:
42   void init(const ShapeU32 shape)
43   {
44     TestIsOGraph<4>::init({shape, shape, shape, shape}, shape);
45     NodeGraphlet::init(g());
46
47     node()->indices(input(0));
48     node()->output_shape(input(1));
49     node()->values(input(2));
50     node()->default_value(input(3));
51
52     output()->from(node());
53   }
54 };
55
56 } // namespace
57
58 TEST(ConnectNodeTest, connect_SparseToDense)
59 {
60   TestNodeGraph tng;
61   tng.init({2, 3});
62
63   ConnectionTestHelper cth;
64   cth.prepare_inputs(&tng);
65
66   auto *node = tng.node();
67   ASSERT_NO_THROW(loco::must_cast<luci::CircleSparseToDense *>(node));
68
69   auto *clone = luci::clone_node(node, cth.graph_clone());
70   ASSERT_NO_THROW(loco::must_cast<luci::CircleSparseToDense *>(clone));
71
72   cth.clone_connect(node, clone);
73
74   ASSERT_EQ(4, clone->arity());
75   ASSERT_EQ(cth.inputs(0), clone->arg(0));
76   ASSERT_EQ(cth.inputs(1), clone->arg(1));
77   ASSERT_EQ(cth.inputs(2), clone->arg(2));
78   ASSERT_EQ(cth.inputs(3), clone->arg(3));
79 }
80
81 TEST(ConnectNodeTest, connect_SparseToDense_NEG)
82 {
83   TestNodeGraph tng;
84   tng.init({2, 3});
85
86   ConnectionTestHelper cth;
87   cth.prepare_inputs_miss(&tng);
88
89   auto *node = tng.node();
90   ASSERT_NO_THROW(loco::must_cast<luci::CircleSparseToDense *>(node));
91
92   auto *clone = luci::clone_node(node, cth.graph_clone());
93   ASSERT_NO_THROW(loco::must_cast<luci::CircleSparseToDense *>(clone));
94
95   EXPECT_ANY_THROW(cth.clone_connect(node, clone));
96 }