• 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/hypotf_data.h"
6 #include "math_test_data/hypot_data.h"
7 
8 using namespace testing::ext;
9 
10 class MathHypotTest : public testing::Test {
SetUp()11     void SetUp() override {}
TearDown()12     void TearDown() override {}
13 };
14 
15 /**
16  * @tc.name: hypot_001
17  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the hypot interface.
18  * @tc.type: FUNC
19  */
20 HWTEST_F(MathHypotTest, hypot_001, TestSize.Level1)
21 {
22     fesetenv(FE_DFL_ENV);
23     for (int i = 0; i < sizeof(g_hypotData) / sizeof(DataDouble3Expected1); i++) {
24         bool testResult = DoubleUlpCmp(g_hypotData[i].expected, hypot(g_hypotData[i].input1, g_hypotData[i].input2), 1);
25         EXPECT_TRUE(testResult);
26     }
27 }
28 
29 /**
30  * @tc.name: hypot_002
31  * @tc.desc: When the value is 6.0, 8.0, test the return value of the function.
32  * @tc.type: FUNC
33  */
34 HWTEST_F(MathHypotTest, hypot_002, TestSize.Level1)
35 {
36     EXPECT_DOUBLE_EQ(10.0, hypot(6.0, 8.0));
37 }
38 
39 /**
40  * @tc.name: hypot_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(MathHypotTest, hypot_003, TestSize.Level1)
45 {
46     EXPECT_EQ(HUGE_VAL, hypot(4.0, HUGE_VAL));
47     EXPECT_EQ(HUGE_VAL, hypot(4.0, -HUGE_VAL));
48     EXPECT_EQ(HUGE_VAL, hypot(HUGE_VAL, 5.0));
49     EXPECT_EQ(HUGE_VAL, hypot(-HUGE_VAL, 5.0));
50 }
51 
52 /**
53  * @tc.name: hypot_004
54  * @tc.desc: When the input parameters are valid, test the return value of this function.
55  * @tc.type: FUNC
56  */
57 HWTEST_F(MathHypotTest, hypot_004, TestSize.Level1)
58 {
59     EXPECT_TRUE(isnan(hypot(6.0, nan(""))));
60     EXPECT_TRUE(isnan(hypot(nan(""), 8.0)));
61 }
62 
63 /**
64  * @tc.name: hypotf_001
65  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the hypotf interface.
66  * @tc.type: FUNC
67  */
68 HWTEST_F(MathHypotTest, hypotf_001, TestSize.Level1)
69 {
70     fesetenv(FE_DFL_ENV);
71     for (int i = 0; i < sizeof(g_hypotfData) / sizeof(DataFloat3Expected1); i++) {
72         bool testResult = FloatUlpCmp(g_hypotfData[i].expected, hypotf(g_hypotfData[i].input1, g_hypotfData[i].input2), 1);
73         EXPECT_TRUE(testResult);
74     }
75 }
76 
77 /**
78  * @tc.name: hypotf_002
79  * @tc.desc: When the value is 6.0f, 8.0f, test the return value of the function.
80  * @tc.type: FUNC
81  */
82 HWTEST_F(MathHypotTest, hypotf_002, TestSize.Level1)
83 {
84     EXPECT_DOUBLE_EQ(10.0f, hypotf(6.0f, 8.0f));
85 }
86 
87 /**
88  * @tc.name: hypotf_003
89  * @tc.desc:  This test is used to detect whether expectations are met when the parameter
90  *           is equal to infinity.
91  * @tc.type: FUNC
92  */
93 HWTEST_F(MathHypotTest, hypotf_003, TestSize.Level1)
94 {
95     EXPECT_EQ(HUGE_VAL, hypotf(4.0f, HUGE_VAL));
96     EXPECT_EQ(HUGE_VAL, hypotf(4.0f, -HUGE_VAL));
97     EXPECT_EQ(HUGE_VAL, hypotf(HUGE_VAL, 5.0f));
98     EXPECT_EQ(HUGE_VAL, hypotf(-HUGE_VAL, 5.0f));
99 }
100 
101 /**
102  * @tc.name: hypotf_004
103  * @tc.desc: When the input parameter is of float type and valid, test the return value of this function.
104  * @tc.type: FUNC
105  */
106 HWTEST_F(MathHypotTest, hypotf_004, TestSize.Level1)
107 {
108     EXPECT_TRUE(isnan(hypotf(6.0f, nan(""))));
109     EXPECT_TRUE(isnan(hypotf(nan(""), 8.0f)));
110 }