• 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/expf_data.h"
6 #include "math_test_data/exp_data.h"
7 
8 using namespace testing::ext;
9 
10 class MathExpTest : public testing::Test {
SetUp()11     void SetUp() override {}
TearDown()12     void TearDown() override {}
13 };
14 
15 /**
16  * @tc.name: exp_001
17  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the exp interface.
18  * @tc.type: FUNC
19  */
20 HWTEST_F(MathExpTest, exp_001, TestSize.Level1)
21 {
22     fesetenv(FE_DFL_ENV);
23     for (int i = 0; i < sizeof(g_expData) / sizeof(DataDoubleDouble); i++) {
24         bool testResult = DoubleUlpCmp(g_expData[i].expected, exp(g_expData[i].input), 1);
25         EXPECT_TRUE(testResult);
26     }
27 }
28 
29 /**
30  * @tc.name: exp_002
31  * @tc.desc: When the parameter of exp is valid, test the return value of the function.
32  * @tc.type: FUNC
33  */
34 HWTEST_F(MathExpTest, exp_002, TestSize.Level1)
35 {
36     EXPECT_DOUBLE_EQ(1.0, exp(0.0));
37     EXPECT_DOUBLE_EQ(M_E, exp(1.0));
38 }
39 
40 /**
41  * @tc.name: expf_001
42  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the expf interface.
43  * @tc.type: FUNC
44  */
45 HWTEST_F(MathExpTest, expf_001, TestSize.Level1)
46 {
47     fesetenv(FE_DFL_ENV);
48     for (int i = 0; i < sizeof(g_expfData) / sizeof(DataFloatFloat); i++) {
49         bool testResult = FloatUlpCmp(g_expfData[i].expected, expf(g_expfData[i].input), 1);
50         EXPECT_TRUE(testResult);
51     }
52 }
53 
54 /**
55  * @tc.name: expf_002
56  * @tc.desc: When the parameter of expf is valid, test the return value of the function.
57  * @tc.type: FUNC
58  */
59 HWTEST_F(MathExpTest, expf_002, TestSize.Level1)
60 {
61     EXPECT_FLOAT_EQ(1.0f, expf(0.0f));
62     EXPECT_FLOAT_EQ(static_cast<float>(M_E), expf(1.0f));
63 }
64 
65 /**
66  * @tc.name: expl_001
67  * @tc.desc: When the parameter of expl is valid, test the return value of the function.
68  * @tc.type: FUNC
69  */
70 HWTEST_F(MathExpTest, expl_001, TestSize.Level1)
71 {
72     EXPECT_DOUBLE_EQ(1.0L, expl(0.0L));
73     EXPECT_DOUBLE_EQ(M_E, expl(1.0L));
74 }