aboutsummaryrefslogtreecommitdiff
path: root/list/test/list_test.c
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2024-06-15 11:43:10 -0700
committer3gg <3gg@shellblade.net>2024-06-15 11:43:10 -0700
commitbec2d50c843ec4fd98bbbb212848ce4f24b96ebb (patch)
tree59c33bc964e723350886035fe249e41d0f8b397e /list/test/list_test.c
parent04e3ded4c28c0b559620609daaae7b939d776b61 (diff)
More convenient list iteration.
Diffstat (limited to 'list/test/list_test.c')
-rw-r--r--list/test/list_test.c20
1 files changed, 10 insertions, 10 deletions
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 @@
4 4
5#define TEST_LIST_SIZE 10 5#define TEST_LIST_SIZE 10
6 6
7DEF_LIST(int); 7DEF_LIST(int, int);
8 8
9// Iterate over a list. 9// Iterate over a list.
10TEST_CASE(list_traverse) { 10TEST_CASE(list_traverse) {
11 int_list list = make_list(int); 11 int_list list = make_list(int);
12 for (int i = 0; i < TEST_LIST_SIZE; ++i) { 12 for (int i = 0; i < TEST_LIST_SIZE; ++i) {
13 list_push(list, i + 1); 13 list_add(list, i + 1);
14 } 14 }
15 15
16 int count = 0; 16 int count = 0;
17 int sum = 0; 17 int sum = 0;
18 list_foreach(list, { 18 list_foreach(list, value, {
19 count++; 19 count++;
20 sum += *value; 20 sum += value;
21 }); 21 });
22 22
23 TEST_EQUAL(count, TEST_LIST_SIZE); 23 TEST_EQUAL(count, TEST_LIST_SIZE);
@@ -30,16 +30,16 @@ TEST_CASE(list_traverse) {
30TEST_CASE(list_remove_by_value) { 30TEST_CASE(list_remove_by_value) {
31 int_list list = make_list(int); 31 int_list list = make_list(int);
32 for (int i = 0; i < TEST_LIST_SIZE; ++i) { 32 for (int i = 0; i < TEST_LIST_SIZE; ++i) {
33 list_push(list, i + 1); 33 list_add(list, i + 1);
34 } 34 }
35 35
36 list_remove(list, 5); 36 list_remove(list, 5);
37 37
38 int count = 0; 38 int count = 0;
39 int sum = 0; 39 int sum = 0;
40 list_foreach(list, { 40 list_foreach(list, value, {
41 count++; 41 count++;
42 sum += *value; 42 sum += value;
43 }); 43 });
44 44
45 TEST_EQUAL(count, TEST_LIST_SIZE - 1); 45 TEST_EQUAL(count, TEST_LIST_SIZE - 1);
@@ -56,7 +56,7 @@ TEST_CASE(list_remove_by_address) {
56 56
57 int_list list = make_list(int); 57 int_list list = make_list(int);
58 for (int i = 0; i < N; ++i) { 58 for (int i = 0; i < N; ++i) {
59 list_push(list, i + 1); 59 list_add(list, i + 1);
60 ptrs[i] = &list.head->val; 60 ptrs[i] = &list.head->val;
61 } 61 }
62 62
@@ -64,9 +64,9 @@ TEST_CASE(list_remove_by_address) {
64 64
65 int count = 0; 65 int count = 0;
66 int sum = 0; 66 int sum = 0;
67 list_foreach(list, { 67 list_foreach(list, value, {
68 count++; 68 count++;
69 sum += *value; 69 sum += value;
70 }); 70 });
71 71
72 TEST_EQUAL(count, 2); 72 TEST_EQUAL(count, 2);