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