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