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