From f8217d240d598f39f70047f7a623dd46312542c6 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 4 Dec 2021 16:01:12 -0800 Subject: Initial commit. --- list/test/list_test.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 list/test/list_test.c (limited to 'list/test/list_test.c') 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 @@ +#include "list.h" + +#include "test.h" + +#define TEST_LIST_SIZE 10 + +// Create an empty list. +TEST_CASE(list_create_empty) { list_make(0, 0); } + +// Create a list of a given size. +TEST_CASE(list_create) { + struct list list[TEST_LIST_SIZE]; + list_make(list, TEST_LIST_SIZE); +} + +// Iterate over a list. +TEST_CASE(list_traverse) { + int numbers[TEST_LIST_SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + + struct list list[TEST_LIST_SIZE]; + list_make(list, TEST_LIST_SIZE); + + int count = 0; + int sum = 0; + list_foreach(list, item) { + count++; + sum += numbers[item - list]; + } + + TEST_EQUAL(count, TEST_LIST_SIZE); + TEST_EQUAL(sum, TEST_LIST_SIZE * (TEST_LIST_SIZE + 1) / 2); +} + +int main() { return 0; } -- cgit v1.2.3