Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / compiler / luci / lang / src / Nodes / CircleDepthwiseConv2D.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/CircleDepthwiseConv2D.h"
18
19 #include "luci/IR/CircleDialect.h"
20 #include "luci/IR/CircleNodeVisitor.h"
21
22 #include <gtest/gtest.h>
23
24 TEST(CircleDepthwiseConv2DTest, constructor_P)
25 {
26   luci::CircleDepthwiseConv2D dw_conv2d_node;
27
28   ASSERT_EQ(luci::CircleDialect::get(), dw_conv2d_node.dialect());
29   ASSERT_EQ(luci::CircleOpcode::DEPTHWISE_CONV_2D, dw_conv2d_node.opcode());
30
31   ASSERT_EQ(nullptr, dw_conv2d_node.input());
32   ASSERT_EQ(nullptr, dw_conv2d_node.filter());
33   ASSERT_EQ(nullptr, dw_conv2d_node.bias());
34   ASSERT_EQ(luci::Padding::UNDEFINED, dw_conv2d_node.padding());
35   ASSERT_EQ(1, dw_conv2d_node.stride()->h());
36   ASSERT_EQ(1, dw_conv2d_node.stride()->w());
37   ASSERT_EQ(1, dw_conv2d_node.dilation()->h());
38   ASSERT_EQ(1, dw_conv2d_node.dilation()->w());
39   ASSERT_EQ(0, dw_conv2d_node.depthMultiplier());
40   ASSERT_EQ(luci::FusedActFunc::UNDEFINED, dw_conv2d_node.fusedActivationFunction());
41 }
42
43 TEST(CircleDepthwiseConv2DTest, input_NEG)
44 {
45   luci::CircleDepthwiseConv2D dw_conv2d_node;
46   luci::CircleDepthwiseConv2D node;
47
48   dw_conv2d_node.input(&node);
49   dw_conv2d_node.filter(&node);
50   dw_conv2d_node.bias(&node);
51   ASSERT_NE(nullptr, dw_conv2d_node.input());
52   ASSERT_NE(nullptr, dw_conv2d_node.filter());
53   ASSERT_NE(nullptr, dw_conv2d_node.bias());
54
55   dw_conv2d_node.input(nullptr);
56   dw_conv2d_node.filter(nullptr);
57   dw_conv2d_node.bias(nullptr);
58   ASSERT_EQ(nullptr, dw_conv2d_node.input());
59   ASSERT_EQ(nullptr, dw_conv2d_node.filter());
60   ASSERT_EQ(nullptr, dw_conv2d_node.bias());
61
62   dw_conv2d_node.padding(luci::Padding::SAME);
63   ASSERT_NE(luci::Padding::UNDEFINED, dw_conv2d_node.padding());
64
65   dw_conv2d_node.stride()->h(2);
66   dw_conv2d_node.stride()->w(2);
67   ASSERT_EQ(2, dw_conv2d_node.stride()->h());
68   ASSERT_EQ(2, dw_conv2d_node.stride()->w());
69
70   dw_conv2d_node.dilation()->h(2);
71   dw_conv2d_node.dilation()->w(2);
72   ASSERT_EQ(2, dw_conv2d_node.dilation()->h());
73   ASSERT_EQ(2, dw_conv2d_node.dilation()->w());
74
75   dw_conv2d_node.fusedActivationFunction(luci::FusedActFunc::RELU);
76   ASSERT_NE(luci::FusedActFunc::UNDEFINED, dw_conv2d_node.fusedActivationFunction());
77 }
78
79 TEST(CircleDepthwiseConv2DTest, arity_NEG)
80 {
81   luci::CircleDepthwiseConv2D dw_conv2d_node;
82
83   ASSERT_NO_THROW(dw_conv2d_node.arg(2));
84   ASSERT_THROW(dw_conv2d_node.arg(3), std::out_of_range);
85 }
86
87 TEST(CircleDepthwiseConv2DTest, visit_mutable_NEG)
88 {
89   struct TestVisitor final : public luci::CircleNodeMutableVisitor<void>
90   {
91   };
92
93   luci::CircleDepthwiseConv2D dw_conv2d_node;
94
95   TestVisitor tv;
96   ASSERT_THROW(dw_conv2d_node.accept(&tv), std::exception);
97 }
98
99 TEST(CircleDepthwiseConv2DTest, visit_NEG)
100 {
101   struct TestVisitor final : public luci::CircleNodeVisitor<void>
102   {
103   };
104
105   luci::CircleDepthwiseConv2D dw_conv2d_node;
106
107   TestVisitor tv;
108   ASSERT_THROW(dw_conv2d_node.accept(&tv), std::exception);
109 }