26e52fdcd612c4aad8665e722b999f76133412a7
[platform/core/ml/nnfw.git] / tests / nnfw_api / src / one_op_tests / Equal.cc
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 "GenModelTest.h"
18
19 TEST_F(GenModelTest, OneOp_Equal)
20 {
21   CircleGen cgen;
22   int lhs = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
23   int rhs = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
24   int out = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_BOOL});
25   cgen.addOperatorEqual({{lhs, rhs}, {out}});
26   cgen.setInputsAndOutputs({lhs, rhs}, {out});
27
28   _context = std::make_unique<GenModelTestContext>(cgen.finish());
29   _context->addTestCase(TestCaseData{}
30                             .addInput<float>({0.1, 0.3, 0.5, 0.7})
31                             .addInput<float>({0.1, 0.2, 0.3, 0.4})
32                             .addOutput<bool>({true, false, false, false}));
33   _context->setBackends({"acl_cl", "acl_neon", "cpu"});
34
35   SUCCEED();
36 }
37
38 TEST_F(GenModelTest, neg_OneOp_Equal_DifferentType)
39 {
40   CircleGen cgen;
41   int lhs = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
42   int rhs = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT32});
43   int out = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_BOOL});
44   cgen.addOperatorEqual({{lhs, rhs}, {out}});
45   cgen.setInputsAndOutputs({lhs, rhs}, {out});
46
47   _context = std::make_unique<GenModelTestContext>(cgen.finish());
48   _context->setBackends({"acl_cl", "acl_neon", "cpu"});
49   _context->expectFailModelLoad();
50
51   SUCCEED();
52 }
53
54 TEST_F(GenModelTest, neg_OneOp_Equal_InvalidType)
55 {
56   CircleGen cgen;
57   int lhs = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
58   int rhs = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
59   int out = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT32});
60   cgen.addOperatorEqual({{lhs, rhs}, {out}});
61   cgen.setInputsAndOutputs({lhs, rhs}, {out});
62
63   _context = std::make_unique<GenModelTestContext>(cgen.finish());
64   _context->setBackends({"acl_cl", "acl_neon", "cpu"});
65   _context->expectFailModelLoad();
66
67   SUCCEED();
68 }