Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / compiler / luci / lang / src / Nodes / CircleWhile.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/CircleWhile.h"
18
19 #include "luci/IR/CircleDialect.h"
20 #include "luci/IR/CircleNodeVisitor.h"
21
22 #include <gtest/gtest.h>
23
24 TEST(CircleWhileTest, constructor)
25 {
26   luci::CircleWhile while_node(2, 2);
27
28   ASSERT_EQ(luci::CircleDialect::get(), while_node.dialect());
29   ASSERT_EQ(luci::CircleOpcode::WHILE, while_node.opcode());
30
31   ASSERT_EQ(2, while_node.input_count());
32   ASSERT_EQ(2, while_node.output_count());
33
34   ASSERT_EQ(nullptr, while_node.input(0));
35   ASSERT_EQ(nullptr, while_node.input(1));
36
37   ASSERT_EQ(-1, while_node.cond_branch());
38   ASSERT_EQ(-1, while_node.body_branch());
39 }
40
41 TEST(CircleWhileTestDeath, invalid_arity_NEG)
42 {
43   ASSERT_DEBUG_DEATH(luci::CircleWhile very_long_name_while_node(0, 1), "");
44
45   SUCCEED();
46 }
47
48 TEST(CircleWhileTestDeath, invalid_output_count_NEG)
49 {
50   ASSERT_DEBUG_DEATH(luci::CircleWhile while_node(2, 0), "");
51
52   SUCCEED();
53 }
54
55 TEST(CircleWhileTestDeath, invalid_input_get_index_NEG)
56 {
57   luci::CircleWhile while_node(2, 2);
58
59   EXPECT_ANY_THROW(while_node.input(100));
60 }
61
62 TEST(CircleWhileTestDeath, invalid_input_set_index_NEG)
63 {
64   luci::CircleWhile while_node(2, 2);
65
66   EXPECT_ANY_THROW(while_node.input(100, nullptr));
67 }
68
69 TEST(CircleWhileTestDeath, visit_mutable_NEG)
70 {
71   struct TestVisitor final : public luci::CircleNodeMutableVisitor<void>
72   {
73   };
74
75   luci::CircleWhile while_node(2, 2);
76
77   TestVisitor tv;
78   ASSERT_THROW(while_node.accept(&tv), std::exception);
79 }
80
81 TEST(CircleWhileTestDeath, visit_NEG)
82 {
83   struct TestVisitor final : public luci::CircleNodeVisitor<void>
84   {
85   };
86
87   luci::CircleWhile while_node(2, 2);
88
89   TestVisitor tv;
90   ASSERT_THROW(while_node.accept(&tv), std::exception);
91 }