Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / compiler / luci / lang / src / Nodes / CircleMaxPool2D.test.cpp
1 /*
2  * Copyright (c) 2020 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/IR/Nodes/CircleMaxPool2D.h"
18
19 #include "luci/IR/CircleDialect.h"
20 #include "luci/IR/CircleNodeVisitor.h"
21
22 #include <gtest/gtest.h>
23
24 TEST(CircleMaxPool2DTest, constructor_P)
25 {
26   luci::CircleMaxPool2D maxpool2d_node;
27
28   ASSERT_EQ(luci::CircleDialect::get(), maxpool2d_node.dialect());
29   ASSERT_EQ(luci::CircleOpcode::MAX_POOL_2D, maxpool2d_node.opcode());
30
31   ASSERT_EQ(nullptr, maxpool2d_node.value());
32   ASSERT_EQ(luci::Padding::UNDEFINED, maxpool2d_node.padding());
33   ASSERT_EQ(1, maxpool2d_node.filter()->h());
34   ASSERT_EQ(1, maxpool2d_node.filter()->w());
35   ASSERT_EQ(1, maxpool2d_node.stride()->h());
36   ASSERT_EQ(1, maxpool2d_node.stride()->w());
37 }
38
39 TEST(CircleMaxPool2DTest, input_NEG)
40 {
41   luci::CircleMaxPool2D maxpool2d_node;
42   luci::CircleMaxPool2D node;
43
44   maxpool2d_node.value(&node);
45   ASSERT_NE(nullptr, maxpool2d_node.value());
46
47   maxpool2d_node.value(nullptr);
48   ASSERT_EQ(nullptr, maxpool2d_node.value());
49
50   maxpool2d_node.filter()->h(2);
51   maxpool2d_node.filter()->w(2);
52   maxpool2d_node.stride()->h(2);
53   maxpool2d_node.stride()->w(2);
54   ASSERT_NE(1, maxpool2d_node.filter()->h());
55   ASSERT_NE(1, maxpool2d_node.filter()->w());
56   ASSERT_NE(1, maxpool2d_node.stride()->h());
57   ASSERT_NE(1, maxpool2d_node.stride()->w());
58 }
59
60 TEST(CircleMaxPool2DTest, arity_NEG)
61 {
62   luci::CircleMaxPool2D maxpool2d_node;
63
64   ASSERT_NO_THROW(maxpool2d_node.arg(0));
65   ASSERT_THROW(maxpool2d_node.arg(1), std::out_of_range);
66 }
67
68 TEST(CircleMaxPool2DTest, visit_mutable_NEG)
69 {
70   struct TestVisitor final : public luci::CircleNodeMutableVisitor<void>
71   {
72   };
73
74   luci::CircleMaxPool2D maxpool2d_node;
75
76   TestVisitor tv;
77   ASSERT_THROW(maxpool2d_node.accept(&tv), std::exception);
78 }
79
80 TEST(CircleMaxPool2DTest, visit_NEG)
81 {
82   struct TestVisitor final : public luci::CircleNodeVisitor<void>
83   {
84   };
85
86   luci::CircleMaxPool2D maxpool2d_node;
87
88   TestVisitor tv;
89   ASSERT_THROW(maxpool2d_node.accept(&tv), std::exception);
90 }