1 #include <gtest/gtest.h> 2 #include <math.h> 3 4 #include "math_data_test.h" 5 #include "math_test_data/pow_data.h" 6 #include "math_test_data/powf_data.h" 7 8 using namespace testing::ext; 9 10 class MathPowTest : public testing::Test { SetUp()11 void SetUp() override {} TearDown()12 void TearDown() override {} 13 }; 14 15 /** 16 * @tc.name: pow_001 17 * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the pow interface. 18 * @tc.type: FUNC 19 */ 20 HWTEST_F(MathPowTest, pow_001, TestSize.Level1) 21 { 22 fesetenv(FE_DFL_ENV); 23 for (int i = 0; i < sizeof(g_powData) / sizeof(DataDouble3Expected1); i++) { 24 bool testResult = DoubleUlpCmp(g_powData[i].expected, pow(g_powData[i].input1, g_powData[i].input2), 1); 25 EXPECT_TRUE(testResult); 26 } 27 } 28 29 /** 30 * @tc.name: pow_002 31 * @tc.desc: When the input parameters are valid, test the return value of this function. 32 * @tc.type: FUNC 33 */ 34 HWTEST_F(MathPowTest, pow_002, TestSize.Level1) 35 { 36 EXPECT_TRUE(isnan(pow(nan(""), 5.0))); 37 EXPECT_TRUE(isnan(pow(4.0, nan("")))); 38 } 39 40 /** 41 * @tc.name: pow_003 42 * @tc.desc: When the input parameters are valid, test the return value of this function. 43 * @tc.type: FUNC 44 */ 45 HWTEST_F(MathPowTest, pow_003, TestSize.Level1) 46 { 47 EXPECT_DOUBLE_EQ(1.0, (pow(1.0, nan("")))); 48 EXPECT_DOUBLE_EQ(9.0, pow(3.0, 2.0)); 49 } 50 51 /** 52 * @tc.name: powf_001 53 * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the powf interface. 54 * @tc.type: FUNC 55 */ 56 HWTEST_F(MathPowTest, powf_001, TestSize.Level1) 57 { 58 fesetenv(FE_DFL_ENV); 59 for (int i = 0; i < sizeof(g_powfData) / sizeof(DataFloat3Expected1); i++) { 60 bool testResult = FloatUlpCmp(g_powfData[i].expected, powf(g_powfData[i].input1, g_powfData[i].input2), 1); 61 EXPECT_TRUE(testResult); 62 } 63 } 64 65 /** 66 * @tc.name: powf_002 67 * @tc.desc: When the input parameter is of float type and valid, test the return value of this function. 68 * @tc.type: FUNC 69 */ 70 HWTEST_F(MathPowTest, powf_002, TestSize.Level1) 71 { 72 EXPECT_TRUE(isnan(powf(nanf(""), 3.0f))); 73 EXPECT_TRUE(isnan(powf(2.0f, nanf("")))); 74 } 75 76 /** 77 * @tc.name: powf_003 78 * @tc.desc: When the input parameter is of float type and valid, test the return value of this function. 79 * @tc.type: FUNC 80 */ 81 HWTEST_F(MathPowTest, powf_003, TestSize.Level1) 82 { 83 EXPECT_DOUBLE_EQ(1.0f, (powf(1.0f, nanf("")))); 84 EXPECT_DOUBLE_EQ(9.0f, powf(3.0f, 2.0f)); 85 }