diff options
Diffstat (limited to 'list/test/list_test.c')
-rw-r--r-- | list/test/list_test.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/list/test/list_test.c b/list/test/list_test.c new file mode 100644 index 0000000..a11c713 --- /dev/null +++ b/list/test/list_test.c | |||
@@ -0,0 +1,34 @@ | |||
1 | #include "list.h" | ||
2 | |||
3 | #include "test.h" | ||
4 | |||
5 | #define TEST_LIST_SIZE 10 | ||
6 | |||
7 | // Create an empty list. | ||
8 | TEST_CASE(list_create_empty) { list_make(0, 0); } | ||
9 | |||
10 | // Create a list of a given size. | ||
11 | TEST_CASE(list_create) { | ||
12 | struct list list[TEST_LIST_SIZE]; | ||
13 | list_make(list, TEST_LIST_SIZE); | ||
14 | } | ||
15 | |||
16 | // Iterate over a list. | ||
17 | TEST_CASE(list_traverse) { | ||
18 | int numbers[TEST_LIST_SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | ||
19 | |||
20 | struct list list[TEST_LIST_SIZE]; | ||
21 | list_make(list, TEST_LIST_SIZE); | ||
22 | |||
23 | int count = 0; | ||
24 | int sum = 0; | ||
25 | list_foreach(list, item) { | ||
26 | count++; | ||
27 | sum += numbers[item - list]; | ||
28 | } | ||
29 | |||
30 | TEST_EQUAL(count, TEST_LIST_SIZE); | ||
31 | TEST_EQUAL(sum, TEST_LIST_SIZE * (TEST_LIST_SIZE + 1) / 2); | ||
32 | } | ||
33 | |||
34 | int main() { return 0; } | ||