• 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/log1pf_data.h"
6 #include "math_test_data/log1p_data.h"
7 
8 using namespace testing::ext;
9 
10 class MathLog1pTest : public testing::Test {
SetUp()11     void SetUp() override {}
TearDown()12     void TearDown() override {}
13 };
14 
15 /**
16  * @tc.name: log1p_001
17  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the log1p interface.
18  * @tc.type: FUNC
19  */
20 HWTEST_F(MathLog1pTest, log1p_001, TestSize.Level1)
21 {
22     fesetenv(FE_DFL_ENV);
23     for (int i = 0; i < sizeof(g_log1pData) / sizeof(DataDoubleDouble); i++) {
24         bool testResult = DoubleUlpCmp(g_log1pData[i].expected, log1p(g_log1pData[i].input), 1);
25         EXPECT_TRUE(testResult);
26     }
27 }
28 
29 /**
30  * @tc.name: log1p_002
31  * @tc.desc: When the value is -1.0, test the return value of the function.
32  * @tc.type: FUNC
33  */
34 HWTEST_F(MathLog1pTest, log1p_002, TestSize.Level1)
35 {
36     EXPECT_EQ(-HUGE_VAL, log1p(-1.0));
37 }
38 
39 /**
40  * @tc.name: log1p_003
41  * @tc.desc: When the input parameters are valid, test the return value of this function.
42  * @tc.type: FUNC
43  */
44 HWTEST_F(MathLog1pTest, log1p_003, TestSize.Level1)
45 {
46     EXPECT_TRUE(isnan(log1p(-HUGE_VAL)));
47     EXPECT_TRUE(isnan(log1p(nan(""))));
48 }
49 
50 /**
51  * @tc.name: log1p_004
52  * @tc.desc: When the input parameters are valid, test the return value of this function.
53  * @tc.type: FUNC
54  */
55 HWTEST_F(MathLog1pTest, log1p_004, TestSize.Level1)
56 {
57     EXPECT_TRUE(isinf(log1p(HUGE_VAL)));
58 }
59 
60 /**
61  * @tc.name: log1p_005
62  * @tc.desc: When the input parameters are valid, test the return value of this function.
63  * @tc.type: FUNC
64  */
65 HWTEST_F(MathLog1pTest, log1p_005, TestSize.Level1)
66 {
67     EXPECT_DOUBLE_EQ(1.0, log1p(M_E - 1.0));
68 }
69 
70 /**
71  * @tc.name: log1pf_001
72  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the log1pf interface.
73  * @tc.type: FUNC
74  */
75 HWTEST_F(MathLog1pTest, log1pf_001, TestSize.Level1)
76 {
77     fesetenv(FE_DFL_ENV);
78     for (int i = 0; i < sizeof(g_log1pfData) / sizeof(DataFloatFloat); i++) {
79         bool testResult = FloatUlpCmp(g_log1pfData[i].expected, log1pf(g_log1pfData[i].input), 1);
80         EXPECT_TRUE(testResult);
81     }
82 }
83 
84 /**
85  * @tc.name: log1pf_002
86  * @tc.desc: When the float value is -1.0f, test the return value of the function.
87  * @tc.type: FUNC
88  */
89 HWTEST_F(MathLog1pTest, log1pf_002, TestSize.Level1)
90 {
91     EXPECT_EQ(-HUGE_VAL, log1pf(-1.0f));
92 }
93 
94 /**
95  * @tc.name: log1pf_003
96  * @tc.desc: When the input parameter is of float type and valid, test the return value of this function.
97  * @tc.type: FUNC
98  */
99 HWTEST_F(MathLog1pTest, log1pf_003, TestSize.Level1)
100 {
101     EXPECT_TRUE(isnan(log1pf(-HUGE_VAL)));
102     EXPECT_TRUE(isnan(log1pf(nanf(""))));
103 }
104 
105 /**
106  * @tc.name: log1pf_004
107  * @tc.desc: When the input parameter is of float type and valid, test the return value of this function.
108  * @tc.type: FUNC
109  */
110 HWTEST_F(MathLog1pTest, log1pf_004, TestSize.Level1)
111 {
112     EXPECT_TRUE(isinf(log1pf(HUGE_VAL)));
113 }
114 
115 /**
116  * @tc.name: log1pf_005
117  * @tc.desc: When the input parameter is of float type and valid, test the return value of this function.
118  * @tc.type: FUNC
119  */
120 HWTEST_F(MathLog1pTest, log1pf_005, TestSize.Level1)
121 {
122     EXPECT_DOUBLE_EQ(1.0f, log1pf(static_cast<float>(M_E) - 1.0f));
123 }