1 #include <gtest/gtest.h> 2 #include <math.h> 3 4 #include "math_data_test.h" 5 #include "math_test_data/ldexpf_data.h" 6 #include "math_test_data/ldexp_data.h" 7 8 using namespace testing::ext; 9 10 class MathLdexpTest : public testing::Test { SetUp()11 void SetUp() override {} TearDown()12 void TearDown() override {} 13 }; 14 15 /** 16 * @tc.name: ldexp_001 17 * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the ldexp interface. 18 * @tc.type: FUNC 19 */ 20 HWTEST_F(MathLdexpTest, ldexp_001, TestSize.Level1) 21 { 22 fesetenv(FE_DFL_ENV); 23 for (int i = 0; i < sizeof(g_ldexpData) / sizeof(DataDoubleDoubleInt); i++) { 24 bool testResult = DoubleUlpCmp(g_ldexpData[i].expected, ldexp(g_ldexpData[i].input1, g_ldexpData[i].input2), 1); 25 EXPECT_TRUE(testResult); 26 } 27 } 28 29 /** 30 * @tc.name: ldexp_002 31 * @tc.desc: When the value is valid, test the return value of the function. 32 * @tc.type: FUNC 33 */ 34 HWTEST_F(MathLdexpTest, ldexp_002, TestSize.Level1) 35 { 36 EXPECT_DOUBLE_EQ(24.0, ldexp(3.0, 3)); 37 } 38 39 /** 40 * @tc.name: ldexpf_001 41 * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the ldexpf interface. 42 * @tc.type: FUNC 43 */ 44 HWTEST_F(MathLdexpTest, ldexpf_001, TestSize.Level1) 45 { 46 fesetenv(FE_DFL_ENV); 47 for (int i = 0; i < sizeof(g_ldexpfData) / sizeof(DataFloatFloatInt); i++) { 48 bool testResult = FloatUlpCmp(g_ldexpfData[i].expected, ldexpf(g_ldexpfData[i].input1, 49 g_ldexpfData[i].input2), 1); 50 EXPECT_TRUE(testResult); 51 } 52 } 53 54 /** 55 * @tc.name: ldexpf_002 56 * @tc.desc: When the float value is valid, test the return value of the function. 57 * @tc.type: FUNC 58 */ 59 HWTEST_F(MathLdexpTest, ldexpf_002, TestSize.Level1) 60 { 61 EXPECT_FLOAT_EQ(24.0f, ldexpf(3.0f, 3)); 62 } 63 64 /** 65 * @tc.name: ldexpl_001 66 * @tc.desc: When the long double value is valid, test the return value of the function. 67 * @tc.type: FUNC 68 */ 69 HWTEST_F(MathLdexpTest, ldexpl_001, TestSize.Level1) 70 { 71 EXPECT_DOUBLE_EQ(24.0L, ldexpl(3.0L, 3)); 72 }