• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 #include <math.h>
3 
4 using namespace testing::ext;
5 
6 class MathNexttowardTest : public testing::Test {
SetUp()7     void SetUp() override {}
TearDown()8     void TearDown() override {}
9 };
10 
11 /**
12  * @tc.name: nexttoward_001
13  * @tc.desc: When the input parameters are valid, test the return value of this function.
14  * @tc.type: FUNC
15  */
16 HWTEST_F(MathNexttowardTest, nexttoward_001, TestSize.Level1)
17 {
18     EXPECT_DOUBLE_EQ(0.0, nexttoward(0.0, 0.0L));
19     EXPECT_DOUBLE_EQ(4.9406564584124654e-324, nexttoward(0.0, 1.0L));
20     EXPECT_DOUBLE_EQ(-4.9406564584124654e-324, nexttoward(0.0, -1.0L));
21 }
22 
23 /**
24  * @tc.name: nexttowardf_001
25  * @tc.desc: When the input parameter is of float type and valid, test the return value of this function.
26  * @tc.type: FUNC
27  */
28 HWTEST_F(MathNexttowardTest, nexttowardf_001, TestSize.Level1)
29 {
30     EXPECT_FLOAT_EQ(0.0f, nexttowardf(0.0f, 0.0L));
31     EXPECT_FLOAT_EQ(1.4012985e-45f, nexttowardf(0.0f, 1.0L));
32     EXPECT_FLOAT_EQ(-1.4012985e-45f, nexttowardf(0.0f, -1.0L));
33 }
34 
35 /**
36  * @tc.name: nexttowardl_001
37  * @tc.desc: When the input parameter is of long double type and valid, test the return value of this function.
38  * @tc.type: FUNC
39  */
40 HWTEST_F(MathNexttowardTest, nexttowardl_001, TestSize.Level1)
41 {
42     EXPECT_DOUBLE_EQ(0.0L, nexttowardl(0.0L, 0.0L));
43     long double minPositive = ldexpl(1.0L, LDBL_MIN_EXP - LDBL_MANT_DIG);
44     EXPECT_DOUBLE_EQ(minPositive, nexttowardl(0.0L, 1.0L));
45     EXPECT_DOUBLE_EQ(-minPositive, nexttowardl(0.0L, -1.0L));
46 }
47