1 #include <gtest/gtest.h> 2 #include <math.h> 3 4 #include "math_data_test.h" 5 #include "math_test_data/nextafterf_data.h" 6 #include "math_test_data/nextafter_data.h" 7 8 using namespace testing::ext; 9 10 class MathNearafterTest : public testing::Test { SetUp()11 void SetUp() override {} TearDown()12 void TearDown() override {} 13 }; 14 15 /** 16 * @tc.name: nextafter_001 17 * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the nextafter interface. 18 * @tc.type: FUNC 19 */ 20 HWTEST_F(MathNearafterTest, nextafter_001, TestSize.Level1) 21 { 22 fesetenv(FE_DFL_ENV); 23 for (int i = 0; i < sizeof(g_nextafterData) / sizeof(DataDouble3Expected1); i++) { 24 bool testResult = DoubleUlpCmp(g_nextafterData[i].expected, nextafter(g_nextafterData[i].input1, 25 g_nextafterData[i].input2), 1); 26 EXPECT_TRUE(testResult); 27 } 28 } 29 30 /** 31 * @tc.name: nextafter_002 32 * @tc.desc: When the input parameters are valid, test the return value of this function. 33 * @tc.type: FUNC 34 */ 35 HWTEST_F(MathNearafterTest, nextafter_002, TestSize.Level1) 36 { 37 EXPECT_DOUBLE_EQ(0.0, nextafter(0.0, 0.0)); 38 EXPECT_DOUBLE_EQ(4.9406564584124654e-324, nextafter(0.0, 1.0)); 39 EXPECT_DOUBLE_EQ(-4.9406564584124654e-324, nextafter(0.0, -1.0)); 40 } 41 42 /** 43 * @tc.name: nextafterf_001 44 * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the nextafterf interface. 45 * @tc.type: FUNC 46 */ 47 HWTEST_F(MathNearafterTest, nextafterf_001, TestSize.Level1) 48 { 49 fesetenv(FE_DFL_ENV); 50 for (int i = 0; i < sizeof(g_nextafterfData) / sizeof(DataFloat3Expected1); i++) { 51 bool testResult = FloatUlpCmp(g_nextafterfData[i].expected, nextafterf(g_nextafterfData[i].input1, 52 g_nextafterfData[i].input2), 1); 53 EXPECT_TRUE(testResult); 54 } 55 } 56 57 /** 58 * @tc.name: nextafterf_002 59 * @tc.desc: When the input parameter is of float type and valid, test the return value of this function. 60 * @tc.type: FUNC 61 */ 62 HWTEST_F(MathNearafterTest, nextafterf_002, TestSize.Level1) 63 { 64 EXPECT_FLOAT_EQ(0.0f, nextafterf(0.0f, 0.0f)); 65 EXPECT_FLOAT_EQ(1.4012985e-45f, nextafterf(0.0f, 1.0f)); 66 EXPECT_FLOAT_EQ(-1.4012985e-45f, nextafterf(0.0f, -1.0f)); 67 } 68 69 /** 70 * @tc.name: nextafterl_001 71 * @tc.desc: When the input parameter is of long double type and valid, test the return value of this function. 72 * @tc.type: FUNC 73 */ 74 HWTEST_F(MathNearafterTest, nextafterl_001, TestSize.Level1) 75 { 76 EXPECT_DOUBLE_EQ(0.0L, nextafterl(0.0L, 0.0L)); 77 long double minPositive = ldexpl(1.0L, LDBL_MIN_EXP - LDBL_MANT_DIG); 78 EXPECT_DOUBLE_EQ(minPositive, nextafterl(0.0L, 1.0L)); 79 EXPECT_DOUBLE_EQ(-minPositive, nextafterl(0.0L, -1.0L)); 80 } 81