-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
97 lines (72 loc) · 1.92 KB
/
test.c
File metadata and controls
97 lines (72 loc) · 1.92 KB
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
#include <stdbool.h>
#include "array.h"
#include "test.h"
int main(void) {
int* numbers = NULL;
TEST_SECTION("Array initialization & Free") {
ARRAY(numbers, 0);
if (!numbers) exit(EXIT_FAILURE);
CHECK_BOOL(
ARRAY_CAPACITY(numbers) == 4,
"Default array capacity if not specified",
""
);
CHECK_BOOL(
ARRAY_COUNT(numbers) == 0,
"Array count is 0 at initialization",
""
);
ARRAY_FREE(numbers);
ARRAY(numbers, 5);
CHECK_BOOL(
ARRAY_CAPACITY(numbers) == 5,
"Array capacity matches given input value",
""
);
};
TEST_SECTION("Array append && Pop") {
ARRAY_APPEND(numbers, 1);
CHECK_BOOL(
ARRAY_COUNT(numbers) == 1,
"Array appending increments count",
""
);
int popped = ARRAY_POP(numbers);
CHECK_BOOL(
popped == 1,
"Pop returns last element",
""
);
for (size_t i = 0; i < 7; ++i) {
ARRAY_APPEND(numbers, (int)i);
}
CHECK_BOOL(
ARRAY_CAPACITY(numbers) == 10,
"Array capacity doubling",
""
);
bool match = 1;
for (int i = 0; i < (int) ARRAY_COUNT(numbers); ++i) {
if (numbers[i] != i) {
match = 0;
break;
}
}
CHECK_BOOL(
match,
"Appended values match (beyond capacity)",
""
);
};
TEST_SECTION("Array shrink") {
ARRAY_SHRINK_TO_FIT(numbers);
CHECK_BOOL(
ARRAY_CAPACITY(numbers) == ARRAY_COUNT(numbers),
"Shrink reduces capacity to array count",
""
);
};
ARRAY_FREE(numbers);
TEST_SUMMARY();
exit(EXIT_SUCCESS);
}