aboutsummaryrefslogtreecommitdiff
path: root/list/test/list_test.c
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2021-12-04 16:01:12 -0800
committer3gg <3gg@shellblade.net>2021-12-04 16:01:12 -0800
commitf8217d240d598f39f70047f7a623dd46312542c6 (patch)
tree4e40843d665e388416c1226f739c2b8c0b8da736 /list/test/list_test.c
parent5f6ea503cdb6ad4a95b679672a1ad324d96c89a5 (diff)
Initial commit.
Diffstat (limited to 'list/test/list_test.c')
-rw-r--r--list/test/list_test.c34
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.
8TEST_CASE(list_create_empty) { list_make(0, 0); }
9
10// Create a list of a given size.
11TEST_CASE(list_create) {
12 struct list list[TEST_LIST_SIZE];
13 list_make(list, TEST_LIST_SIZE);
14}
15
16// Iterate over a list.
17TEST_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
34int main() { return 0; }