• 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/ilogbf_data.h"
6 #include "math_test_data/ilogb_data.h"
7 
8 using namespace testing::ext;
9 
10 class MathIlogbTest : public testing::Test {
SetUp()11     void SetUp() override {}
TearDown()12     void TearDown() override {}
13 };
14 
15 /**
16  * @tc.name: ilogb_001
17  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the ilogb interface.
18  * @tc.type: FUNC
19  */
20 HWTEST_F(MathIlogbTest, ilogb_001, TestSize.Level1)
21 {
22     fesetenv(FE_DFL_ENV);
23     for (int i = 0; i < sizeof(g_ilogbData) / sizeof(DataIntDouble); i++) {
24         EXPECT_EQ(g_ilogbData[i].expected, ilogb(g_ilogbData[i].input));
25     }
26 }
27 
28 /**
29  * @tc.name: ilogb_002
30  * @tc.desc: When the value is valid, test the return value of the function.
31  * @tc.type: FUNC
32  */
33 HWTEST_F(MathIlogbTest, ilogb_002, TestSize.Level1)
34 {
35     EXPECT_EQ(FP_ILOGB0, ilogb(0.0));
36 }
37 
38 /**
39  * @tc.name: ilogb_003
40  * @tc.desc: When the value is nan, test the return value of the function.
41  * @tc.type: FUNC
42  */
43 HWTEST_F(MathIlogbTest, ilogb_003, TestSize.Level1)
44 {
45     EXPECT_EQ(FP_ILOGBNAN, ilogb(nan("")));
46 }
47 
48 /**
49  * @tc.name: ilogb_004
50  * @tc.desc: When the input parameters are valid, test the return value of this function.
51  * @tc.type: FUNC
52  */
53 HWTEST_F(MathIlogbTest, ilogb_004, TestSize.Level1)
54 {
55     EXPECT_EQ(INT_MAX, ilogb(HUGE_VAL));
56     EXPECT_EQ(INT_MAX, ilogb(-HUGE_VAL));
57 }
58 
59 /**
60  * @tc.name: ilogb_005
61  * @tc.desc: When the value is valid, test the return value of the function.
62  * @tc.type: FUNC
63  */
64 HWTEST_F(MathIlogbTest, ilogb_005, TestSize.Level1)
65 {
66     EXPECT_EQ(2, ilogb(4.0));
67     EXPECT_EQ(3, ilogb(8.0));
68 }
69 
70 /**
71  * @tc.name: ilogbf_001
72  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the ilogbf interface.
73  * @tc.type: FUNC
74  */
75 HWTEST_F(MathIlogbTest, ilogbf_001, TestSize.Level1)
76 {
77     fesetenv(FE_DFL_ENV);
78     for (int i = 0; i < sizeof(g_ilogbfData) / sizeof(DataIntFloat); i++) {
79         EXPECT_EQ(g_ilogbfData[i].expected, ilogbf(g_ilogbfData[i].input));
80     }
81 }
82 
83 /**
84  * @tc.name: ilogbf_002
85  * @tc.desc: When the float value is valid, test the return value of the function.
86  * @tc.type: FUNC
87  */
88 HWTEST_F(MathIlogbTest, ilogbf_002, TestSize.Level1)
89 {
90     EXPECT_EQ(FP_ILOGB0, ilogbf(0.0f));
91 }
92 
93 /**
94  * @tc.name: ilogbf_003
95  * @tc.desc: When the float value is nan, test the return value of the function.
96  * @tc.type: FUNC
97  */
98 HWTEST_F(MathIlogbTest, ilogbf_003, TestSize.Level1)
99 {
100     EXPECT_EQ(FP_ILOGBNAN, ilogbf(nan("")));
101 }
102 
103 /**
104  * @tc.name: ilogbf_004
105  * @tc.desc: When the input parameter is valid, test the return value of this function.
106  * @tc.type: FUNC
107  */
108 HWTEST_F(MathIlogbTest, ilogbf_004, TestSize.Level1)
109 {
110     EXPECT_EQ(INT_MAX, ilogbf(HUGE_VAL));
111     EXPECT_EQ(INT_MAX, ilogbf(-HUGE_VAL));
112 }
113 
114 /**
115  * @tc.name: ilogbf_005
116  * @tc.desc: When the float value is 4.0f, 8.0f, test the return value of the function.
117  * @tc.type: FUNC
118  */
119 HWTEST_F(MathIlogbTest, ilogbf_005, TestSize.Level1)
120 {
121     EXPECT_EQ(2, ilogbf(4.0f));
122     EXPECT_EQ(3, ilogbf(8.0f));
123 }
124 
125 /**
126  * @tc.name: ilogbl_001
127  * @tc.desc: When the long double value is 0.0L, test the return value of the function.
128  * @tc.type: FUNC
129  */
130 HWTEST_F(MathIlogbTest, ilogbl_001, TestSize.Level1)
131 {
132     EXPECT_EQ(FP_ILOGB0, ilogbl(0.0L));
133 }
134 
135 /**
136  * @tc.name: ilogbl_002
137  * @tc.desc: When the long double value is nan, test the return value of the function.
138  * @tc.type: FUNC
139  */
140 HWTEST_F(MathIlogbTest, ilogbl_002, TestSize.Level1)
141 {
142     EXPECT_EQ(FP_ILOGBNAN, ilogbl(nan("")));
143 }
144 
145 /**
146  * @tc.name: ilogbl_003
147  * @tc.desc: When the input parameter is valid, test the return value of this function.
148  * @tc.type: FUNC
149  */
150 HWTEST_F(MathIlogbTest, ilogbl_003, TestSize.Level1)
151 {
152     EXPECT_EQ(INT_MAX, ilogbl(HUGE_VAL));
153     EXPECT_EQ(INT_MAX, ilogbl(-HUGE_VAL));
154 }
155 
156 /**
157  * @tc.name: ilogbl_004
158  * @tc.desc: When the long double value is 4.0f, 8.0f, test the return value of the function.
159  * @tc.type: FUNC
160  */
161 HWTEST_F(MathIlogbTest, ilogbl_004, TestSize.Level1)
162 {
163     EXPECT_EQ(2, ilogbl(4.0L));
164     EXPECT_EQ(3, ilogbl(8.0L));
165 }