1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *   http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include <math.h>
17#include "functionalext.h"
18
19typedef void (*TEST_FUN)();
20const int SUCCESS = 1;
21const int FAILED = 0;
22
23/**
24 * @tc.name      : finite_0100
25 * @tc.desc      : The parameter is 0.0, it is judged that the parameter is a finite value.
26 * @tc.level     : Level 0
27 */
28void finite_0100(void)
29{
30    int ret = finite(0.0);
31    EXPECT_EQ("finite_0100", ret, SUCCESS);
32}
33
34/**
35 * @tc.name      : finite_0200
36 * @tc.desc      : The parameter is DBL_MIN/2.0, and it is judged that the parameter is a finite value
37 * @tc.level     : Level 0
38 */
39void finite_0200(void)
40{
41    int ret = finite(__DBL_MIN__ / 2);
42    EXPECT_EQ("finite_0100", ret, SUCCESS);
43}
44
45/**
46 * @tc.name      : finite_0300
47 * @tc.desc      : If the parameter is NAN, it is judged that the parameter is not a finite value.
48 * @tc.level     : Level 2
49 */
50void finite_0300(void)
51{
52    int ret = finite(NAN);
53    EXPECT_EQ("finite_0100", ret, FAILED);
54}
55
56/**
57 * @tc.name      : finite_0400
58 * @tc.desc      : If the parameter is INFINITY, it is judged that the parameter is not a finite value.
59 * @tc.level     : Level 2
60 */
61void finite_0400(void)
62{
63    int ret = finite(INFINITY);
64    EXPECT_EQ("finite_0400", ret, FAILED);
65}
66
67/**
68 * @tc.name      : finite_0500
69 * @tc.desc      : If the parameter is sqrt(-1.0), it is judged that the parameter is not a finite value.
70 * @tc.level     : Level 2
71 */
72void finite_0500(void)
73{
74    int ret = finite(sqrt(-1.0));
75    EXPECT_EQ("finite_0500", ret, FAILED);
76}
77
78/**
79 * @tc.name      : finite_0600
80 * @tc.desc      : If the parameter is exp(800), it is judged that the parameter is not a finite value.
81 * @tc.level     : Level 2
82 */
83void finite_0600(void)
84{
85    int ret = finite(exp(800));
86    EXPECT_EQ("finite_0600", ret, FAILED);
87}
88
89TEST_FUN G_Fun_Array[] = {
90    finite_0100,
91    finite_0200,
92    finite_0300,
93    finite_0400,
94    finite_0500,
95    finite_0600,
96};
97
98int main(int argc, char *argv[])
99{
100    int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
101    for (int pos = 0; pos < num; ++pos) {
102        G_Fun_Array[pos]();
103    }
104
105    return t_status;
106}