cdb52953e231ec75478dbe555f225471ab1e7063
[platform/core/ml/nnfw.git] / tests / nnfw_api / src / one_op_tests / AddN.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_AddN_1D)
20 {
21   CircleGen cgen;
22
23   int in1 = cgen.addTensor({{8}, circle::TensorType::TensorType_FLOAT32});
24   int in2 = cgen.addTensor({{8}, circle::TensorType::TensorType_FLOAT32});
25   int in3 = cgen.addTensor({{8}, circle::TensorType::TensorType_FLOAT32});
26   int out = cgen.addTensor({{8}, circle::TensorType::TensorType_FLOAT32});
27
28   cgen.addOperatorAddN({{in1, in2, in3}, {out}});
29   cgen.setInputsAndOutputs({in1, in2, in3}, {out});
30
31   _context = std::make_unique<GenModelTestContext>(cgen.finish());
32   _context->setBackends({"cpu"});
33   _context->addTestCase(uniformTCD<float>({{1.2, 2.0, -3.0, 4.5, 10.0, 5.1, -7.0, 12.0},
34                                            {3.3, 4.1, 3.0, 4.4, 5.0, 4.3, -1.2, 4.0},
35                                            {-5.2, 3.1, 2.2, -3.7, 5.2, 2.0, -4.3, 5.0}},
36                                           {{-0.7, 9.2, 2.2, 5.2, 20.2, 11.4, -12.5, 21.0}}));
37
38   SUCCEED();
39 }
40
41 TEST_F(GenModelTest, neg_OneOp_AddN_InvalidType)
42 {
43   CircleGen cgen;
44
45   int in1 = cgen.addTensor({{8}, circle::TensorType::TensorType_UINT8});
46   int in2 = cgen.addTensor({{8}, circle::TensorType::TensorType_UINT8});
47   int in3 = cgen.addTensor({{8}, circle::TensorType::TensorType_UINT8});
48   int out = cgen.addTensor({{8}, circle::TensorType::TensorType_UINT8});
49
50   cgen.addOperatorAddN({{in1, in2, in3}, {out}});
51   cgen.setInputsAndOutputs({in1, in2, in3}, {out});
52
53   _context = std::make_unique<GenModelTestContext>(cgen.finish());
54   _context->setBackends({"cpu"});
55   _context->expectFailModelLoad();
56
57   SUCCEED();
58 }