Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / compiler / luci / lang / src / Nodes / CircleReshape.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/CircleReshape.h"
18
19 #include "luci/IR/CircleDialect.h"
20 #include "luci/IR/CircleNodeVisitor.h"
21
22 #include <gtest/gtest.h>
23
24 TEST(CircleReshapeTest, constructor_P)
25 {
26   luci::CircleReshape reshape;
27
28   ASSERT_EQ(luci::CircleDialect::get(), reshape.dialect());
29   ASSERT_EQ(luci::CircleOpcode::RESHAPE, reshape.opcode());
30
31   ASSERT_EQ(nullptr, reshape.tensor());
32   ASSERT_EQ(nullptr, reshape.shape());
33   ASSERT_EQ(0, reshape.newShape()->rank());
34 }
35
36 TEST(CircleReshapeTest, alloc_new_shape_P)
37 {
38   luci::CircleReshape reshape;
39
40   reshape.newShape()->rank(2);
41   ASSERT_EQ(2, reshape.newShape()->rank());
42
43   reshape.newShape()->dim(0) = 0;
44   reshape.newShape()->dim(1) = 1;
45
46   auto &const_reshape = const_cast<const luci::CircleReshape &>(reshape);
47   ASSERT_EQ(0, const_reshape.newShape()->dim(0));
48   ASSERT_EQ(1, const_reshape.newShape()->dim(1));
49 }
50
51 TEST(CircleReshapeTest, input_NEG)
52 {
53   luci::CircleReshape reshape_node;
54   luci::CircleReshape node;
55
56   reshape_node.tensor(&node);
57   reshape_node.shape(&node);
58   ASSERT_NE(nullptr, reshape_node.tensor());
59   ASSERT_NE(nullptr, reshape_node.shape());
60
61   reshape_node.tensor(nullptr);
62   reshape_node.shape(nullptr);
63   ASSERT_EQ(nullptr, reshape_node.tensor());
64   ASSERT_EQ(nullptr, reshape_node.shape());
65 }
66
67 TEST(CircleReshapeTest, arity_NEG)
68 {
69   luci::CircleReshape reshape_node;
70
71   ASSERT_NO_THROW(reshape_node.arg(1));
72   ASSERT_THROW(reshape_node.arg(2), std::out_of_range);
73 }
74
75 TEST(CircleReshapeTest, visit_mutable_NEG)
76 {
77   struct TestVisitor final : public luci::CircleNodeMutableVisitor<void>
78   {
79   };
80
81   luci::CircleReshape reshape_node;
82
83   TestVisitor tv;
84   ASSERT_THROW(reshape_node.accept(&tv), std::exception);
85 }
86
87 TEST(CircleReshapeTest, visit_NEG)
88 {
89   struct TestVisitor final : public luci::CircleNodeVisitor<void>
90   {
91   };
92
93   luci::CircleReshape reshape_node;
94
95   TestVisitor tv;
96   ASSERT_THROW(reshape_node.accept(&tv), std::exception);
97 }