• 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/logbf_data.h"
6 #include "math_test_data/logb_data.h"
7 
8 using namespace testing::ext;
9 
10 class MathLogbTest : public testing::Test {
SetUp()11     void SetUp() override {}
TearDown()12     void TearDown() override {}
13 };
14 
15 /**
16  * @tc.name: logb_001
17  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the logb interface.
18  * @tc.type: FUNC
19  */
20 HWTEST_F(MathLogbTest, logb_001, TestSize.Level1)
21 {
22     fesetenv(FE_DFL_ENV);
23     for (int i = 0; i < sizeof(g_logbData) / sizeof(DataDoubleDouble); i++) {
24         bool testResult = DoubleUlpCmp(g_logbData[i].expected, logb(g_logbData[i].input), 1);
25         EXPECT_TRUE(testResult);
26     }
27 }
28 
29 /**
30  * @tc.name: logb_002
31  * @tc.desc: When the input parameter is 0, test the return value of the function.
32  * @tc.type: FUNC
33  */
34 HWTEST_F(MathLogbTest, logb_002, TestSize.Level1)
35 {
36     EXPECT_EQ(-HUGE_VAL, logb(0.0));
37 }
38 
39 /**
40  * @tc.name: logb_003
41  * @tc.desc: When the input parameter is NaN, test the return value of the function.
42  * @tc.type: FUNC
43  */
44 HWTEST_F(MathLogbTest, logb_003, TestSize.Level1)
45 {
46     EXPECT_TRUE(isnan(logb(nan(""))));
47 }
48 
49 /**
50  * @tc.name: logb_004
51  * @tc.desc: When the input parameter is positive infinity or negative infinity, test the return value of the function.
52  * @tc.type: FUNC
53  */
54 HWTEST_F(MathLogbTest, logb_004, TestSize.Level1)
55 {
56     EXPECT_TRUE(isinf(logb(HUGE_VAL)));
57     EXPECT_TRUE(isinf(logb(-HUGE_VAL)));
58 }
59 
60 /**
61  * @tc.name: logb_005
62  * @tc.desc: When the input parameter is valid, test the return value of the function.
63  * @tc.type: FUNC
64  */
65 HWTEST_F(MathLogbTest, logb_005, TestSize.Level1)
66 {
67     EXPECT_EQ(0.0, logb(1.0));
68     EXPECT_EQ(3.0, logb(10.0));
69 }
70 
71 /**
72  * @tc.name: logbf_001
73  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the logbf interface.
74  * @tc.type: FUNC
75  */
76 HWTEST_F(MathLogbTest, logbf_001, TestSize.Level1)
77 {
78     fesetenv(FE_DFL_ENV);
79     for (int i = 0; i < sizeof(g_logbfData) / sizeof(DataFloatFloat); i++) {
80         bool testResult = FloatUlpCmp(g_logbfData[i].expected, logbf(g_logbfData[i].input), 1);
81         EXPECT_TRUE(testResult);
82     }
83 }
84 
85 /**
86  * @tc.name: logbf_002
87  * @tc.desc: When the input parameter is valid, test the return value of the function.
88  * @tc.type: FUNC
89  */
90 HWTEST_F(MathLogbTest, logbf_002, TestSize.Level1)
91 {
92     EXPECT_EQ(-HUGE_VAL, logbf(0.0f));
93 }
94 
95 /**
96  * @tc.name: logbf_003
97  * @tc.desc: When the input parameter is NaN, test the return value of the function.
98  * @tc.type: FUNC
99  */
100 HWTEST_F(MathLogbTest, logbf_003, TestSize.Level1)
101 {
102     EXPECT_TRUE(isnan(logbf(nanf(""))));
103 }
104 
105 /**
106  * @tc.name: logbf_004
107  * @tc.desc: When the input parameter is positive infinity or negative infinity, test the return value of the function.
108  * @tc.type: FUNC
109  */
110 HWTEST_F(MathLogbTest, logbf_004, TestSize.Level1)
111 {
112     EXPECT_TRUE(isinf(logbf(HUGE_VAL)));
113     EXPECT_TRUE(isinf(logbf(-HUGE_VAL)));
114 }
115 
116 /**
117  * @tc.name: logbf_005
118  * @tc.desc: When the input parameter is valid, test the return value of the function.
119  * @tc.type: FUNC
120  */
121 HWTEST_F(MathLogbTest, logbf_005, TestSize.Level1)
122 {
123     EXPECT_EQ(0.0f, logbf(1.0f));
124     EXPECT_EQ(3.0f, logbf(10.0f));
125 }
126 
127 /**
128  * @tc.name: logbl_001
129  * @tc.desc: When the input parameter is valid, test the return value of the function.
130  * @tc.type: FUNC
131  */
132 HWTEST_F(MathLogbTest, logbl_001, TestSize.Level1)
133 {
134     EXPECT_EQ(-HUGE_VAL, logbl(0.0L));
135 }
136 
137 /**
138  * @tc.name: logbl_002
139  * @tc.desc: When the input parameter is NaN, test the return value of the function.
140  * @tc.type: FUNC
141  */
142 HWTEST_F(MathLogbTest, logbl_002, TestSize.Level1)
143 {
144     EXPECT_TRUE(isnan(logbl(nanl(""))));
145 }
146 
147 /**
148  * @tc.name: logbl_003
149  * @tc.desc: When the input parameter is positive infinity or negative infinity, test the return value of the function.
150  * @tc.type: FUNC
151  */
152 HWTEST_F(MathLogbTest, logbl_003, TestSize.Level1)
153 {
154     EXPECT_TRUE(isinf(logbl(HUGE_VAL)));
155     EXPECT_TRUE(isinf(logbl(-HUGE_VAL)));
156 }
157 
158 /**
159  * @tc.name: logbl_004
160  * @tc.desc: When the input parameter is valid, test the return value of the function.
161  * @tc.type: FUNC
162  */
163 HWTEST_F(MathLogbTest, logbl_004, TestSize.Level1)
164 {
165     EXPECT_EQ(0.0L, logbl(1.0L));
166     EXPECT_EQ(3.0L, logbl(10.0L));
167 }