Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / compiler / locomotiv / src / NodeData.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 "locomotiv/NodeData.h"
18
19 #include <nncc/core/ADT/tensor/Shape.h>
20 #include <nncc/core/ADT/tensor/Buffer.h>
21 #include <nncc/core/ADT/tensor/LexicalLayout.h>
22
23 #include <gtest/gtest.h>
24
25 using nncc::core::ADT::tensor::Index;
26 using nncc::core::ADT::tensor::Shape;
27 using nncc::core::ADT::tensor::LexicalLayout;
28 using nncc::core::ADT::tensor::make_buffer;
29
30 TEST(NodeData, as_s32_buffer_wrapper)
31 {
32   const Shape shape{1};
33   auto buf = make_buffer<int32_t, LexicalLayout>(shape);
34   buf.at(Index{0}) = 42;
35
36   auto data = locomotiv::make_data(buf);
37
38   ASSERT_EQ(loco::DataType::S32, data->dtype());
39   ASSERT_EQ(shape, *(data->shape()));
40   ASSERT_EQ(42, data->as_s32_bufptr()->at(Index{0}));
41 }
42
43 TEST(NodeData, as_f32_buffer_wrapper)
44 {
45   const Shape shape{1};
46   auto buf = make_buffer<float, LexicalLayout>(shape);
47   buf.at(Index{0}) = 3.14f;
48
49   auto data = locomotiv::make_data(buf);
50
51   ASSERT_EQ(loco::DataType::FLOAT32, data->dtype());
52   ASSERT_EQ(shape, *(data->shape()));
53   ASSERT_FLOAT_EQ(3.14f, data->as_f32_bufptr()->at(Index{0}));
54 }