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