8b2bc1a828bfe608e557528e63463d294d730d79
[platform/core/ml/nnfw.git] / onert-micro / luci-interpreter / src / kernels / Neg.test.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved
3  * Copyright 2017 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/Neg.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 template <typename T>
32 void Check(std::initializer_list<int32_t> input_shape, std::initializer_list<int32_t> output_shape,
33            std::initializer_list<T> input_data, std::initializer_list<T> output_data)
34 {
35   std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>();
36   constexpr DataType element_type = getElementType<T>();
37   Tensor input_tensor =
38     makeInputTensor<element_type>(input_shape, input_data, memory_manager.get());
39   Tensor output_tensor = makeOutputTensor(element_type);
40
41   Neg kernel(&input_tensor, &output_tensor);
42
43   kernel.configure();
44   memory_manager->allocate_memory(output_tensor);
45   kernel.execute();
46
47   EXPECT_THAT(extractTensorData<T>(output_tensor), ::testing::ElementsAreArray(output_data));
48   EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray(output_shape));
49 }
50
51 TEST(NegTest, FloatSimple)
52 {
53   Check<float>(/*input_shape=*/{2, 3},
54                /*output_shape=*/{2, 3},
55                /*input_data=*/
56                {
57                  0.0f, 1.0f, 3.0f,   // Row 1
58                  1.0f, -1.0f, -2.0f, // Row 2
59                },
60                /*output_data=*/
61                {
62                  0.0f, -1.0f, -3.0f, // Row 1
63                  -1.0f, 1.0f, 2.0f,  // Row 2
64                });
65
66   SUCCEED();
67 }
68
69 } // namespace
70 } // namespace kernels
71 } // namespace luci_interpreter