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/CircleReshape.h"
19 #include "luci/IR/CircleDialect.h"
20 #include "luci/IR/CircleNodeVisitor.h"
22 #include <gtest/gtest.h>
24 TEST(CircleReshapeTest, constructor_P)
26 luci::CircleReshape reshape;
28 ASSERT_EQ(luci::CircleDialect::get(), reshape.dialect());
29 ASSERT_EQ(luci::CircleOpcode::RESHAPE, reshape.opcode());
31 ASSERT_EQ(nullptr, reshape.tensor());
32 ASSERT_EQ(nullptr, reshape.shape());
33 ASSERT_EQ(0, reshape.newShape()->rank());
36 TEST(CircleReshapeTest, alloc_new_shape_P)
38 luci::CircleReshape reshape;
40 reshape.newShape()->rank(2);
41 ASSERT_EQ(2, reshape.newShape()->rank());
43 reshape.newShape()->dim(0) = 0;
44 reshape.newShape()->dim(1) = 1;
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));
51 TEST(CircleReshapeTest, input_NEG)
53 luci::CircleReshape reshape_node;
54 luci::CircleReshape node;
56 reshape_node.tensor(&node);
57 reshape_node.shape(&node);
58 ASSERT_NE(nullptr, reshape_node.tensor());
59 ASSERT_NE(nullptr, reshape_node.shape());
61 reshape_node.tensor(nullptr);
62 reshape_node.shape(nullptr);
63 ASSERT_EQ(nullptr, reshape_node.tensor());
64 ASSERT_EQ(nullptr, reshape_node.shape());
67 TEST(CircleReshapeTest, arity_NEG)
69 luci::CircleReshape reshape_node;
71 ASSERT_NO_THROW(reshape_node.arg(1));
72 ASSERT_THROW(reshape_node.arg(2), std::out_of_range);
75 TEST(CircleReshapeTest, visit_mutable_NEG)
77 struct TestVisitor final : public luci::CircleNodeMutableVisitor<void>
81 luci::CircleReshape reshape_node;
84 ASSERT_THROW(reshape_node.accept(&tv), std::exception);
87 TEST(CircleReshapeTest, visit_NEG)
89 struct TestVisitor final : public luci::CircleNodeVisitor<void>
93 luci::CircleReshape reshape_node;
96 ASSERT_THROW(reshape_node.accept(&tv), std::exception);