2 * Copyright (c) 2019 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 "loco/IR/TensorShape.h"
19 #include <gtest/gtest.h>
21 TEST(TensorShapeTest, default_constructor)
23 loco::TensorShape tensor_shape;
25 ASSERT_EQ(0, tensor_shape.rank());
28 TEST(TensorShapeTest, initializer_list_constructor)
30 loco::TensorShape tensor_shape{3, 5};
32 ASSERT_EQ(2, tensor_shape.rank());
34 ASSERT_TRUE(tensor_shape.dim(0).known());
35 ASSERT_TRUE(tensor_shape.dim(1).known());
37 ASSERT_EQ(3, tensor_shape.dim(0).value());
38 ASSERT_EQ(5, tensor_shape.dim(1).value());
41 TEST(TensorShapeTest, rank)
43 loco::TensorShape tensor_shape;
47 ASSERT_EQ(2, tensor_shape.rank());
48 ASSERT_FALSE(tensor_shape.dim(0).known());
49 ASSERT_FALSE(tensor_shape.dim(1).known());
52 TEST(TensorShapeTest, dim)
54 loco::TensorShape tensor_shape;
58 tensor_shape.dim(0) = 3;
60 ASSERT_TRUE(tensor_shape.dim(0).known());
61 ASSERT_FALSE(tensor_shape.dim(1).known());
63 ASSERT_EQ(3, tensor_shape.dim(0));
66 TEST(TensorShapeTest, rank_update)
68 loco::TensorShape tensor_shape;
72 tensor_shape.dim(1) = 3;
76 ASSERT_FALSE(tensor_shape.dim(0).known());
77 ASSERT_TRUE(tensor_shape.dim(1).known());
78 ASSERT_FALSE(tensor_shape.dim(2).known());
79 ASSERT_FALSE(tensor_shape.dim(3).known());
81 ASSERT_EQ(3, tensor_shape.dim(1));
84 TEST(TensorShapeTest, copy)
86 loco::TensorShape src;
91 loco::TensorShape dst;
95 ASSERT_EQ(2, dst.rank());
97 ASSERT_FALSE(dst.dim(0).known());
98 ASSERT_TRUE(dst.dim(1).known());
100 ASSERT_EQ(3, dst.dim(1));
103 TEST(TensorShapeTest, element_count)
106 loco::TensorShape src;
108 ASSERT_EQ(1, loco::element_count(&src));
111 TEST(TensorShapeTest, equal_operator)
113 loco::TensorShape lhs, rhs;
122 EXPECT_FALSE(lhs == rhs);
128 EXPECT_TRUE(lhs == rhs);
131 loco::TensorShape lhs_u, rhs_u;
139 EXPECT_FALSE(lhs == rhs_u);