• 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/frexpf_data.h"
6 #include "math_test_data/frexp_data.h"
7 
8 using namespace testing::ext;
9 
10 class MathFrexpTest : public testing::Test {
SetUp()11     void SetUp() override {}
TearDown()12     void TearDown() override {}
13 };
14 
15 /**
16  * @tc.name: frexp_001
17  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the frexp interface.
18  * @tc.type: FUNC
19  */
20 HWTEST_F(MathFrexpTest, frexp_001, TestSize.Level1)
21 {
22     fesetenv(FE_DFL_ENV);
23     for (int i = 0; i < sizeof(g_frexpData) / sizeof(DataDoubleIntDouble); i++) {
24         int exp;
25         bool testResult = DoubleUlpCmp(g_frexpData[i].expected1, frexp(g_frexpData[i].input, &exp), 1);
26         EXPECT_TRUE(testResult);
27         EXPECT_EQ(exp, g_frexpData[i].expected2);
28     }
29 }
30 
31 /**
32  * @tc.name: frexp_002
33  * @tc.desc: When the input parameters are valid, test the return value of this function.
34  * @tc.type: FUNC
35  */
36 HWTEST_F(MathFrexpTest, frexp_002, TestSize.Level1)
37 {
38     int exponent;
39     double inputNum = 2048.0;
40     double fraction = frexp(inputNum, &exponent);
41     EXPECT_DOUBLE_EQ(2048.0, scalbn(fraction, exponent));
42 }
43 
44 /**
45  * @tc.name: frexpf_001
46  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the frexpf interface.
47  * @tc.type: FUNC
48  */
49 HWTEST_F(MathFrexpTest, frexpf_001, TestSize.Level1)
50 {
51     fesetenv(FE_DFL_ENV);
52     for (int i = 0; i < sizeof(g_frexpfData) / sizeof(DataFloatIntFloat); i++) {
53         int exp;
54         bool testResult = FloatUlpCmp(g_frexpfData[i].expected1, frexpf(g_frexpfData[i].input, &exp), 1);
55         EXPECT_TRUE(testResult);
56         EXPECT_EQ(exp, g_frexpfData[i].expected2);
57     }
58 }
59 
60 /**
61  * @tc.name: frexpf_002
62  * @tc.desc: When the input parameter is of float type and valid, test the return value of this function.
63  * @tc.type: FUNC
64  */
65 HWTEST_F(MathFrexpTest, frexpf_002, TestSize.Level1)
66 {
67     int exponent;
68     float inputNum = 2048.0f;
69     float fraction = frexpf(inputNum, &exponent);
70     EXPECT_FLOAT_EQ(2048.0f, scalbnf(fraction, exponent));
71 }
72 
73 /**
74  * @tc.name: frexpf_003
75  * @tc.desc: When the input parameter is of float type and valid, test the return value of this function.
76  * @tc.type: FUNC
77  */
78 HWTEST_F(MathFrexpTest, frexpf_003, TestSize.Level1)
79 {
80     int exponent;
81     float inputNum = 6.3f;
82     float fraction = frexpf(inputNum, &exponent);
83     EXPECT_FLOAT_EQ(6.3f, scalbnf(fraction, exponent));
84 }
85 
86 /**
87  * @tc.name: frexpl_001
88  * @tc.desc: When the input parameter is of long double type and valid, test the return value of this function.
89  * @tc.type: FUNC
90  */
91 HWTEST_F(MathFrexpTest, frexpl_001, TestSize.Level1)
92 {
93     int exponent;
94     long double inputNum = 2048.0L;
95     long double fraction = frexpl(inputNum, &exponent);
96     EXPECT_DOUBLE_EQ(2048.0L, scalbnl(fraction, exponent));
97 }