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