-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_cmath.c
78 lines (59 loc) · 1.44 KB
/
test_cmath.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#if _MSC_VER
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#include "boolean.h"
#endif
#include <float.h>
#include <stdlib.h>
#include <time.h>
#include "clibs_math.h"
#include "print.h"
#define TEST(cond) { \
if (!(cond)) { \
DEBUG_INFO("Wrong test"); \
passed = FALSE; \
} \
}
int main(void)
{
BOOL passed = TRUE;
TEST(MAX(3, 5) == 5);
TEST(MAX(4.0, 1.0) == 4.0);
TEST(MIN(3, 5) == 3);
TEST(MIN(4.0, 1.0) == 1.0);
TEST(ABS(3.0) == 3.0);
TEST(ABS(-3.0) == 3.0);
TEST(IS_EQUAL(3.14f, 3.14f, 0.01));
TEST(IS_EQUAL(3.14159, 3.14159, 0.00001));
TEST(IS_EQUAL(3.1415927L, 3.1415927L, 0.0000001));
TEST(!IS_EQUAL(3.14f, 3.15f, 0.005));
TEST(!IS_EQUAL(3.14159, 3.14160, 0.000005));
TEST(IS_EQUAL(1.0 / 3.0 + 1.0 / 3.0 + 1.0 / 3.0, 1.0, 0.05));
TEST(IS_EQUAL(1.0 - 0.3 - 0.5 - 0.2, 0.0, 0.05));
TEST(0 < COMPARE(5, 3));
TEST(0 == COMPARE(5, 5));
TEST(0 > COMPARE(3, 5));
TEST(IS_EVEN(4));
TEST(!IS_EVEN(5));
TEST(!IS_ODD(4));
TEST(IS_ODD(5));
{
unsigned a = 3;
unsigned b = 4;
SWAP(a, b);
TEST(4 == a);
TEST(3 == b);
}
{
srand((unsigned) time(NULL));
int n = RANDINT(1, 10);
TEST(1 <= n && n <= 10);
}
TEST(IS_INF(INF + INF));
TEST(IS_NEG_INF(NEG_INF + NEG_INF));
TEST(IS_NaN(INF + NEG_INF));
if (!passed)
return 1;
return 0;
}