-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests_3.c
63 lines (58 loc) · 1.86 KB
/
tests_3.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
#include "tests_3.h"
int test_3()
{
generic_stack(uint) *gs_u = new_generic_stack_ptr(uint)(3);
GENERIC_STACK_LOG(uint, gs_u, 10, "[capacity == 4]");
if (gs_u->capacity != 4) {
printf("error capacity!");
exit(1);
}
generic_stack_push(uint)(gs_u, 1);
generic_stack_push(uint)(gs_u, 2);
generic_stack_push(uint)(gs_u, 3);
generic_stack_push(uint)(gs_u, 4);
generic_stack_push(uint)(gs_u, 5);
generic_stack_push(uint)(gs_u, 6);
GENERIC_STACK_LOG(uint, gs_u, 10, "[capacity == 8]");
if (gs_u->capacity != 8) {
printf("error capacity!");
exit(1);
}
generic_stack_set_capacity(uint)(gs_u, 12);
GENERIC_STACK_LOG(uint, gs_u, 10, "[capacity == 16]");
if (gs_u->capacity != 16) {
printf("error capacity!");
exit(1);
}
if (generic_stack_pop(uint)(gs_u) != 6) {
printf("error in pop!");
exit(1);
}
generic_stack_squeeze_capacity(uint)(gs_u);
GENERIC_STACK_LOG(uint, gs_u, 10, "[capacity == 8]");
if (gs_u->capacity != 8) {
printf("error capacity!");
exit(1);
}
generic_stack_set_capacity(uint)(gs_u, 3); // be careful with it
GENERIC_STACK_LOG(uint, gs_u, 10, "[capacity == 4]");
if (generic_stack_pop(uint)(gs_u) != 3) {
printf("error in pop!");
exit(1);
}
generic_stack_set_capacity(uint)(gs_u, 0);
GENERIC_STACK_LOG(uint, gs_u, 10, "[ptr == NULL]");
if (gs_u->ptr != NULL) {
printf("error in set capacity!");
exit(1);
}
generic_stack_push(uint)(gs_u, 1);
generic_stack_push(uint)(gs_u, 2);
GENERIC_STACK_LOG(uint, gs_u, 10, "[capacity == 2]");
if (generic_stack_pop(uint)(gs_u) != 2) {
printf("error in pop!");
exit(1);
}
free_generic_stack(uint)(gs_u);
return 0;
}