• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "libpandabase/utils/utils.h"
17 #include "util/function_traits.h"
18 
19 #include "util/tests/verifier_test.h"
20 
21 #include <gtest/gtest.h>
22 
23 namespace ark::verifier::test {
24 
25 struct SquareSum {
operator ()ark::verifier::test::SquareSum26     int operator()(int x, int y) const
27     {
28         return (x + y) * (x + y);
29     }
30 };
31 
32 struct SquareDiversity {
operator ()ark::verifier::test::SquareDiversity33     int operator()(int x, int y) const
34     {
35         return (x - y) * (x - y);
36     }
37 };
38 
39 struct MultByMod {
40     // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
41     int mod;
MultByModark::verifier::test::MultByMod42     explicit MultByMod(int module) : mod {module} {}
operator ()ark::verifier::test::MultByMod43     int operator()(int x, int y) const
44     {
45         return (x * y) % mod;
46     }
47 };
48 
TEST_F(VerifierTest,function_traits)49 TEST_F(VerifierTest, function_traits)
50 {
51     SquareSum sqSum;
52     SquareDiversity sqDiv;
53     NAry<SquareSum> opSSum {sqSum};
54     NAry<SquareDiversity> opSDiv {sqDiv};
55     EXPECT_EQ(opSSum(2_I, 2_I), 16_I);
56     EXPECT_EQ(opSDiv(2_I, 1_I), 1_I);
57     EXPECT_EQ(opSSum(2_I, 1_I, 2_I), 121_I);
58     EXPECT_EQ(opSDiv(2_I, 1_I, 2_I), 1_I);
59 
60     MultByMod mod5 {5_I};
61     // NOLINTNEXTLINE(readability-magic-numbers)
62     MultByMod mod10 {10_I};
63     NAry<MultByMod> opMultMod5 {mod5};
64     NAry<MultByMod> opMultMod10 {mod10};
65     EXPECT_EQ(opMultMod5(2_I, 4_I), 3_I);
66     EXPECT_EQ(opMultMod10(2_I, 4_I), 8_I);
67     EXPECT_EQ(opMultMod5(2_I, 4_I, 2_I), 1_I);
68     EXPECT_EQ(opMultMod10(2_I, 4_I, 2_I), 6_I);
69 }
70 
71 }  // namespace ark::verifier::test
72