]> Savannah Git Hosting - gnulib.git/commitdiff
*-list tests: Add more tests.
authorBruno Haible <bruno@clisp.org>
Sat, 3 Apr 2021 16:25:56 +0000 (18:25 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 3 Apr 2021 16:30:52 +0000 (18:30 +0200)
* 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.

ChangeLog
tests/test-array_list.c
tests/test-avltree_list.c
tests/test-avltreehash_list.c
tests/test-carray_list.c
tests/test-linked_list.c
tests/test-linkedhash_list.c
tests/test-rbtree_list.c
tests/test-rbtreehash_list.c

index 80cce4f17ff4681ffb92ab082f26472533b1259c..956f6dd57a0494d1f669f5f5e9ac506e0864984d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2021-04-03  Bruno Haible  <bruno@clisp.org>
 
+       *-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.
+
        list: Add operations first_node, last_node.
        Reported by Marc Nieper-Wißkirchen in
        <https://lists.gnu.org/archive/html/bug-gnulib/2021-04/msg00005.html>.
index 1c736ee6cb7bc3e2829cef1616bd07a5822e01e8..fa606914b85a5ec374b348f570a5b44fe3b5e086 100644 (file)
@@ -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);
index c4c0f021cbb29ebc26d41f932bda081813f9ef62..b4938c489dc8af2e8c1d14dcdd9d6a81647f1da9 100644 (file)
@@ -47,6 +47,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)
 {
@@ -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);
index a77ee86294bc584273392bba4b791b36d27d5f4f..040efd39c50fb4c032e3fba60da04bd3e5ae17cc 100644 (file)
@@ -74,6 +74,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)
 {
@@ -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);
index 53ab6f58bc9f5e8f9787cc14fcc0015ea0886105..4077571735ec97a33505419864876f74deb6532b 100644 (file)
@@ -45,6 +45,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)
 {
@@ -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);
index 4f3ec5d2de38675390814c000a316c126c25ea94..fff7e061dee917c6aa29260505b8ad26c7770236 100644 (file)
@@ -45,6 +45,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)
 {
@@ -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);
index b61feda3cf68c14329e7bfed9f63e7781acd2104..fc2a8a05ab2cbd8d125754e96fe3efd479b4d8b4 100644 (file)
@@ -72,6 +72,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)
 {
@@ -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);
index 9c403f779b5f9d1543e6273ed170bbd9a8b87dc6..d3ea65682eead53a2771a4118d111fbd30a2a9c0 100644 (file)
@@ -47,6 +47,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)
 {
@@ -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);
index 41ef5c4df3cdbb5634a20b61c99d08f2ebecb039..89fc3eb5b9b4fc49c6370afbcb445a0d4eda2d07 100644 (file)
@@ -74,6 +74,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)
 {
@@ -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);