Imported Upstream version 1.21.0
[platform/core/ml/nnfw.git] / compiler / luci / partition / src / Nodes / CircleMaxPool2D.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::CircleMaxPool2D>
31 {
32 public:
33   NodeGraphlet() = default;
34
35 public:
36   void init(loco::Graph *g) override
37   {
38     NodeGraphletT<luci::CircleMaxPool2D>::init(g);
39
40     _node->fusedActivationFunction(luci::FusedActFunc::RELU);
41     _node->padding(luci::Padding::VALID);
42   }
43 };
44
45 class TestNodeGraph : public TestIOGraph, public NodeGraphlet
46 {
47 public:
48   TestNodeGraph() = default;
49
50 public:
51   void init(const ShapeU32 shape)
52   {
53     TestIOGraph::init(shape, shape);
54     NodeGraphlet::init(g());
55
56     node()->value(input());
57
58     output()->from(node());
59   }
60 };
61
62 } // namespace
63
64 TEST(ConnectNodeTest, connect_MaxPool2D)
65 {
66   TestNodeGraph tng;
67   tng.init({2, 3});
68
69   ConnectionTestHelper cth;
70   cth.prepare_inputs(&tng);
71
72   auto *node = tng.node();
73   ASSERT_NO_THROW(loco::must_cast<luci::CircleMaxPool2D *>(node));
74
75   auto *clone = luci::clone_node(node, cth.graph_clone());
76   ASSERT_NO_THROW(loco::must_cast<luci::CircleMaxPool2D *>(clone));
77
78   cth.clone_connect(node, clone);
79
80   ASSERT_EQ(1, clone->arity());
81   ASSERT_EQ(cth.inputs(0), clone->arg(0));
82 }
83
84 TEST(ConnectNodeTest, connect_MaxPool2D_NEG)
85 {
86   TestNodeGraph tng;
87   tng.init({2, 3});
88
89   ConnectionTestHelper cth;
90   cth.prepare_inputs_miss(&tng);
91
92   auto *node = tng.node();
93   ASSERT_NO_THROW(loco::must_cast<luci::CircleMaxPool2D *>(node));
94
95   auto *clone = luci::clone_node(node, cth.graph_clone());
96   ASSERT_NO_THROW(loco::must_cast<luci::CircleMaxPool2D *>(clone));
97
98   EXPECT_ANY_THROW(cth.clone_connect(node, clone));
99 }