37523be2d2a360a2528268c11faa781eb8f0b4dd
[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  * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *    http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include "kernels/Floor.h"
19 #include "kernels/TestUtils.h"
20 #include "luci_interpreter/TestMemoryManager.h"
21
22 namespace luci_interpreter
23 {
24 namespace kernels
25 {
26 namespace
27 {
28
29 using namespace testing;
30
31 class FloorTest : public ::testing::Test
32 {
33 protected:
34   void SetUp() override { _memory_manager = std::make_unique<TestMemoryManager>(); }
35
36   std::unique_ptr<IMemoryManager> _memory_manager;
37 };
38
39 TEST_F(FloorTest, SimpleFloat)
40 {
41   std::initializer_list<int32_t> input_shape{1, 2, 4, 1};
42   std::vector<float> input_data{
43     0.2, 8.6, 2.4,  4.3,  // Row 1
44     3,   7.1, 10.5, -0.9, // Row 2
45   };
46
47   std::initializer_list<int32_t> ref_output_shape{1, 2, 4, 1};
48   std::vector<float> ref_output_data{
49     0, 8, 2,  4,  // Row 1
50     3, 7, 10, -1, // Row 2
51   };
52
53   Tensor input_tensor =
54     makeInputTensor<DataType::FLOAT32>(input_shape, input_data, _memory_manager.get());
55   Tensor output_tensor = makeOutputTensor(DataType::FLOAT32);
56
57   Floor kernel(&input_tensor, &output_tensor);
58   kernel.configure();
59   _memory_manager->allocate_memory(output_tensor);
60   kernel.execute();
61
62   EXPECT_THAT(extractTensorData<float>(output_tensor), FloatArrayNear(ref_output_data));
63   EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray(ref_output_shape));
64 }
65
66 TEST_F(FloorTest, Input_Output_Type_NEG)
67 {
68   Tensor input_tensor = makeInputTensor<DataType::FLOAT32>({1}, {1.f}, _memory_manager.get());
69   Tensor output_tensor = makeOutputTensor(DataType::S32);
70
71   Floor kernel(&input_tensor, &output_tensor);
72   EXPECT_ANY_THROW(kernel.configure());
73 }
74
75 } // namespace
76 } // namespace kernels
77 } // namespace luci_interpreter