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