Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / onert-micro / luci-interpreter / src / kernels / Floor.test.cpp
1 /*
2  * Copyright (c) 2020 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 "kernels/Floor.h"
18 #include "kernels/TestUtils.h"
19 #include "luci_interpreter/TestMemoryManager.h"
20
21 namespace luci_interpreter
22 {
23 namespace kernels
24 {
25 namespace
26 {
27
28 using namespace testing;
29
30 class FloorTest : public ::testing::Test
31 {
32 protected:
33   void SetUp() override { _memory_manager = std::make_unique<TestMemoryManager>(); }
34
35   std::unique_ptr<IMemoryManager> _memory_manager;
36 };
37
38 TEST_F(FloorTest, SimpleFloat)
39 {
40   std::initializer_list<int32_t> input_shape{1, 2, 4, 1};
41   std::vector<float> input_data{
42     0.2, 8.6, 2.4,  4.3,  // Row 1
43     3,   7.1, 10.5, -0.9, // Row 2
44   };
45
46   std::initializer_list<int32_t> ref_output_shape{1, 2, 4, 1};
47   std::vector<float> ref_output_data{
48     0, 8, 2,  4,  // Row 1
49     3, 7, 10, -1, // Row 2
50   };
51
52   Tensor input_tensor =
53     makeInputTensor<DataType::FLOAT32>(input_shape, input_data, _memory_manager.get());
54   Tensor output_tensor = makeOutputTensor(DataType::FLOAT32);
55
56   Floor kernel(&input_tensor, &output_tensor);
57   kernel.configure();
58   _memory_manager->allocate_memory(output_tensor);
59   kernel.execute();
60
61   EXPECT_THAT(extractTensorData<float>(output_tensor), FloatArrayNear(ref_output_data));
62   EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray(ref_output_shape));
63 }
64
65 TEST_F(FloorTest, Input_Output_Type_NEG)
66 {
67   Tensor input_tensor = makeInputTensor<DataType::FLOAT32>({1}, {1.f}, _memory_manager.get());
68   Tensor output_tensor = makeOutputTensor(DataType::S32);
69
70   Floor kernel(&input_tensor, &output_tensor);
71   EXPECT_ANY_THROW(kernel.configure());
72 }
73
74 } // namespace
75 } // namespace kernels
76 } // namespace luci_interpreter