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