annotate tests/test-rbtree_list.c @ 6980:9ccb96800d02

Sequential list data type implemented by a binary tree.
author Bruno Haible <bruno@clisp.org>
date Mon, 17 Jul 2006 11:30:58 +0000
parents
children 0afb48f6e566
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6980
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of sequential list data type implementation.
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2006 Free Software Foundation, Inc.
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2006.
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 the Free Software Foundation; either version 2, or (at your option)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 any later version.
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 along with this program; if not, write to the Free Software Foundation,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #ifdef HAVE_CONFIG_H
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 # include <config.h>
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #endif
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <stdlib.h>
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include "gl_array_list.h"
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include "gl_rbtree_list.h"
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 extern void gl_rbtree_list_check_invariants (gl_list_t list);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 static const char *objects[15] =
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o"
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 };
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 #define SIZEOF(array) (sizeof (array) / sizeof (array[0]))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 #define ASSERT(condition) if (!(condition)) abort ()
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 #define RANDOM(n) (rand () % (n))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 #define RANDOM_OBJECT() objects[RANDOM (SIZEOF (objects))]
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 static void
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 check_equals (gl_list_t list1, gl_list_t list2)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 size_t n, i;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 n = gl_list_size (list1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 ASSERT (n == gl_list_size (list2));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 for (i = 0; i < n; i++)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 ASSERT (gl_list_get_at (list1, i) == gl_list_get_at (list2, i));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 static void
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 check_all (gl_list_t list1, gl_list_t list2, gl_list_t list3)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 gl_rbtree_list_check_invariants (list2);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 gl_rbtree_list_check_invariants (list3);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 check_equals (list1, list2);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 check_equals (list1, list3);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 int
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 main (int argc, char *argv[])
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 gl_list_t list1, list2, list3;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 /* Allow the user to provide a non-default random seed on the command line. */
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 if (argc > 1)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 srand (atoi (argv[1]));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 size_t initial_size = RANDOM (50);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 const void **contents =
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 (const void **) malloc (initial_size * sizeof (const void *));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 size_t i;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 unsigned int repeat;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 for (i = 0; i < initial_size; i++)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 contents[i] = RANDOM_OBJECT ();
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 /* Create list1. */
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 list1 = gl_list_create (GL_ARRAY_LIST, NULL, NULL, true,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 initial_size, contents);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 /* Create list2. */
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 list2 = gl_list_create_empty (GL_RBTREE_LIST, NULL, NULL, true);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 for (i = 0; i < initial_size; i++)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 gl_list_add_last (list2, contents[i]);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 /* Create list3. */
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 list3 = gl_list_create (GL_RBTREE_LIST, NULL, NULL, true,
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 initial_size, contents);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 check_all (list1, list2, list3);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 for (repeat = 0; repeat < 10000; repeat++)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 unsigned int operation = RANDOM (16);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 switch (operation)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 case 0:
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 if (gl_list_size (list1) > 0)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 size_t index = RANDOM (gl_list_size (list1));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 const char *obj = RANDOM_OBJECT ();
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 gl_list_node_t node1, node2, node3;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 node1 = gl_list_set_at (list1, index, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 ASSERT (gl_list_get_at (list1, index) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 ASSERT (gl_list_node_value (list1, node1) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 node2 = gl_list_set_at (list2, index, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 ASSERT (gl_list_get_at (list2, index) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 ASSERT (gl_list_node_value (list2, node2) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 node3 = gl_list_set_at (list3, index, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 ASSERT (gl_list_get_at (list3, index) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 ASSERT (gl_list_node_value (list3, node3) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 if (index > 0)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 ASSERT (gl_list_node_value (list1, gl_list_previous_node (list1, node1))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 == gl_list_get_at (list1, index - 1));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 ASSERT (gl_list_node_value (list2, gl_list_previous_node (list3, node3))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 == gl_list_get_at (list2, index - 1));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 ASSERT (gl_list_node_value (list3, gl_list_previous_node (list3, node3))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 == gl_list_get_at (list2, index - 1));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 if (index + 1 < gl_list_size (list1))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 ASSERT (gl_list_node_value (list1, gl_list_next_node (list1, node1))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 == gl_list_get_at (list1, index + 1));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 ASSERT (gl_list_node_value (list2, gl_list_next_node (list3, node3))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 == gl_list_get_at (list2, index + 1));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 ASSERT (gl_list_node_value (list3, gl_list_next_node (list3, node3))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 == gl_list_get_at (list2, index + 1));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 break;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 case 1:
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 const char *obj = RANDOM_OBJECT ();
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 gl_list_node_t node1, node2, node3;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 node1 = gl_list_search (list1, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 node2 = gl_list_search (list2, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 node3 = gl_list_search (list3, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 if (node1 == NULL)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 ASSERT (node2 == NULL);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 ASSERT (node3 == NULL);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 else
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 ASSERT (node2 != NULL);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 ASSERT (node3 != NULL);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 ASSERT (gl_list_node_value (list1, node1) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 ASSERT (gl_list_node_value (list2, node2) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 ASSERT (gl_list_node_value (list3, node3) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 break;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 case 2:
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 const char *obj = RANDOM_OBJECT ();
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 size_t index1, index2, index3;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 index1 = gl_list_indexof (list1, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 index2 = gl_list_indexof (list2, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 index3 = gl_list_indexof (list3, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 if (index1 == (size_t)(-1))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 ASSERT (index2 == (size_t)(-1));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 ASSERT (index3 == (size_t)(-1));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 else
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 ASSERT (index2 != (size_t)(-1));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 ASSERT (index3 != (size_t)(-1));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 ASSERT (gl_list_get_at (list1, index1) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 ASSERT (gl_list_get_at (list2, index2) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 ASSERT (gl_list_get_at (list3, index3) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180 ASSERT (index2 == index1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181 ASSERT (index3 == index1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 break;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 case 3: /* add 1 element */
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 const char *obj = RANDOM_OBJECT ();
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188 gl_list_node_t node1, node2, node3;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
189 node1 = gl_list_add_first (list1, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 node2 = gl_list_add_first (list2, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191 node3 = gl_list_add_first (list3, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
192 ASSERT (gl_list_node_value (list1, node1) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
193 ASSERT (gl_list_node_value (list2, node2) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
194 ASSERT (gl_list_node_value (list3, node3) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
195 ASSERT (gl_list_get_at (list1, 0) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
196 ASSERT (gl_list_get_at (list2, 0) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
197 ASSERT (gl_list_get_at (list3, 0) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
198 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
199 break;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
200 case 4: /* add 1 element */
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
201 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
202 const char *obj = RANDOM_OBJECT ();
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
203 gl_list_node_t node1, node2, node3;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
204 node1 = gl_list_add_last (list1, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
205 node2 = gl_list_add_last (list2, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
206 node3 = gl_list_add_last (list3, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
207 ASSERT (gl_list_node_value (list1, node1) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
208 ASSERT (gl_list_node_value (list2, node2) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
209 ASSERT (gl_list_node_value (list3, node3) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
210 ASSERT (gl_list_get_at (list1, gl_list_size (list1) - 1) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
211 ASSERT (gl_list_get_at (list2, gl_list_size (list2) - 1) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
212 ASSERT (gl_list_get_at (list3, gl_list_size (list3) - 1) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
213 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
214 break;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
215 case 5: /* add 3 elements */
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
216 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
217 const char *obj0 = RANDOM_OBJECT ();
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
218 const char *obj1 = RANDOM_OBJECT ();
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
219 const char *obj2 = RANDOM_OBJECT ();
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
220 gl_list_node_t node1, node2, node3;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
221 node1 = gl_list_add_first (list1, obj2);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
222 node1 = gl_list_add_before (list1, node1, obj0);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
223 node1 = gl_list_add_after (list1, node1, obj1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
224 node2 = gl_list_add_first (list2, obj2);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
225 node2 = gl_list_add_before (list2, node2, obj0);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
226 node2 = gl_list_add_after (list2, node2, obj1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
227 node3 = gl_list_add_first (list3, obj2);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
228 node3 = gl_list_add_before (list3, node3, obj0);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
229 node3 = gl_list_add_after (list3, node3, obj1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
230 ASSERT (gl_list_node_value (list1, node1) == obj1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
231 ASSERT (gl_list_node_value (list2, node2) == obj1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
232 ASSERT (gl_list_node_value (list3, node3) == obj1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
233 ASSERT (gl_list_get_at (list1, 0) == obj0);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
234 ASSERT (gl_list_get_at (list1, 1) == obj1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
235 ASSERT (gl_list_get_at (list1, 2) == obj2);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
236 ASSERT (gl_list_get_at (list2, 0) == obj0);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
237 ASSERT (gl_list_get_at (list2, 1) == obj1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
238 ASSERT (gl_list_get_at (list2, 2) == obj2);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
239 ASSERT (gl_list_get_at (list3, 0) == obj0);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
240 ASSERT (gl_list_get_at (list3, 1) == obj1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
241 ASSERT (gl_list_get_at (list3, 2) == obj2);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
242 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
243 break;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
244 case 6: /* add 1 element */
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
245 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
246 size_t index = RANDOM (gl_list_size (list1) + 1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
247 const char *obj = RANDOM_OBJECT ();
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
248 gl_list_node_t node1, node2, node3;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
249 node1 = gl_list_add_at (list1, index, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
250 node2 = gl_list_add_at (list2, index, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
251 node3 = gl_list_add_at (list3, index, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
252 ASSERT (gl_list_get_at (list1, index) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
253 ASSERT (gl_list_node_value (list1, node1) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
254 ASSERT (gl_list_get_at (list2, index) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
255 ASSERT (gl_list_node_value (list2, node2) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
256 ASSERT (gl_list_get_at (list3, index) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
257 ASSERT (gl_list_node_value (list3, node3) == obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
258 if (index > 0)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
259 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
260 ASSERT (gl_list_node_value (list1, gl_list_previous_node (list1, node1))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
261 == gl_list_get_at (list1, index - 1));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
262 ASSERT (gl_list_node_value (list2, gl_list_previous_node (list3, node3))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
263 == gl_list_get_at (list2, index - 1));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
264 ASSERT (gl_list_node_value (list3, gl_list_previous_node (list3, node3))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
265 == gl_list_get_at (list2, index - 1));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
266 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
267 if (index + 1 < gl_list_size (list1))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
268 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
269 ASSERT (gl_list_node_value (list1, gl_list_next_node (list1, node1))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
270 == gl_list_get_at (list1, index + 1));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
271 ASSERT (gl_list_node_value (list2, gl_list_next_node (list3, node3))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
272 == gl_list_get_at (list2, index + 1));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
273 ASSERT (gl_list_node_value (list3, gl_list_next_node (list3, node3))
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
274 == gl_list_get_at (list2, index + 1));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
275 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
276 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
277 break;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
278 case 7: case 8: /* remove 1 element */
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
279 if (gl_list_size (list1) > 0)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
280 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
281 size_t n = gl_list_size (list1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
282 const char *obj = gl_list_get_at (list1, RANDOM (n));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
283 gl_list_node_t node1, node2, node3;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
284 node1 = gl_list_search (list1, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
285 node2 = gl_list_search (list2, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
286 node3 = gl_list_search (list3, obj);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
287 ASSERT (node1 != NULL);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
288 ASSERT (node2 != NULL);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
289 ASSERT (node3 != NULL);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
290 ASSERT (gl_list_remove_node (list1, node1));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
291 ASSERT (gl_list_remove_node (list2, node2));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
292 ASSERT (gl_list_remove_node (list3, node3));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
293 ASSERT (gl_list_size (list1) == n - 1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
294 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
295 break;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
296 case 9: case 10: /* remove 1 element */
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
297 if (gl_list_size (list1) > 0)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
298 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
299 size_t n = gl_list_size (list1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
300 size_t index = RANDOM (n);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
301 ASSERT (gl_list_remove_at (list1, index));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
302 ASSERT (gl_list_remove_at (list2, index));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
303 ASSERT (gl_list_remove_at (list3, index));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
304 ASSERT (gl_list_size (list1) == n - 1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
305 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
306 break;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
307 case 11: case 12: /* remove 1 element */
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
308 if (gl_list_size (list1) > 0)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
309 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
310 size_t n = gl_list_size (list1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
311 const char *obj = gl_list_get_at (list1, RANDOM (n));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
312 ASSERT (gl_list_remove (list1, obj));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
313 ASSERT (gl_list_remove (list2, obj));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
314 ASSERT (gl_list_remove (list3, obj));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
315 ASSERT (gl_list_size (list1) == n - 1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
316 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
317 break;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
318 case 13:
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
319 if (gl_list_size (list1) > 0)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
320 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
321 size_t n = gl_list_size (list1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
322 const char *obj = "xyzzy";
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
323 ASSERT (!gl_list_remove (list1, obj));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
324 ASSERT (!gl_list_remove (list2, obj));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
325 ASSERT (!gl_list_remove (list3, obj));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
326 ASSERT (gl_list_size (list1) == n);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
327 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
328 break;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
329 case 14:
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
330 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
331 size_t n = gl_list_size (list1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
332 gl_list_iterator_t iter1, iter2, iter3;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
333 const void *elt;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
334 iter1 = gl_list_iterator (list1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
335 iter2 = gl_list_iterator (list2);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
336 iter3 = gl_list_iterator (list3);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
337 for (i = 0; i < n; i++)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
338 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
339 ASSERT (gl_list_iterator_next (&iter1, &elt, NULL));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
340 ASSERT (gl_list_get_at (list1, i) == elt);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
341 ASSERT (gl_list_iterator_next (&iter2, &elt, NULL));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
342 ASSERT (gl_list_get_at (list2, i) == elt);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
343 ASSERT (gl_list_iterator_next (&iter3, &elt, NULL));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
344 ASSERT (gl_list_get_at (list3, i) == elt);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
345 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
346 ASSERT (!gl_list_iterator_next (&iter1, &elt, NULL));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
347 ASSERT (!gl_list_iterator_next (&iter2, &elt, NULL));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
348 ASSERT (!gl_list_iterator_next (&iter3, &elt, NULL));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
349 gl_list_iterator_free (&iter1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
350 gl_list_iterator_free (&iter2);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
351 gl_list_iterator_free (&iter3);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
352 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
353 break;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
354 case 15:
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
355 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
356 size_t end = RANDOM (gl_list_size (list1) + 1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
357 size_t start = RANDOM (end + 1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
358 gl_list_iterator_t iter1, iter2, iter3;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
359 const void *elt;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
360 iter1 = gl_list_iterator_from_to (list1, start, end);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
361 iter2 = gl_list_iterator_from_to (list2, start, end);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
362 iter3 = gl_list_iterator_from_to (list3, start, end);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
363 for (i = start; i < end; i++)
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
364 {
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
365 ASSERT (gl_list_iterator_next (&iter1, &elt, NULL));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
366 ASSERT (gl_list_get_at (list1, i) == elt);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
367 ASSERT (gl_list_iterator_next (&iter2, &elt, NULL));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
368 ASSERT (gl_list_get_at (list2, i) == elt);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
369 ASSERT (gl_list_iterator_next (&iter3, &elt, NULL));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
370 ASSERT (gl_list_get_at (list3, i) == elt);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
371 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
372 ASSERT (!gl_list_iterator_next (&iter1, &elt, NULL));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
373 ASSERT (!gl_list_iterator_next (&iter2, &elt, NULL));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
374 ASSERT (!gl_list_iterator_next (&iter3, &elt, NULL));
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
375 gl_list_iterator_free (&iter1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
376 gl_list_iterator_free (&iter2);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
377 gl_list_iterator_free (&iter3);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
378 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
379 break;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
380 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
381 check_all (list1, list2, list3);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
382 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
383
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
384 gl_list_free (list1);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
385 gl_list_free (list2);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
386 gl_list_free (list3);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
387 free (contents);
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
388 }
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
389
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
390 return 0;
9ccb96800d02 Sequential list data type implemented by a binary tree.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
391 }