2 * Copyright (c) 2018 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 "nncc/core/ADT/feature/Buffer.h"
18 #include "nncc/core/ADT/feature/CHWLayout.h"
20 #include <gtest/gtest.h>
22 using nncc::core::ADT::feature::Shape;
23 using nncc::core::ADT::feature::CHWLayout;
24 using nncc::core::ADT::feature::Buffer;
26 using nncc::core::ADT::feature::make_buffer;
28 TEST(ADT_FEATURE_BUFFER, ctor)
30 const Shape shape{4, 6, 3};
31 auto buffer = make_buffer<int, CHWLayout>(shape);
33 ASSERT_EQ(shape.depth(), buffer.shape().depth());
34 ASSERT_EQ(shape.height(), buffer.shape().height());
35 ASSERT_EQ(shape.width(), buffer.shape().width());
38 TEST(ADT_FEATURE_BUFFER, access)
40 const Shape shape{4, 6, 3};
41 auto buffer = make_buffer<int, CHWLayout>(shape);
43 ASSERT_EQ(0, buffer.at(3, 5, 2));
44 buffer.at(3, 5, 2) = 4;
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));