• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 #include <math.h>
3 
4 #include "math_data_test.h"
5 #include "math_test_data/fdimf_data.h"
6 #include "math_test_data/fdim_data.h"
7 
8 using namespace testing::ext;
9 
10 class MathFdimTest : public testing::Test {
SetUp()11     void SetUp() override {}
TearDown()12     void TearDown() override {}
13 };
14 
15 /**
16  * @tc.name: fdim_001
17  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the fdim interface.
18  * @tc.type: FUNC
19  */
20 HWTEST_F(MathFdimTest, fdim_001, TestSize.Level1)
21 {
22     fesetenv(FE_DFL_ENV);
23     for (int i = 0; i < sizeof(g_fdimData) / sizeof(DataDouble3Expected1); i++) {
24         bool testResult = DoubleUlpCmp(g_fdimData[i].expected, fdim(g_fdimData[i].input1, g_fdimData[i].input2), 1);
25         EXPECT_TRUE(testResult);
26     }
27 }
28 
29 /**
30  * @tc.name: fdim_002
31  * @tc.desc: When the parameter of fdim is valid, test the return value of the function.
32  * @tc.type: FUNC
33  */
34 HWTEST_F(MathFdimTest, fdim_002, TestSize.Level1)
35 {
36     EXPECT_DOUBLE_EQ(2.0, fdim(3.0, 1.0));
37     EXPECT_DOUBLE_EQ(2.0, fdim(5.0, 3.0));
38     EXPECT_DOUBLE_EQ(0.0, fdim(1.0, 2.0));
39 }
40 
41 /**
42  * @tc.name: fdimf_001
43  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the fdimf interface.
44  * @tc.type: FUNC
45  */
46 HWTEST_F(MathFdimTest, fdimf_001, TestSize.Level1)
47 {
48     fesetenv(FE_DFL_ENV);
49     for (int i = 0; i < sizeof(g_fdimfData) / sizeof(DataFloat3Expected1); i++) {
50         bool testResult = FloatUlpCmp(g_fdimfData[i].expected, fdimf(g_fdimfData[i].input1, g_fdimfData[i].input2), 1);
51         EXPECT_TRUE(testResult);
52     }
53 }
54 
55 /**
56  * @tc.name: fdimf_002
57  * @tc.desc: When the parameter of fdimf is valid, test the return value of the function.
58  * @tc.type: FUNC
59  */
60 HWTEST_F(MathFdimTest, fdimf_002, TestSize.Level1)
61 {
62     EXPECT_FLOAT_EQ(2.0f, fdimf(3.0f, 1.0f));
63     EXPECT_FLOAT_EQ(2.0f, fdimf(5.0f, 3.0f));
64     EXPECT_FLOAT_EQ(0.0f, fdimf(1.0f, 2.0f));
65 }
66 
67 /**
68  * @tc.name: fdiml_001
69  * @tc.desc: When the parameter of fdiml is valid, test the return value of the function.
70  * @tc.type: FUNC
71  */
72 HWTEST_F(MathFdimTest, fdiml_001, TestSize.Level1)
73 {
74     EXPECT_DOUBLE_EQ(2.0L, fdiml(3.0L, 1.0L));
75     EXPECT_DOUBLE_EQ(2.0L, fdiml(5.0L, 3.0L));
76     EXPECT_DOUBLE_EQ(0.0L, fdiml(1.0L, 2.0L));
77 }