• 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/remquof_data.h"
6 #include "math_test_data/remquo_data.h"
7 
8 using namespace testing::ext;
9 
10 class MathRemquoTest : public testing::Test {
SetUp()11     void SetUp() override {}
TearDown()12     void TearDown() override {}
13 };
14 
15 /**
16  * @tc.name: remquo_001
17  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the remquo interface.
18  * @tc.type: FUNC
19  */
20 HWTEST_F(MathRemquoTest, remquo_001, TestSize.Level1)
21 {
22     fesetenv(FE_DFL_ENV);
23     for (int i = 0; i < sizeof(g_remquoData) / sizeof(DataDouble3Int1); i++) {
24         int q;
25         bool testResult = DoubleUlpCmp(g_remquoData[i].expected1, remquo(g_remquoData[i].input1,
26             g_remquoData[i].input2, &q), 1);
27         EXPECT_TRUE(testResult);
28         EXPECT_EQ(g_remquoData[i].expected2, q);
29     }
30 }
31 
32 /**
33  * @tc.name: remquo_002
34  * @tc.desc: When the input parameter is of float type and valid, test the return value of this function.
35  * @tc.type: FUNC
36  */
37 HWTEST_F(MathRemquoTest, remquo_002, TestSize.Level1)
38 {
39     int quotient;
40     double result = remquo(15.0, 6.0, &quotient);
41     EXPECT_EQ(2, quotient);
42     EXPECT_DOUBLE_EQ(3.0, result);
43 }
44 
45 /**
46  * @tc.name: remquo_003
47  * @tc.desc: When the input parameter is of float type and valid, test the return value of this function.
48  * @tc.type: FUNC
49  */
50 HWTEST_F(MathRemquoTest, remquo_003, TestSize.Level1)
51 {
52     int quotient;
53     EXPECT_TRUE(isnan(remquo(nan(""), 15.0, &quotient)));
54     EXPECT_TRUE(isnan(remquo(11.0, nan(""), &quotient)));
55 }
56 
57 /**
58  * @tc.name: remquo_004
59  * @tc.desc: When the input parameter is infinite, test the return value of this function.
60  * @tc.type: FUNC
61  */
62 HWTEST_F(MathRemquoTest, remquo_004, TestSize.Level1)
63 {
64     int quotient;
65     EXPECT_TRUE(isnan(remquo(HUGE_VAL, 15.0, &quotient)));
66     EXPECT_TRUE(isnan(remquo(-HUGE_VAL, 11.0, &quotient)));
67 }
68 
69 /**
70  * @tc.name: remquo_005
71  * @tc.desc: When the input parameter is valid, test the return value of this function.
72  * @tc.type: FUNC
73  */
74 HWTEST_F(MathRemquoTest, remquo_005, TestSize.Level1)
75 {
76     int quotient;
77     EXPECT_TRUE(isnan(remquo(14.0, 0.0, &quotient)));
78 }
79 
80 /**
81  * @tc.name: remquof_001
82  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the remquof interface.
83  * @tc.type: FUNC
84  */
85 HWTEST_F(MathRemquoTest, remquof_001, TestSize.Level1)
86 {
87     fesetenv(FE_DFL_ENV);
88     for (int i = 0; i < sizeof(g_remquofData) / sizeof(DataFloat3Int1); i++) {
89         int q;
90         bool testResult1 = FloatUlpCmp(g_remquofData[i].expected1, remquof(g_remquofData[i].input1,
91             g_remquofData[i].input2, &q), 1);
92         EXPECT_TRUE(testResult1);
93         bool testResult2 = FloatUlpCmp(g_remquofData[i].expected2, q, 1);
94         EXPECT_TRUE(testResult2);
95     }
96 }
97 
98 /**
99  * @tc.name: remquof_002
100  * @tc.desc: When the input parameter is of float type and valid, test the return value of this function.
101  * @tc.type: FUNC
102  */
103 HWTEST_F(MathRemquoTest, remquof_002, TestSize.Level1)
104 {
105     int quotient;
106     double result = remquof(15.0f, 6.0f, &quotient);
107     EXPECT_EQ(2, quotient);
108     EXPECT_DOUBLE_EQ(3.0, result);
109 }
110 
111 /**
112  * @tc.name: remquof_003
113  * @tc.desc: When the input parameter is of float type and valid, test the return value of this function.
114  * @tc.type: FUNC
115  */
116 HWTEST_F(MathRemquoTest, remquof_003, TestSize.Level1)
117 {
118     int quotient;
119     EXPECT_TRUE(isnan(remquof(nanf(""), 15.0f, &quotient)));
120     EXPECT_TRUE(isnan(remquof(11.0f, nanf(""), &quotient)));
121 }
122 
123 /**
124  * @tc.name: remquof_004
125  * @tc.desc: When the input parameter is infinite, test the return value of this function.
126  * @tc.type: FUNC
127  */
128 HWTEST_F(MathRemquoTest, remquof_004, TestSize.Level1)
129 {
130     int quotient;
131     EXPECT_TRUE(isnan(remquof(HUGE_VAL, 15.0f, &quotient)));
132     EXPECT_TRUE(isnan(remquof(-HUGE_VAL, 11.0f, &quotient)));
133 }
134 
135 /**
136  * @tc.name: remquof_005
137  * @tc.desc: When the input parameter is valid, test the return value of this function.
138  * @tc.type: FUNC
139  */
140 HWTEST_F(MathRemquoTest, remquof_005, TestSize.Level1)
141 {
142     int quotient;
143     EXPECT_TRUE(isnan(remquof(14.0f, 0.0f, &quotient)));
144 }