-
Notifications
You must be signed in to change notification settings - Fork 11
/
test.c
46 lines (37 loc) · 1 KB
/
test.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
#include <assert.h>
#include <stdio.h>
#include "dlist.h"
void assert_list_is(dlist(int)* list, int* array, int len){
dlist_element(int) *cursor = list->head;
int i;
for (i = 0; i < len; ++i) {
assert(dlistel_data(cursor) == array[i]);
cursor = cursor->next;
}
}
void print_int_list(dlist(int)* list){
printf("list:\n");
dlist_foreach(int, list, cursor){
printf("%d\n", cursor->data);
}
}
int main(void){
dlist(int) *list = NULL;
// Push test
dlist_push(int, list, 5);
dlist_push(int, list, 3);
int array[5] = {5, 3, 0, 0, 0};
assert_list_is(list, array, 2);
// Shift test
dlist_shift(int, list, 2);
assert_list_is(list, (int[]){2, 5, 3, 0, 0}, 3);
// Pop test
int item = dlist_pop(int, list);
assert_list_is(list, (int[]){2, 5}, 2);
// Unshift test
item = dlist_unshift(int, list);
assert_list_is(list, (int[]){5}, 1);
dlist_free(int, list);
puts("Testing complete. No errors.");
return 0;
}