• 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/modff_data.h"
6 #include "math_test_data/modf_data.h"
7 
8 using namespace testing::ext;
9 
10 class MathModfTest : public testing::Test {
SetUp()11     void SetUp() override {}
TearDown()12     void TearDown() override {}
13 };
14 
15 /**
16  * @tc.name: modf_001
17  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the modf interface.
18  * @tc.type: FUNC
19  */
20 HWTEST_F(MathModfTest, modf_001, TestSize.Level1)
21 {
22     fesetenv(FE_DFL_ENV);
23     for (int i = 0; i < sizeof(g_modfData) / sizeof(DataDouble3Expected2); i++) {
24         double di;
25         bool testResult1 = DoubleUlpCmp(g_modfData[i].expected1, modf(g_modfData[i].input, &di), 1);
26         EXPECT_TRUE(testResult1);
27         bool testResult2 = DoubleUlpCmp(g_modfData[i].expected2, di, 1);
28         EXPECT_TRUE(testResult2);
29     }
30 }
31 
32 /**
33  * @tc.name: modf_002
34  * @tc.desc: When the input parameters are valid, test the return value of this function.
35  * @tc.type: FUNC
36  */
37 HWTEST_F(MathModfTest, modf_002, TestSize.Level1)
38 {
39     double integerPart;
40     double decimalPart = modf(8.125, &integerPart);
41     EXPECT_DOUBLE_EQ(8.0, integerPart);
42     EXPECT_DOUBLE_EQ(0.125, decimalPart);
43 }
44 
45 /**
46  * @tc.name: modff_001
47  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the modff interface.
48  * @tc.type: FUNC
49  */
50 HWTEST_F(MathModfTest, modff_001, TestSize.Level1)
51 {
52     fesetenv(FE_DFL_ENV);
53     for (int i = 0; i < sizeof(g_modffData) / sizeof(DataFloat3Expected2); i++) {
54         float di;
55         bool testResult1 = FloatUlpCmp(g_modffData[i].expected1, modff(g_modffData[i].input, &di), 1);
56         EXPECT_TRUE(testResult1);
57         bool testResult2 = FloatUlpCmp(g_modffData[i].expected2, di, 1);
58         EXPECT_TRUE(testResult2);
59     }
60 }
61 
62 /**
63  * @tc.name: modff_002
64  * @tc.desc: When the input parameter is of float type and valid, test the return value of this function.
65  * @tc.type: FUNC
66  */
67 HWTEST_F(MathModfTest, modff_002, TestSize.Level1)
68 {
69     float integralPart;
70     float fractionalPart = modff(8.125f, &integralPart);
71     EXPECT_FLOAT_EQ(8.0f, integralPart);
72     EXPECT_FLOAT_EQ(0.125f, fractionalPart);
73 }
74 
75 /**
76  * @tc.name: modfl_001
77  * @tc.desc: When the input parameter is of long double type and valid, test the return value of this function.
78  * @tc.type: FUNC
79  */
80 HWTEST_F(MathModfTest, modfl_001, TestSize.Level1)
81 {
82     long double integralPart;
83     long double fractionalPart = modfl(8.125L, &integralPart);
84     EXPECT_FLOAT_EQ(8.0L, integralPart);
85     EXPECT_FLOAT_EQ(0.125L, fractionalPart);
86 }