1 #include <gtest/gtest.h> 2 #include <math.h> 3 4 #include "math_data_test.h" 5 #include "math_test_data/significandf_data.h" 6 #include "math_test_data/significand_data.h" 7 8 using namespace testing::ext; 9 10 class MathSignificandTest : public testing::Test { SetUp()11 void SetUp() override {} TearDown()12 void TearDown() override {} 13 }; 14 15 /** 16 * @tc.name: significand_001 17 * @tc.desc: Obtain test data in sequence and check if it is within the expected error range 18 * of the significand interface. 19 * @tc.type: FUNC 20 */ 21 HWTEST_F(MathSignificandTest, significand_001, TestSize.Level1) 22 { 23 fesetenv(FE_DFL_ENV); 24 for (int i = 0; i < sizeof(g_significandData) / sizeof(DataDoubleDouble); i++) { 25 bool testResult = DoubleUlpCmp(g_significandData[i].expected, significand(g_significandData[i].input), 1); 26 EXPECT_TRUE(testResult); 27 } 28 } 29 30 /** 31 * @tc.name: significand_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(MathSignificandTest, significand_002, TestSize.Level1) 36 { 37 EXPECT_DOUBLE_EQ(0.0, significand(0.0)); 38 EXPECT_DOUBLE_EQ(1.2, significand(1.2)); 39 EXPECT_DOUBLE_EQ(1.53125, significand(12.25)); 40 } 41 42 /** 43 * @tc.name: significandf_001 44 * @tc.desc: Obtain test data in sequence and check if it is within the expected error range 45 * of the significandf interface. 46 * @tc.type: FUNC 47 */ 48 HWTEST_F(MathSignificandTest, significandf_001, TestSize.Level1) 49 { 50 fesetenv(FE_DFL_ENV); 51 for (int i = 0; i < sizeof(g_significandfData) / sizeof(DataFloatFloat); i++) { 52 bool testResult = FloatUlpCmp(g_significandfData[i].expected, significandf(g_significandfData[i].input), 1); 53 EXPECT_TRUE(testResult); 54 } 55 } 56 57 /** 58 * @tc.name: significandf_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(MathSignificandTest, significandf_002, TestSize.Level1) 63 { 64 EXPECT_FLOAT_EQ(0.0f, significandf(0.0f)); 65 EXPECT_FLOAT_EQ(1.2f, significandf(1.2f)); 66 EXPECT_FLOAT_EQ(1.53125f, significandf(12.25f)); 67 }