Imported Upstream version 1.11.0
[platform/core/ml/nnfw.git] / compiler / luci-interpreter / src / kernels / Slice.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/Slice.h"
18 #include "kernels/TestUtils.h"
19
20 namespace luci_interpreter
21 {
22 namespace kernels
23 {
24 namespace
25 {
26
27 using namespace testing;
28
29 template <typename T> class SliceTest : public ::testing::Test
30 {
31 };
32
33 using DataTypes = ::testing::Types<float, uint8_t>;
34 TYPED_TEST_CASE(SliceTest, DataTypes);
35
36 TYPED_TEST(SliceTest, SimpleTest)
37 {
38   std::vector<TypeParam> input_data{1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6};
39   Shape input_shape{3, 2, 3, 1};
40   std::vector<int32_t> begin_data{1, 0, 0, 0};
41   Shape begin_shape{4};
42   std::vector<int32_t> size_data{2, 1, -1, 1};
43   Shape size_shape{4};
44   std::vector<TypeParam> output_data{3, 3, 3, 5, 5, 5};
45   std::vector<int32_t> output_shape{2, 1, 3, 1};
46
47   Tensor input_tensor = makeInputTensor<getElementType<TypeParam>()>(input_shape, input_data);
48   Tensor begin_tensor = makeInputTensor<DataType::S32>(begin_shape, begin_data);
49   Tensor size_tensor = makeInputTensor<DataType::S32>(size_shape, size_data);
50
51   Tensor output_tensor = makeOutputTensor(getElementType<TypeParam>());
52
53   Slice kernel(&input_tensor, &begin_tensor, &size_tensor, &output_tensor);
54   kernel.configure();
55   kernel.execute();
56
57   EXPECT_THAT(extractTensorData<TypeParam>(output_tensor),
58               ::testing::ElementsAreArray(output_data));
59   EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAreArray(output_shape));
60 }
61
62 } // namespace
63 } // namespace kernels
64 } // namespace luci_interpreter