Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / compiler / record-minmax / tests / MinMaxComputer.test.cpp
1 /*
2  * Copyright (c) 2023 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 "MinMaxComputer.h"
18
19 #include <luci/IR/CircleNodes.h>
20
21 #include <unordered_map>
22
23 #include <gtest/gtest.h>
24
25 using namespace record_minmax;
26
27 TEST(MinMaxComputerTest, percentile)
28 {
29   auto computer = make_percentile_computer(0.0, 100.0);
30
31   luci::CircleAdd node;
32   MinMaxVectors minmax;
33   {
34     minmax.min_vector = {1.0, 2.0, 3.0};
35     minmax.max_vector = {4.0, 5.0, 6.0};
36   }
37   std::unordered_map<const luci::CircleNode *, MinMaxVectors> min_max_map;
38   min_max_map.insert({&node, minmax});
39
40   computer->update_qparam(&min_max_map);
41
42   EXPECT_TRUE(node.quantparam() != nullptr);
43 }
44
45 TEST(MinMaxComputerTest, percentile_nullptr_NEG)
46 {
47   auto computer = make_percentile_computer(0.0, 100.0);
48
49   EXPECT_ANY_THROW(computer->update_qparam(nullptr));
50 }
51
52 TEST(MinMaxComputerTest, moving_avg)
53 {
54   auto computer = make_moving_avg_computer(1, 0.99);
55
56   luci::CircleAdd node;
57   MinMaxVectors minmax;
58   {
59     minmax.min_vector = {1.0, 2.0, 3.0};
60     minmax.max_vector = {4.0, 5.0, 6.0};
61   }
62   std::unordered_map<const luci::CircleNode *, MinMaxVectors> min_max_map;
63   min_max_map.insert({&node, minmax});
64
65   computer->update_qparam(&min_max_map);
66
67   EXPECT_TRUE(node.quantparam() != nullptr);
68 }
69
70 TEST(MinMaxComputerTest, moving_avg_nullptr_NEG)
71 {
72   auto computer = make_moving_avg_computer(1, 0.99);
73
74   EXPECT_ANY_THROW(computer->update_qparam(nullptr));
75 }