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>.
}
}
+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[])
{
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);
}
}
+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_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);
}
}
+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_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);
}
}
+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_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);
}
}
+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_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);
}
}
+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_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);
}
}
+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_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);
}
}
+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_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);