• 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/fmodf_data.h"
6 #include "math_test_data/fmod_data.h"
7 
8 using namespace testing::ext;
9 
10 class MathFmodTest : public testing::Test {
SetUp()11     void SetUp() override {}
TearDown()12     void TearDown() override {}
13 };
14 
15 /**
16  * @tc.name: fmod_001
17  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the fmod interface.
18  * @tc.type: FUNC
19  */
20 HWTEST_F(MathFmodTest, fmod_001, TestSize.Level1)
21 {
22     fesetenv(FE_DFL_ENV);
23     for (int i = 0; i < sizeof(g_fmodData) / sizeof(DataDouble3Expected1); i++) {
24         bool testResult = DoubleUlpCmp(g_fmodData[i].expected, fmod(g_fmodData[i].input1, g_fmodData[i].input2), 1);
25         EXPECT_TRUE(testResult);
26     }
27 }
28 
29 /**
30  * @tc.name: fmod_002
31  * @tc.desc: When the parameter of fmod is valid, test the return value of the function.
32  * @tc.type: FUNC
33  */
34 HWTEST_F(MathFmodTest, fmod_002, TestSize.Level1)
35 {
36     EXPECT_DOUBLE_EQ(5.0, fmod(15.0, 10.0));
37 }
38 
39 /**
40  * @tc.name: fmod_003
41  * @tc.desc: When the parameter of fmod is infinite, test the return value of the function.
42  * @tc.type: FUNC
43  */
44 HWTEST_F(MathFmodTest, fmod_003, TestSize.Level1)
45 {
46     EXPECT_TRUE(isnan(fmod(HUGE_VAL, 15.0f)));
47     EXPECT_TRUE(isnan(fmod(-HUGE_VAL, 15.0f)));
48 }
49 
50 /**
51  * @tc.name: fmod_004
52  * @tc.desc: When one of the numbers is NaN, test the return value of the function.
53  * @tc.type: FUNC
54  */
55 HWTEST_F(MathFmodTest, fmod_004, TestSize.Level1)
56 {
57     EXPECT_TRUE(isnan(fmod(nan(""), 14.0)));
58     EXPECT_TRUE(isnan(fmod(14.0, nan(""))));
59 }
60 
61 /**
62  * @tc.name: fmod_005
63  * @tc.desc: When the second operand is valid, test the return value of the function.
64  * @tc.type: FUNC
65  */
66 HWTEST_F(MathFmodTest, fmod_005, TestSize.Level1)
67 {
68     EXPECT_TRUE(isnan(fmod(4.0, 0.0)));
69 }
70 
71 /**
72  * @tc.name: fmodf_001
73  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the fmodf interface.
74  * @tc.type: FUNC
75  */
76 HWTEST_F(MathFmodTest, fmodf_001, TestSize.Level1)
77 {
78     fesetenv(FE_DFL_ENV);
79     for (int i = 0; i < sizeof(g_fmodfData) / sizeof(DataFloat3Expected1); i++) {
80         bool testResult = FloatUlpCmp(g_fmodfData[i].expected, fmodf(g_fmodfData[i].input1, g_fmodfData[i].input2), 1);
81         EXPECT_TRUE(testResult);
82     }
83 }
84 
85 /**
86  * @tc.name: fmodf_002
87  * @tc.desc: When the parameter of fmodf is valid, test the return value of the function.
88  * @tc.type: FUNC
89  */
90 HWTEST_F(MathFmodTest, fmodf_002, TestSize.Level1)
91 {
92     EXPECT_FLOAT_EQ(5.0f, fmodf(15.0f, 10.0f));
93 }
94 
95 /**
96  * @tc.name: fmodf_003
97  * @tc.desc: When the parameter of fmod is infinite, test the return value of the function.
98  * @tc.type: FUNC
99  */
100 HWTEST_F(MathFmodTest, fmodf_003, TestSize.Level1)
101 {
102     EXPECT_TRUE(isnan(fmodf(HUGE_VAL, 15.0f)));
103     EXPECT_TRUE(isnan(fmodf(-HUGE_VAL, 15.0f)));
104 }
105 
106 /**
107  * @tc.name: fmodf_004
108  * @tc.desc: When one of the numbers is NaN, test the return value of the function.
109  * @tc.type: FUNC
110  */
111 HWTEST_F(MathFmodTest, fmodf_004, TestSize.Level1)
112 {
113     EXPECT_TRUE(isnan(fmodf(nanf(""), 14.0f)));
114     EXPECT_TRUE(isnan(fmodf(14.0f, nan(""))));
115 }
116 
117 /**
118  * @tc.name: fmodf_005
119  * @tc.desc: When the second operand is valid, test the return value of the function.
120  * @tc.type: FUNC
121  */
122 HWTEST_F(MathFmodTest, fmodf_005, TestSize.Level1)
123 {
124     EXPECT_TRUE(isnan(fmodf(4.0f, 0.0f)));
125 }