• 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/fmaxf_data.h"
6 #include "math_test_data/fmax_data.h"
7 
8 using namespace testing::ext;
9 
10 class MathFmaxTest : public testing::Test {
SetUp()11     void SetUp() override {}
TearDown()12     void TearDown() override {}
13 };
14 
15 /**
16  * @tc.name: fmax_001
17  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the fmax interface.
18  * @tc.type: FUNC
19  */
20 HWTEST_F(MathFmaxTest, fmax_001, TestSize.Level1)
21 {
22     fesetenv(FE_DFL_ENV);
23     for (int i = 0; i < sizeof(g_fmaxData) / sizeof(DataDouble3Expected1); i++) {
24         bool testResult = DoubleUlpCmp(g_fmaxData[i].expected, fmax(g_fmaxData[i].input1, g_fmaxData[i].input2), 1);
25         EXPECT_TRUE(testResult);
26     }
27 }
28 
29 /**
30  * @tc.name: fmax_002
31  * @tc.desc: When the parameter of fmax is valid, test the return value of the function.
32  * @tc.type: FUNC
33  */
34 HWTEST_F(MathFmaxTest, fmax_002, TestSize.Level1)
35 {
36     EXPECT_DOUBLE_EQ(17.0, fmax(17.0, 17.0));
37     EXPECT_DOUBLE_EQ(15.0, fmax(15.0, nan("")));
38     EXPECT_DOUBLE_EQ(14.0, fmax(nan(""), 14.0));
39 }
40 
41 /**
42  * @tc.name: fmaxf_001
43  * @tc.desc: Obtain test data in sequence and check if it is within the expected error range of the fmaxf interface.
44  * @tc.type: FUNC
45  */
46 HWTEST_F(MathFmaxTest, fmaxf_001, TestSize.Level1)
47 {
48     fesetenv(FE_DFL_ENV);
49     for (int i = 0; i < sizeof(g_fmaxfData) / sizeof(DataFloat3Expected1); i++) {
50         bool testResult = FloatUlpCmp(g_fmaxfData[i].expected, fmaxf(g_fmaxfData[i].input1, g_fmaxfData[i].input2), 1);
51         EXPECT_TRUE(testResult);
52     }
53 }
54 
55 /**
56  * @tc.name: fmaxf_002
57  * @tc.desc: When the parameter of fmaxf is valid, test the return value of the function.
58  * @tc.type: FUNC
59  */
60 HWTEST_F(MathFmaxTest, fmaxf_002, TestSize.Level1)
61 {
62     EXPECT_FLOAT_EQ(17.0f, fmaxf(17.0f, 17.0f));
63     EXPECT_FLOAT_EQ(15.0f, fmaxf(15.0f, nanf("")));
64     EXPECT_FLOAT_EQ(14.0f, fmaxf(nanf(""), 14.0f));
65 }
66 
67 /**
68  * @tc.name: fmaxl_001
69  * @tc.desc: When the parameter of fmaxl is valid, test the return value of the function.
70  * @tc.type: FUNC
71  */
72 HWTEST_F(MathFmaxTest, fmaxl_001, TestSize.Level1)
73 {
74     EXPECT_DOUBLE_EQ(17.0L, fmaxl(17.0L, 17.0L));
75     EXPECT_DOUBLE_EQ(15.0L, fmaxl(15.0L, nanl("")));
76     EXPECT_DOUBLE_EQ(14.0L, fmaxl(nanl(""), 14.0L));
77 }