Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / compiler / loco / src / IR / Dimension.test.cpp
1 /*
2  * Copyright (c) 2019 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 "loco/IR/Dimension.h"
18
19 #include <gtest/gtest.h>
20
21 namespace
22 {
23
24 struct DimensionTest : public ::testing::Test
25 {
26 protected:
27   uint32_t value(void) const { return _value; }
28
29 private:
30   uint32_t const _value{3};
31 };
32
33 } // namespace
34
35 TEST_F(DimensionTest, default_constructor)
36 {
37   loco::Dimension dim;
38
39   ASSERT_FALSE(dim.known());
40 }
41
42 TEST_F(DimensionTest, value_constructor)
43 {
44   loco::Dimension dim{value()};
45
46   ASSERT_TRUE(dim.known());
47   ASSERT_EQ(value(), dim.value());
48 }
49
50 TEST_F(DimensionTest, set)
51 {
52   loco::Dimension dim;
53
54   dim.set(value());
55
56   ASSERT_TRUE(dim.known());
57   ASSERT_EQ(value(), dim.value());
58 }
59
60 TEST_F(DimensionTest, unset)
61 {
62   loco::Dimension dim{value()};
63
64   dim.unset();
65
66   ASSERT_FALSE(dim.known());
67 }
68
69 TEST_F(DimensionTest, operator_eq)
70 {
71   loco::Dimension unknown;
72   loco::Dimension known{3};
73
74   // Compare uint32_t and an unknown dimension
75   ASSERT_FALSE(unknown == 3);
76   ASSERT_FALSE(3 == unknown);
77
78   // Compare uint32_t and a known dimension
79   ASSERT_TRUE(known == 3);
80   ASSERT_TRUE(3 == known);
81
82   ASSERT_FALSE(known == 4);
83   ASSERT_FALSE(4 == known);
84
85   // Compare two known dimensions
86   loco::Dimension another_known{3};
87   ASSERT_TRUE(known == another_known);
88
89   // Compare two unknown dimensions
90   loco::Dimension unknown_a, unknown_b;
91   ASSERT_TRUE(unknown_a.known() == false && unknown_b.known() == false);
92   ASSERT_FALSE(unknown_a == unknown_b);
93 }
94
95 TEST_F(DimensionTest, make_unknown_dimension)
96 {
97   auto dim = loco::make_dimension();
98
99   ASSERT_FALSE(dim.known());
100 }