Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / compute / test / cker / Range.cc
1 /*
2  * Copyright (c) 2019 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 <cker/operation/Range.h>
18
19 #include <gtest/gtest.h>
20 #include <vector>
21
22 TEST(CKer_Operation, Range)
23 {
24   {
25     const int start = 0;
26     const int limit = 10;
27     const int delta = 1;
28     std::vector<int> actual(10);
29     nnfw::cker::Range<int>(&start, &limit, &delta, actual.data());
30
31     for (int i = 0; i < actual.size(); i++)
32       ASSERT_EQ(actual[i], i);
33   }
34
35   {
36     const int start = 3;
37     const int limit = 18;
38     const int delta = 3;
39     std::vector<int> expected = {3, 6, 9, 12, 15};
40     std::vector<int> actual(expected.size());
41     nnfw::cker::Range<int>(&start, &limit, &delta, actual.data());
42
43     for (int i = 0; i < actual.size(); i++)
44       ASSERT_EQ(actual[i], expected[i]);
45   }
46
47   {
48     const float start = 3;
49     const float limit = 1;
50     const float delta = -0.5;
51     std::vector<float> expected = {
52         3, 2.5, 2, 1.5,
53     };
54     std::vector<float> actual(expected.size());
55     nnfw::cker::Range<float>(&start, &limit, &delta, actual.data());
56
57     for (int i = 0; i < actual.size(); i++)
58       ASSERT_FLOAT_EQ(actual[i], expected[i]);
59   }
60 }
61
62 TEST(CKer_Operation, neg_Range)
63 {
64   {
65     const int start = 212;
66     const int limit = 10;
67     const int delta = 1;
68     std::vector<int> actual(10);
69
70     EXPECT_ANY_THROW(nnfw::cker::Range<int>(&start, &limit, &delta, actual.data()));
71   }
72 }