Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / compiler / angkor / src / TensorIndex.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 "angkor/TensorIndex.h"
18
19 #include <gtest/gtest.h>
20
21 TEST(TensorIndexTest, ctor)
22 {
23   angkor::TensorIndex index;
24
25   ASSERT_EQ(0, index.rank());
26 }
27
28 TEST(TensorIndexTest, ctor_initializer_list)
29 {
30   const angkor::TensorIndex index{1, 3, 5, 7};
31
32   ASSERT_EQ(4, index.rank());
33
34   ASSERT_EQ(1, index.at(0));
35   ASSERT_EQ(3, index.at(1));
36   ASSERT_EQ(5, index.at(2));
37   ASSERT_EQ(7, index.at(3));
38 }
39
40 TEST(TensorIndexTest, resize)
41 {
42   angkor::TensorIndex index;
43
44   index.resize(4);
45
46   ASSERT_EQ(4, index.rank());
47 }
48
49 TEST(TensorIndexTest, at)
50 {
51   angkor::TensorIndex index;
52
53   index.resize(4);
54
55   uint32_t indices[4] = {3, 5, 2, 7};
56
57   for (uint32_t axis = 0; axis < 4; ++axis)
58   {
59     index.at(axis) = indices[axis];
60     ASSERT_EQ(indices[axis], index.at(axis));
61   }
62 }
63
64 TEST(TensorIndexTest, copy)
65 {
66   const angkor::TensorIndex original{3, 5, 2, 7};
67   const angkor::TensorIndex copied{original};
68
69   ASSERT_EQ(copied.rank(), original.rank());
70
71   for (uint32_t axis = 0; axis < 4; ++axis)
72   {
73     ASSERT_EQ(copied.at(axis), original.at(axis));
74   }
75 }
76
77 TEST(TensorIndexTest, fill)
78 {
79   angkor::TensorIndex index{1, 6};
80
81   index.fill(3);
82
83   ASSERT_EQ(2, index.rank());
84
85   ASSERT_EQ(3, index.at(0));
86   ASSERT_EQ(3, index.at(1));
87 }