• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 #include <math.h>
3 
4 #include "math_data_test.h"
5 #include "math_test_data/remainderf_data.h"
6 #include "math_test_data/remainder_data.h"
7 
8 using namespace testing::ext;
9 
10 class MathRemainderTest : public testing::Test {
SetUp()11     void SetUp() override {}
TearDown()12     void TearDown() override {}
13 };
14 
15 /**
16  * @tc.name: remainder_001
17  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the remainder interface.
18  * @tc.type: FUNC
19  */
20 HWTEST_F(MathRemainderTest, remainder_001, TestSize.Level1)
21 {
22     fesetenv(FE_DFL_ENV);
23     for (int i = 0; i < sizeof(g_remainderData) / sizeof(DataDouble3Expected1); i++) {
24         bool testResult = DoubleUlpCmp(g_remainderData[i].expected, remainder(g_remainderData[i].input1,
25             g_remainderData[i].input2), 1);
26         EXPECT_TRUE(testResult);
27     }
28 }
29 
30 /**
31  * @tc.name: remainder_002
32  * @tc.desc: When the value is valid, test the return value of the function.
33  * @tc.type: FUNC
34  */
35 HWTEST_F(MathRemainderTest, remainder_002, TestSize.Level1)
36 {
37     EXPECT_DOUBLE_EQ(4.0, remainder(15.0, 11.0));
38 }
39 
40 /**
41  * @tc.name: remainder_003
42  * @tc.desc: When the value is nan, test the return value of the function.
43  * @tc.type: FUNC
44  */
45 HWTEST_F(MathRemainderTest, remainder_003, TestSize.Level1)
46 {
47     EXPECT_TRUE(isnan(remainder(nan(""), 11.0)));
48     EXPECT_TRUE(isnan(remainder(13.0, nan(""))));
49 }
50 
51 /**
52  * @tc.name: remainder_004
53  * @tc.desc: When the value is infinite, test the return value of the function.
54  * @tc.type: FUNC
55  */
56 HWTEST_F(MathRemainderTest, remainder_004, TestSize.Level1)
57 {
58     EXPECT_TRUE(isnan(remainder(HUGE_VAL, 14.0)));
59     EXPECT_TRUE(isnan(remainder(-HUGE_VAL, 14.0)));
60 }
61 
62 /**
63  * @tc.name: remainder_005
64  * @tc.desc: When the dividend is a non-zero constant and the divisor is zero, test the return value of the function.
65  * @tc.type: FUNC
66  */
67 HWTEST_F(MathRemainderTest, remainder_005, TestSize.Level1)
68 {
69     EXPECT_TRUE(isnan(remainder(15.0, 0.0)));
70 }
71 
72 /**
73  * @tc.name: remainderf_001
74  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the remainderf interface.
75  * @tc.type: FUNC
76  */
77 HWTEST_F(MathRemainderTest, remainderf_001, TestSize.Level1)
78 {
79     fesetenv(FE_DFL_ENV);
80     for (int i = 0; i < sizeof(g_remainderfData) / sizeof(DataFloat3Expected1); i++) {
81         bool testResult = FloatUlpCmp(g_remainderfData[i].expected, remainderf(g_remainderfData[i].input1,
82             g_remainderfData[i].input2), 1);
83         EXPECT_TRUE(testResult);
84     }
85 }
86 
87 /**
88  * @tc.name: remainderf_002
89  * @tc.desc: When the float value is valid, test the return value of the function.
90  * @tc.type: FUNC
91  */
92 HWTEST_F(MathRemainderTest, remainderf_002, TestSize.Level1)
93 {
94     EXPECT_DOUBLE_EQ(4.0f, remainderf(15.0f, 11.0f));
95 }
96 
97 /**
98  * @tc.name: remainderf_003
99  * @tc.desc: When the value is nan, test the return value of the function.
100  * @tc.type: FUNC
101  */
102 HWTEST_F(MathRemainderTest, remainderf_003, TestSize.Level1)
103 {
104     EXPECT_TRUE(isnan(remainderf(nanf(""), 11.0f)));
105     EXPECT_TRUE(isnan(remainderf(13.0f, nanf(""))));
106 }
107 
108 /**
109  * @tc.name: remainderf_004
110  * @tc.desc: When the value is infinite, test the return value of the function.
111  * @tc.type: FUNC
112  */
113 HWTEST_F(MathRemainderTest, remainderf_004, TestSize.Level1)
114 {
115     EXPECT_TRUE(isnan(remainderf(HUGE_VAL, 14.0f)));
116     EXPECT_TRUE(isnan(remainderf(-HUGE_VAL, 14.0f)));
117 }
118 
119 /**
120  * @tc.name: remainderf_005
121  * @tc.desc: When the dividend is a non-zero constant and the divisor is zero, test the return value of the function.
122  * @tc.type: FUNC
123  */
124 HWTEST_F(MathRemainderTest, remainderf_005, TestSize.Level1)
125 {
126     EXPECT_TRUE(isnan(remainderf(15.0f, 0.0f)));
127 }