From bec2d50c843ec4fd98bbbb212848ce4f24b96ebb Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 15 Jun 2024 11:43:10 -0700 Subject: More convenient list iteration. --- list/test/list_test.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'list/test') diff --git a/list/test/list_test.c b/list/test/list_test.c index 9ff10c1..418e156 100644 --- a/list/test/list_test.c +++ b/list/test/list_test.c @@ -4,20 +4,20 @@ #define TEST_LIST_SIZE 10 -DEF_LIST(int); +DEF_LIST(int, int); // Iterate over a list. TEST_CASE(list_traverse) { int_list list = make_list(int); for (int i = 0; i < TEST_LIST_SIZE; ++i) { - list_push(list, i + 1); + list_add(list, i + 1); } int count = 0; int sum = 0; - list_foreach(list, { + list_foreach(list, value, { count++; - sum += *value; + sum += value; }); TEST_EQUAL(count, TEST_LIST_SIZE); @@ -30,16 +30,16 @@ TEST_CASE(list_traverse) { TEST_CASE(list_remove_by_value) { int_list list = make_list(int); for (int i = 0; i < TEST_LIST_SIZE; ++i) { - list_push(list, i + 1); + list_add(list, i + 1); } list_remove(list, 5); int count = 0; int sum = 0; - list_foreach(list, { + list_foreach(list, value, { count++; - sum += *value; + sum += value; }); TEST_EQUAL(count, TEST_LIST_SIZE - 1); @@ -56,7 +56,7 @@ TEST_CASE(list_remove_by_address) { int_list list = make_list(int); for (int i = 0; i < N; ++i) { - list_push(list, i + 1); + list_add(list, i + 1); ptrs[i] = &list.head->val; } @@ -64,9 +64,9 @@ TEST_CASE(list_remove_by_address) { int count = 0; int sum = 0; - list_foreach(list, { + list_foreach(list, value, { count++; - sum += *value; + sum += value; }); TEST_EQUAL(count, 2); -- cgit v1.2.3