-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_helpers.h
125 lines (110 loc) · 7.92 KB
/
test_helpers.h
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <cstdint>
#ifndef BLACKJACKSTATS_TEST_HELPERS_H
#define BLACKJACKSTATS_TEST_HELPERS_H
bool assert(bool condition, const char* test, uint32_t number);
#define TEST_START(name) \
{ \
printf("|- Test suite: " name "\n"); \
const char* test_name = name; \
uint32_t test_counter = 0;
#define TEST_LOG(...) printf("> " __VA_ARGS__);
#define TEST_ASSERT_TRUE(toRun) \
{ \
bool actual = toRun; \
if (!assert(actual, #toRun " == true", test_counter)) { \
printf("Expected: true\n"); \
printf("Got: false"); \
TEST_END_FAIL() \
return 1; \
} \
} \
test_counter++;
#define TEST_ASSERT_FALSE(toRun) \
{ \
bool actual = toRun; \
if (!assert(!actual, #toRun " == false", test_counter)) { \
printf("Expected: false\n"); \
printf("Got: true"); \
TEST_END_FAIL() \
return 1; \
} \
} \
test_counter++;
#define TEST_ASSERT_EQUAL_TO_INT(toRun, expected) \
{ \
int32_t actual = toRun; \
if (!assert(actual == (expected), #toRun " == (" #expected ")", test_counter)) { \
printf("Expected: "); \
printf(#expected); \
printf("\nGot: %d", actual); \
TEST_END_FAIL() \
return 1; \
} \
} \
test_counter++;
#define TEST_ASSERT_LESS_THAN_INT(toRun, expected) \
{ \
int32_t actual = toRun; \
if (!assert(actual < (expected), #toRun " < (" #expected ")", test_counter)) { \
printf("Expected less than: "); \
printf(#expected); \
printf("\nGot: %d", actual); \
TEST_END_FAIL() \
return 1; \
} \
} \
test_counter++;
#define TEST_ASSERT_LESS_THAN_OR_EQUAL_TO_INT(toRun, expected) \
{ \
int32_t actual = toRun; \
if (!assert(actual <= (expected), #toRun " <= (" #expected ")", test_counter)) { \
printf("Expected less than or equal to: "); \
printf(#expected); \
printf("\nGot: %d", actual); \
TEST_END_FAIL() \
return 1; \
} \
} \
test_counter++;
#define TEST_ASSERT_GREATER_THAN_INT(toRun, expected) \
{ \
int32_t actual = toRun; \
if (!assert(actual > (expected), #toRun " > (" #expected ")", test_counter)) { \
printf("Expected greater than: "); \
printf(#expected); \
printf("\nGot: %d", actual); \
TEST_END_FAIL() \
return 1; \
} \
} \
test_counter++;
#define TEST_ASSERT_GREATER_THAN_OR_EQUAL_TO_INT(toRun, expected) \
{ \
int32_t actual = toRun; \
if (!assert(actual >= (expected), #toRun " >= (" #expected ")", test_counter)) { \
printf("Expected greater than or equal to: "); \
printf(#expected); \
printf("\nGot: %d", actual); \
TEST_END_FAIL() \
return 1; \
} \
} \
test_counter++;
#define TEST_ASSERT_EQUAL_TO_CARD(toRun, expected) \
{ \
card_t actual = toRun; \
if (!assert(actual == (expected), #toRun " == (" #expected ")", test_counter)) { \
printf("Expected: "); \
printf(#expected); \
printf("Got: "); \
printCard(actual); \
TEST_END_FAIL() \
return 1; \
} \
} \
test_counter++;
#define TEST_END() \
printf("|- Test suite: %s...%d tests passed!\n", test_name, test_counter); \
}
#define TEST_END_FAIL() printf("\n|- Test suite: %s...failed!\n", test_name);
#endif //BLACKJACKSTATS_TEST_HELPERS_H