diff options
author | Bruno Haible <bruno@clisp.org> | 2021-04-03 18:25:56 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2021-04-03 18:30:52 +0200 |
commit | 0cdb81c92993b8b1e41aee9df2170f5dc35e86b8 (patch) | |
tree | 749fd1ce37ef34561213a229382673be596e7cf4 /tests | |
parent | e108960209b3c13c2d43d745c0898c8778bff186 (diff) | |
download | gnulib-0cdb81c92993b8b1e41aee9df2170f5dc35e86b8.tar.gz |
*-list tests: Add more tests.
* tests/test-array_list.c (check_equals_by_forward_iteration,
check_equals_by_backward_iteration): New functions.
(main): Invoke them.
* tests/test-carray_list.c: Likewise.
* tests/test-linked_list.c: Likewise.
* tests/test-linkedhash_list.c: Likewise.
* tests/test-avltree_list.c: Likewise.
* tests/test-avltreehash_list.c: Likewise.
* tests/test-rbtree_list.c: Likewise.
* tests/test-rbtreehash_list.c: Likewise.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-array_list.c | 39 | ||||
-rw-r--r-- | tests/test-avltree_list.c | 33 | ||||
-rw-r--r-- | tests/test-avltreehash_list.c | 33 | ||||
-rw-r--r-- | tests/test-carray_list.c | 33 | ||||
-rw-r--r-- | tests/test-linked_list.c | 33 | ||||
-rw-r--r-- | tests/test-linkedhash_list.c | 33 | ||||
-rw-r--r-- | tests/test-rbtree_list.c | 33 | ||||
-rw-r--r-- | tests/test-rbtreehash_list.c | 33 |
8 files changed, 270 insertions, 0 deletions
diff --git a/tests/test-array_list.c b/tests/test-array_list.c index 1c736ee6cb..fa606914b8 100644 --- a/tests/test-array_list.c +++ b/tests/test-array_list.c @@ -44,6 +44,42 @@ check_equals (gl_list_t list1, gl_list_t list2) } } +static void +check_equals_by_forward_iteration (gl_list_t list1, gl_list_t list2) +{ + size_t n = gl_list_size (list1); + size_t i; + gl_list_node_t node2; + + i = 0; + node2 = gl_list_first_node (list2); + while (i < n && node2 != NULL) + { + ASSERT (gl_list_get_at (list1, i) == gl_list_node_value (list2, node2)); + i++; + node2 = gl_list_next_node (list2, node2); + } + ASSERT ((i == n) == (node2 == NULL)); +} + +static void +check_equals_by_backward_iteration (gl_list_t list1, gl_list_t list2) +{ + size_t n = gl_list_size (list1); + size_t i; + gl_list_node_t node2; + + i = n - 1; + node2 = gl_list_last_node (list2); + while (i != (size_t)(-1) && node2 != NULL) + { + ASSERT (gl_list_get_at (list1, i) == gl_list_node_value (list2, node2)); + i--; + node2 = gl_list_previous_node (list2, node2); + } + ASSERT ((i == (size_t)(-1)) == (node2 == NULL)); +} + int main (int argc, char *argv[]) { @@ -75,6 +111,9 @@ main (int argc, char *argv[]) check_equals (list1, list2); + check_equals_by_forward_iteration (list1, list2); + check_equals_by_backward_iteration (list1, list2); + for (repeat = 0; repeat < 10000; repeat++) { unsigned int operation = RANDOM (18); diff --git a/tests/test-avltree_list.c b/tests/test-avltree_list.c index c4c0f021cb..b4938c489d 100644 --- a/tests/test-avltree_list.c +++ b/tests/test-avltree_list.c @@ -48,6 +48,36 @@ check_equals (gl_list_t list1, gl_list_t list2) } static void +check_equals_by_forward_iteration (gl_list_t list1, gl_list_t list2) +{ + gl_list_node_t node1 = gl_list_first_node (list1); + gl_list_node_t node2 = gl_list_first_node (list2); + while (node1 != NULL && node2 != NULL) + { + ASSERT (gl_list_node_value (list1, node1) + == gl_list_node_value (list2, node2)); + node1 = gl_list_next_node (list1, node1); + node2 = gl_list_next_node (list2, node2); + } + ASSERT ((node1 == NULL) == (node2 == NULL)); +} + +static void +check_equals_by_backward_iteration (gl_list_t list1, gl_list_t list2) +{ + gl_list_node_t node1 = gl_list_last_node (list1); + gl_list_node_t node2 = gl_list_last_node (list2); + while (node1 != NULL && node2 != NULL) + { + ASSERT (gl_list_node_value (list1, node1) + == gl_list_node_value (list2, node2)); + node1 = gl_list_previous_node (list1, node1); + node2 = gl_list_previous_node (list2, node2); + } + ASSERT ((node1 == NULL) == (node2 == NULL)); +} + +static void check_all (gl_list_t list1, gl_list_t list2, gl_list_t list3) { gl_avltree_list_check_invariants (list2); @@ -92,6 +122,9 @@ main (int argc, char *argv[]) check_all (list1, list2, list3); + check_equals_by_forward_iteration (list1, list2); + check_equals_by_backward_iteration (list1, list2); + for (repeat = 0; repeat < 10000; repeat++) { unsigned int operation = RANDOM (18); diff --git a/tests/test-avltreehash_list.c b/tests/test-avltreehash_list.c index a77ee86294..040efd39c5 100644 --- a/tests/test-avltreehash_list.c +++ b/tests/test-avltreehash_list.c @@ -75,6 +75,36 @@ check_equals (gl_list_t list1, gl_list_t list2) } static void +check_equals_by_forward_iteration (gl_list_t list1, gl_list_t list2) +{ + gl_list_node_t node1 = gl_list_first_node (list1); + gl_list_node_t node2 = gl_list_first_node (list2); + while (node1 != NULL && node2 != NULL) + { + ASSERT (gl_list_node_value (list1, node1) + == gl_list_node_value (list2, node2)); + node1 = gl_list_next_node (list1, node1); + node2 = gl_list_next_node (list2, node2); + } + ASSERT ((node1 == NULL) == (node2 == NULL)); +} + +static void +check_equals_by_backward_iteration (gl_list_t list1, gl_list_t list2) +{ + gl_list_node_t node1 = gl_list_last_node (list1); + gl_list_node_t node2 = gl_list_last_node (list2); + while (node1 != NULL && node2 != NULL) + { + ASSERT (gl_list_node_value (list1, node1) + == gl_list_node_value (list2, node2)); + node1 = gl_list_previous_node (list1, node1); + node2 = gl_list_previous_node (list2, node2); + } + ASSERT ((node1 == NULL) == (node2 == NULL)); +} + +static void check_all (gl_list_t list1, gl_list_t list2, gl_list_t list3) { gl_avltreehash_list_check_invariants (list2); @@ -122,6 +152,9 @@ main (int argc, char *argv[]) check_all (list1, list2, list3); + check_equals_by_forward_iteration (list1, list2); + check_equals_by_backward_iteration (list1, list2); + for (repeat = 0; repeat < 10000; repeat++) { unsigned int operation = RANDOM (18); diff --git a/tests/test-carray_list.c b/tests/test-carray_list.c index 53ab6f58bc..4077571735 100644 --- a/tests/test-carray_list.c +++ b/tests/test-carray_list.c @@ -46,6 +46,36 @@ check_equals (gl_list_t list1, gl_list_t list2) } static void +check_equals_by_forward_iteration (gl_list_t list1, gl_list_t list2) +{ + gl_list_node_t node1 = gl_list_first_node (list1); + gl_list_node_t node2 = gl_list_first_node (list2); + while (node1 != NULL && node2 != NULL) + { + ASSERT (gl_list_node_value (list1, node1) + == gl_list_node_value (list2, node2)); + node1 = gl_list_next_node (list1, node1); + node2 = gl_list_next_node (list2, node2); + } + ASSERT ((node1 == NULL) == (node2 == NULL)); +} + +static void +check_equals_by_backward_iteration (gl_list_t list1, gl_list_t list2) +{ + gl_list_node_t node1 = gl_list_last_node (list1); + gl_list_node_t node2 = gl_list_last_node (list2); + while (node1 != NULL && node2 != NULL) + { + ASSERT (gl_list_node_value (list1, node1) + == gl_list_node_value (list2, node2)); + node1 = gl_list_previous_node (list1, node1); + node2 = gl_list_previous_node (list2, node2); + } + ASSERT ((node1 == NULL) == (node2 == NULL)); +} + +static void check_all (gl_list_t list1, gl_list_t list2, gl_list_t list3) { check_equals (list1, list2); @@ -88,6 +118,9 @@ main (int argc, char *argv[]) check_all (list1, list2, list3); + check_equals_by_forward_iteration (list1, list2); + check_equals_by_backward_iteration (list1, list2); + for (repeat = 0; repeat < 10000; repeat++) { unsigned int operation = RANDOM (18); diff --git a/tests/test-linked_list.c b/tests/test-linked_list.c index 4f3ec5d2de..fff7e061de 100644 --- a/tests/test-linked_list.c +++ b/tests/test-linked_list.c @@ -46,6 +46,36 @@ check_equals (gl_list_t list1, gl_list_t list2) } static void +check_equals_by_forward_iteration (gl_list_t list1, gl_list_t list2) +{ + gl_list_node_t node1 = gl_list_first_node (list1); + gl_list_node_t node2 = gl_list_first_node (list2); + while (node1 != NULL && node2 != NULL) + { + ASSERT (gl_list_node_value (list1, node1) + == gl_list_node_value (list2, node2)); + node1 = gl_list_next_node (list1, node1); + node2 = gl_list_next_node (list2, node2); + } + ASSERT ((node1 == NULL) == (node2 == NULL)); +} + +static void +check_equals_by_backward_iteration (gl_list_t list1, gl_list_t list2) +{ + gl_list_node_t node1 = gl_list_last_node (list1); + gl_list_node_t node2 = gl_list_last_node (list2); + while (node1 != NULL && node2 != NULL) + { + ASSERT (gl_list_node_value (list1, node1) + == gl_list_node_value (list2, node2)); + node1 = gl_list_previous_node (list1, node1); + node2 = gl_list_previous_node (list2, node2); + } + ASSERT ((node1 == NULL) == (node2 == NULL)); +} + +static void check_all (gl_list_t list1, gl_list_t list2, gl_list_t list3) { check_equals (list1, list2); @@ -88,6 +118,9 @@ main (int argc, char *argv[]) check_all (list1, list2, list3); + check_equals_by_forward_iteration (list1, list2); + check_equals_by_backward_iteration (list1, list2); + for (repeat = 0; repeat < 10000; repeat++) { unsigned int operation = RANDOM (18); diff --git a/tests/test-linkedhash_list.c b/tests/test-linkedhash_list.c index b61feda3cf..fc2a8a05ab 100644 --- a/tests/test-linkedhash_list.c +++ b/tests/test-linkedhash_list.c @@ -73,6 +73,36 @@ check_equals (gl_list_t list1, gl_list_t list2) } static void +check_equals_by_forward_iteration (gl_list_t list1, gl_list_t list2) +{ + gl_list_node_t node1 = gl_list_first_node (list1); + gl_list_node_t node2 = gl_list_first_node (list2); + while (node1 != NULL && node2 != NULL) + { + ASSERT (gl_list_node_value (list1, node1) + == gl_list_node_value (list2, node2)); + node1 = gl_list_next_node (list1, node1); + node2 = gl_list_next_node (list2, node2); + } + ASSERT ((node1 == NULL) == (node2 == NULL)); +} + +static void +check_equals_by_backward_iteration (gl_list_t list1, gl_list_t list2) +{ + gl_list_node_t node1 = gl_list_last_node (list1); + gl_list_node_t node2 = gl_list_last_node (list2); + while (node1 != NULL && node2 != NULL) + { + ASSERT (gl_list_node_value (list1, node1) + == gl_list_node_value (list2, node2)); + node1 = gl_list_previous_node (list1, node1); + node2 = gl_list_previous_node (list2, node2); + } + ASSERT ((node1 == NULL) == (node2 == NULL)); +} + +static void check_all (gl_list_t list1, gl_list_t list2, gl_list_t list3) { check_equals (list1, list2); @@ -118,6 +148,9 @@ main (int argc, char *argv[]) check_all (list1, list2, list3); + check_equals_by_forward_iteration (list1, list2); + check_equals_by_backward_iteration (list1, list2); + for (repeat = 0; repeat < 10000; repeat++) { unsigned int operation = RANDOM (18); diff --git a/tests/test-rbtree_list.c b/tests/test-rbtree_list.c index 9c403f779b..d3ea65682e 100644 --- a/tests/test-rbtree_list.c +++ b/tests/test-rbtree_list.c @@ -48,6 +48,36 @@ check_equals (gl_list_t list1, gl_list_t list2) } static void +check_equals_by_forward_iteration (gl_list_t list1, gl_list_t list2) +{ + gl_list_node_t node1 = gl_list_first_node (list1); + gl_list_node_t node2 = gl_list_first_node (list2); + while (node1 != NULL && node2 != NULL) + { + ASSERT (gl_list_node_value (list1, node1) + == gl_list_node_value (list2, node2)); + node1 = gl_list_next_node (list1, node1); + node2 = gl_list_next_node (list2, node2); + } + ASSERT ((node1 == NULL) == (node2 == NULL)); +} + +static void +check_equals_by_backward_iteration (gl_list_t list1, gl_list_t list2) +{ + gl_list_node_t node1 = gl_list_last_node (list1); + gl_list_node_t node2 = gl_list_last_node (list2); + while (node1 != NULL && node2 != NULL) + { + ASSERT (gl_list_node_value (list1, node1) + == gl_list_node_value (list2, node2)); + node1 = gl_list_previous_node (list1, node1); + node2 = gl_list_previous_node (list2, node2); + } + ASSERT ((node1 == NULL) == (node2 == NULL)); +} + +static void check_all (gl_list_t list1, gl_list_t list2, gl_list_t list3) { gl_rbtree_list_check_invariants (list2); @@ -92,6 +122,9 @@ main (int argc, char *argv[]) check_all (list1, list2, list3); + check_equals_by_forward_iteration (list1, list2); + check_equals_by_backward_iteration (list1, list2); + for (repeat = 0; repeat < 10000; repeat++) { unsigned int operation = RANDOM (18); diff --git a/tests/test-rbtreehash_list.c b/tests/test-rbtreehash_list.c index 41ef5c4df3..89fc3eb5b9 100644 --- a/tests/test-rbtreehash_list.c +++ b/tests/test-rbtreehash_list.c @@ -75,6 +75,36 @@ check_equals (gl_list_t list1, gl_list_t list2) } static void +check_equals_by_forward_iteration (gl_list_t list1, gl_list_t list2) +{ + gl_list_node_t node1 = gl_list_first_node (list1); + gl_list_node_t node2 = gl_list_first_node (list2); + while (node1 != NULL && node2 != NULL) + { + ASSERT (gl_list_node_value (list1, node1) + == gl_list_node_value (list2, node2)); + node1 = gl_list_next_node (list1, node1); + node2 = gl_list_next_node (list2, node2); + } + ASSERT ((node1 == NULL) == (node2 == NULL)); +} + +static void +check_equals_by_backward_iteration (gl_list_t list1, gl_list_t list2) +{ + gl_list_node_t node1 = gl_list_last_node (list1); + gl_list_node_t node2 = gl_list_last_node (list2); + while (node1 != NULL && node2 != NULL) + { + ASSERT (gl_list_node_value (list1, node1) + == gl_list_node_value (list2, node2)); + node1 = gl_list_previous_node (list1, node1); + node2 = gl_list_previous_node (list2, node2); + } + ASSERT ((node1 == NULL) == (node2 == NULL)); +} + +static void check_all (gl_list_t list1, gl_list_t list2, gl_list_t list3) { gl_rbtreehash_list_check_invariants (list2); @@ -122,6 +152,9 @@ main (int argc, char *argv[]) check_all (list1, list2, list3); + check_equals_by_forward_iteration (list1, list2); + check_equals_by_backward_iteration (list1, list2); + for (repeat = 0; repeat < 10000; repeat++) { unsigned int operation = RANDOM (18); |