1 #include <gtest/gtest.h> 2 #include <math.h> 3 4 #include "math_data_test.h" 5 #include "math_test_data/sincosf_data.h" 6 #include "math_test_data/sincos_data.h" 7 8 using namespace testing::ext; 9 10 class MathSincosTest : public testing::Test { SetUp()11 void SetUp() override {} TearDown()12 void TearDown() override {} 13 }; 14 15 /** 16 * @tc.name: sincos_001 17 * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the sincos interface. 18 * @tc.type: FUNC 19 */ 20 HWTEST_F(MathSincosTest, sincos_001, TestSize.Level1) 21 { 22 fesetenv(FE_DFL_ENV); 23 for (int i = 0; i < sizeof(g_sincosData) / sizeof(DataDouble3Expected2); i++) { 24 double s, c; 25 sincos(g_sincosData[i].input, &s, &c); 26 bool testResult1 = DoubleUlpCmp(g_sincosData[i].expected1, s, 1); 27 EXPECT_TRUE(testResult1); 28 bool testResult2 = DoubleUlpCmp(g_sincosData[i].expected2, c, 1); 29 EXPECT_TRUE(testResult2); 30 } 31 } 32 33 /** 34 * @tc.name: sincos_002 35 * @tc.desc: When the input parameters are valid, test the return value of this function. 36 * @tc.type: FUNC 37 */ 38 HWTEST_F(MathSincosTest, sincos_002, TestSize.Level1) 39 { 40 double sineResult, cosineResult; 41 sincos(0.0, &sineResult, &cosineResult); 42 EXPECT_DOUBLE_EQ(0.0, sineResult); 43 EXPECT_DOUBLE_EQ(1.0, cosineResult); 44 } 45 46 /** 47 * @tc.name: sincosf_001 48 * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the sincos interface. 49 * @tc.type: FUNC 50 */ 51 HWTEST_F(MathSincosTest, sincosf_001, TestSize.Level1) 52 { 53 fesetenv(FE_DFL_ENV); 54 for (int i = 0; i < sizeof(g_sincosfData) / sizeof(DataFloat3Expected2); i++) { 55 float s, c; 56 sincosf(g_sincosfData[i].input, &s, &c); 57 bool testResult1 = FloatUlpCmp(g_sincosfData[i].expected1, s, 1); 58 EXPECT_TRUE(testResult1); 59 bool testResult2 = FloatUlpCmp(g_sincosfData[i].expected2, c, 1); 60 EXPECT_TRUE(testResult2); 61 } 62 } 63 64 /** 65 * @tc.name: sincosf_002 66 * @tc.desc: When the input parameter is of float type and valid, test the return value of this function. 67 * @tc.type: FUNC 68 */ 69 HWTEST_F(MathSincosTest, sincosf_002, TestSize.Level1) 70 { 71 float sineResult, cosineResult; 72 sincosf(0.0f, &sineResult, &cosineResult); 73 EXPECT_FLOAT_EQ(0.0f, sineResult); 74 EXPECT_FLOAT_EQ(1.0f, cosineResult); 75 } 76 77 /** 78 * @tc.name: sincosl_001 79 * @tc.desc: When the input parameter is of long double type and valid, test the return value of this function. 80 * @tc.type: FUNC 81 */ 82 HWTEST_F(MathSincosTest, sincosl_001, TestSize.Level1) 83 { 84 long double sineResult, cosineResult; 85 sincosl(0.0L, &sineResult, &cosineResult); 86 EXPECT_DOUBLE_EQ(0.0L, sineResult); 87 EXPECT_DOUBLE_EQ(1.0L, cosineResult); 88 }