2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2017 The TensorFlow Authors. All Rights Reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "kernels/LogicalAnd.h"
19 #include "kernels/TestUtils.h"
20 #include "luci_interpreter/TestMemoryManager.h"
22 namespace luci_interpreter
29 using namespace testing;
31 class LogicalAndTest : public ::testing::Test
34 void SetUp() override { _memory_manager = std::make_unique<TestMemoryManager>(); }
36 std::unique_ptr<IMemoryManager> _memory_manager;
39 TEST_F(LogicalAndTest, Basic)
41 Shape input_shape{1, 1, 1, 4};
42 Tensor input_tensor1 =
43 makeInputTensor<DataType::BOOL>(input_shape, {true, false, false, true}, _memory_manager.get());
44 Tensor input_tensor2 =
45 makeInputTensor<DataType::BOOL>(input_shape, {true, false, true, false}, _memory_manager.get());
46 Tensor output_tensor = makeOutputTensor(DataType::BOOL);
48 LogicalAnd kernel(&input_tensor1, &input_tensor2, &output_tensor);
50 _memory_manager->allocate_memory(output_tensor);
53 EXPECT_THAT(extractTensorData<bool>(output_tensor),
54 ::testing::ElementsAre(true, false, false, false));
55 EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAre(1, 1, 1, 4));
58 TEST_F(LogicalAndTest, Broadcast)
60 Tensor input_tensor1 = makeInputTensor<DataType::BOOL>({1, 1, 1, 4}, {true, false, false, true},
61 _memory_manager.get());
62 Tensor input_tensor2 =
63 makeInputTensor<DataType::BOOL>({1, 1, 1, 1}, {true}, _memory_manager.get());
64 Tensor output_tensor = makeOutputTensor(DataType::BOOL);
66 LogicalAnd kernel(&input_tensor1, &input_tensor2, &output_tensor);
68 _memory_manager->allocate_memory(output_tensor);
71 EXPECT_THAT(extractTensorData<bool>(output_tensor),
72 ::testing::ElementsAre(true, false, false, true));
73 EXPECT_THAT(extractTensorShape(output_tensor), ::testing::ElementsAre(1, 1, 1, 4));
76 TEST_F(LogicalAndTest, MismatchInputType_NEG)
78 Tensor input1_tensor =
79 makeInputTensor<DataType::S32>({1, 1, 1, 4}, {1, 0, 0, 1}, _memory_manager.get());
80 Tensor input2_tensor =
81 makeInputTensor<DataType::BOOL>({1, 1, 1, 1}, {false}, _memory_manager.get());
82 Tensor output_tensor = makeOutputTensor(DataType::S32);
84 LogicalAnd kernel(&input1_tensor, &input2_tensor, &output_tensor);
85 EXPECT_ANY_THROW(kernel.configure());
88 TEST_F(LogicalAndTest, InputTypeInvalid_NEG)
90 Tensor input1_tensor =
91 makeInputTensor<DataType::S32>({1, 1, 1, 4}, {1, 0, 0, 1}, _memory_manager.get());
92 Tensor input2_tensor = makeInputTensor<DataType::S32>({1, 1, 1, 1}, {0}, _memory_manager.get());
93 Tensor output_tensor = makeOutputTensor(DataType::BOOL);
95 LogicalAnd kernel(&input1_tensor, &input2_tensor, &output_tensor);
96 EXPECT_ANY_THROW(kernel.configure());
100 } // namespace kernels
101 } // namespace luci_interpreter