2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "luci/IR/Nodes/CircleDepthwiseConv2D.h"
19 #include "luci/IR/CircleDialect.h"
20 #include "luci/IR/CircleNodeVisitor.h"
22 #include <gtest/gtest.h>
24 TEST(CircleDepthwiseConv2DTest, constructor_P)
26 luci::CircleDepthwiseConv2D dw_conv2d_node;
28 ASSERT_EQ(luci::CircleDialect::get(), dw_conv2d_node.dialect());
29 ASSERT_EQ(luci::CircleOpcode::DEPTHWISE_CONV_2D, dw_conv2d_node.opcode());
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());
43 TEST(CircleDepthwiseConv2DTest, input_NEG)
45 luci::CircleDepthwiseConv2D dw_conv2d_node;
46 luci::CircleDepthwiseConv2D node;
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());
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());
62 dw_conv2d_node.padding(luci::Padding::SAME);
63 ASSERT_NE(luci::Padding::UNDEFINED, dw_conv2d_node.padding());
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());
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());
75 dw_conv2d_node.fusedActivationFunction(luci::FusedActFunc::RELU);
76 ASSERT_NE(luci::FusedActFunc::UNDEFINED, dw_conv2d_node.fusedActivationFunction());
79 TEST(CircleDepthwiseConv2DTest, arity_NEG)
81 luci::CircleDepthwiseConv2D dw_conv2d_node;
83 ASSERT_NO_THROW(dw_conv2d_node.arg(2));
84 ASSERT_THROW(dw_conv2d_node.arg(3), std::out_of_range);
87 TEST(CircleDepthwiseConv2DTest, visit_mutable_NEG)
89 struct TestVisitor final : public luci::CircleNodeMutableVisitor<void>
93 luci::CircleDepthwiseConv2D dw_conv2d_node;
96 ASSERT_THROW(dw_conv2d_node.accept(&tv), std::exception);
99 TEST(CircleDepthwiseConv2DTest, visit_NEG)
101 struct TestVisitor final : public luci::CircleNodeVisitor<void>
105 luci::CircleDepthwiseConv2D dw_conv2d_node;
108 ASSERT_THROW(dw_conv2d_node.accept(&tv), std::exception);