1 #include <gtest/gtest.h> 2 #include <math.h> 3 4 #include "math_data_test.h" 5 #include "math_test_data/exp2f_data.h" 6 #include "math_test_data/exp2_data.h" 7 8 using namespace testing::ext; 9 10 class MathExp2Test : public testing::Test { SetUp()11 void SetUp() override {} TearDown()12 void TearDown() override {} 13 }; 14 15 /** 16 * @tc.name: exp2_001 17 * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the exp2 interface. 18 * @tc.type: FUNC 19 */ 20 HWTEST_F(MathExp2Test, exp2_001, TestSize.Level1) 21 { 22 fesetenv(FE_DFL_ENV); 23 for (int i = 0; i < sizeof(g_exp2Data) / sizeof(DataDoubleDouble); i++) { 24 bool testResult = DoubleUlpCmp(g_exp2Data[i].expected, exp2(g_exp2Data[i].input), 1); 25 EXPECT_TRUE(testResult); 26 } 27 } 28 29 /** 30 * @tc.name: exp2_002 31 * @tc.desc: When the parameter of exp2 is valid, test the return value of the function. 32 * @tc.type: FUNC 33 */ 34 HWTEST_F(MathExp2Test, exp2_002, TestSize.Level1) 35 { 36 EXPECT_DOUBLE_EQ(8.0, exp2(3.0)); 37 } 38 39 /** 40 * @tc.name: exp2_003 41 * @tc.desc: The test code can check whether the expo2() and log2() functions correctly 42 * implement exponential and logarithmic operations on the OpenBSD system, and return the expected results. 43 * @tc.type: FUNC 44 */ 45 HWTEST_F(MathExp2Test, exp2_003, TestSize.Level1) 46 { 47 EXPECT_DOUBLE_EQ(10.0, exp2(log2(10))); 48 EXPECT_FLOAT_EQ(10.0f, exp2f(log2f(10))); 49 EXPECT_DOUBLE_EQ(10.0L, exp2l(log2l(10))); 50 } 51 52 /** 53 * @tc.name: exp2f_001 54 * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the exp2f interface. 55 * @tc.type: FUNC 56 */ 57 HWTEST_F(MathExp2Test, exp2f_001, TestSize.Level1) 58 { 59 fesetenv(FE_DFL_ENV); 60 for (int i = 0; i < sizeof(g_exp2fData) / sizeof(DataFloatFloat); i++) { 61 bool testResult = FloatUlpCmp(g_exp2fData[i].expected, exp2f(g_exp2fData[i].input), 1); 62 EXPECT_TRUE(testResult); 63 } 64 } 65 66 /** 67 * @tc.name: exp2f_002 68 * @tc.desc: When the parameter of exp2f is valid, test the return value of the function. 69 * @tc.type: FUNC 70 */ 71 HWTEST_F(MathExp2Test, exp2f_002, TestSize.Level1) 72 { 73 EXPECT_FLOAT_EQ(8.0f, exp2f(3.0f)); 74 } 75 76 /** 77 * @tc.name: exp2l_001 78 * @tc.desc: When the parameter of exp2l is valid, test the return value of the function. 79 * @tc.type: FUNC 80 */ 81 HWTEST_F(MathExp2Test, exp2l_001, TestSize.Level1) 82 { 83 EXPECT_DOUBLE_EQ(8.0L, exp2l(3.0L)); 84 }