-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_test.c
77 lines (70 loc) · 2.13 KB
/
list_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
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
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "list.c"
void test_list_element_construct() {
Element* element = list_element_construct(1, 2);
assert(element->begin == 1);
assert(element->end == 2);
printf("\tList element construct test passed\n");
}
void test_list_construct() {
List* list = list_construct();
assert(list->length == 0);
assert(list_empty(list));
printf("\tList construct test passed\n");
}
void test_list_push() {
List* list = list_construct();
assert(list_empty(list));
list_push(list, 1, 2);
assert(list->length == 1);
assert(list->head->begin == 1);
assert(list->head->end == 2);
assert(list->head == list->tail);
assert(! list_empty(list));
list_push(list, 3, 4);
assert(list->length == 2);
assert(list->head->begin == 1);
assert(list->head->end == 2);
assert(list->tail->begin == 3);
assert(list->tail->end == 4);
assert(list->head->next == list->tail);
printf("\tList push test passed\n");
}
void test_list_int_tostring() {
char *first = list_int_tostring(12);
assert(! strcmp(first, "12"));
char *second = list_int_tostring(123450);
assert(! strcmp(second, "123450"));
char *third = list_int_tostring(0);
assert(! strcmp(third, "0"));
printf("\tInt to string test passed\n");
}
void test_list_element_tostring() {
Element* element = list_element_construct(1235, 23556);
char* string = list_element_tostring(element);
assert(! strcmp(string, "<1235, 23556>"));
printf("\tList element tostring test passed\n");
}
void test_list_tostring() {
List* list = list_construct();
char* empty_list_str = list_tostring(list);
assert(! strcmp(empty_list_str, "Empty list"));
list_push(list, 1235, 23456);
list_push(list, 888, 2934);
char* list_str = list_tostring(list);
assert(! strcmp(list_str, "List: <1235, 23456>, <888, 2934>"));
printf("\tList tostring test passed\n");
}
int main(void) {
printf("List module tests running\n");
test_list_element_construct();
test_list_construct();
test_list_push();
test_list_int_tostring();
test_list_element_tostring();
test_list_tostring();
printf("List module all tests passed\n");
return 0;
}