Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / compiler / angkor / src / ADT / kernel / Buffer.test.cpp
1 /*
2  * Copyright (c) 2018 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 "nncc/core/ADT/kernel/Buffer.h"
18 #include "nncc/core/ADT/kernel/NCHWLayout.h"
19
20 #include <gtest/gtest.h>
21
22 using nncc::core::ADT::kernel::Shape;
23 using nncc::core::ADT::kernel::NCHWLayout;
24 using nncc::core::ADT::kernel::Buffer;
25
26 using nncc::core::ADT::kernel::make_buffer;
27
28 TEST(ADT_KERNEL_BUFFER, ctor)
29 {
30   const Shape shape{2, 4, 6, 3};
31   auto buffer = make_buffer<int, NCHWLayout>(shape);
32
33   ASSERT_EQ(shape.count(), buffer.shape().count());
34   ASSERT_EQ(shape.depth(), buffer.shape().depth());
35   ASSERT_EQ(shape.height(), buffer.shape().height());
36   ASSERT_EQ(shape.width(), buffer.shape().width());
37 }
38
39 TEST(ADT_KERNEL_BUFFER, access)
40 {
41   const Shape shape{2, 4, 6, 3};
42   auto buffer = make_buffer<int, NCHWLayout>(shape);
43
44   ASSERT_EQ(0, buffer.at(1, 3, 5, 2));
45   buffer.at(1, 3, 5, 2) = 4;
46
47   // Casting is introduced to use 'const T &at(...) const' method
48   ASSERT_EQ(4, static_cast<const Buffer<int> &>(buffer).at(1, 3, 5, 2));
49 }