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/CircleWhile.h"
19 #include "luci/IR/CircleDialect.h"
20 #include "luci/IR/CircleNodeVisitor.h"
22 #include <gtest/gtest.h>
24 TEST(CircleWhileTest, constructor)
26 luci::CircleWhile while_node(2, 2);
28 ASSERT_EQ(luci::CircleDialect::get(), while_node.dialect());
29 ASSERT_EQ(luci::CircleOpcode::WHILE, while_node.opcode());
31 ASSERT_EQ(2, while_node.input_count());
32 ASSERT_EQ(2, while_node.output_count());
34 ASSERT_EQ(nullptr, while_node.input(0));
35 ASSERT_EQ(nullptr, while_node.input(1));
37 ASSERT_EQ(-1, while_node.cond_branch());
38 ASSERT_EQ(-1, while_node.body_branch());
41 TEST(CircleWhileTestDeath, invalid_arity_NEG)
43 ASSERT_DEBUG_DEATH(luci::CircleWhile very_long_name_while_node(0, 1), "");
48 TEST(CircleWhileTestDeath, invalid_output_count_NEG)
50 ASSERT_DEBUG_DEATH(luci::CircleWhile while_node(2, 0), "");
55 TEST(CircleWhileTestDeath, invalid_input_get_index_NEG)
57 luci::CircleWhile while_node(2, 2);
59 EXPECT_ANY_THROW(while_node.input(100));
62 TEST(CircleWhileTestDeath, invalid_input_set_index_NEG)
64 luci::CircleWhile while_node(2, 2);
66 EXPECT_ANY_THROW(while_node.input(100, nullptr));
69 TEST(CircleWhileTestDeath, visit_mutable_NEG)
71 struct TestVisitor final : public luci::CircleNodeMutableVisitor<void>
75 luci::CircleWhile while_node(2, 2);
78 ASSERT_THROW(while_node.accept(&tv), std::exception);
81 TEST(CircleWhileTestDeath, visit_NEG)
83 struct TestVisitor final : public luci::CircleNodeVisitor<void>
87 luci::CircleWhile while_node(2, 2);
90 ASSERT_THROW(while_node.accept(&tv), std::exception);