annotate tests/test-hash_map.c @ 40057:b06060465f09

maint: Run 'make update-copyright'
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 01 Jan 2019 00:25:11 +0100
parents 493211f9fd3d
children b76c7bdde2bf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40024
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of map data type implementation.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 40024
diff changeset
2 Copyright (C) 2006-2019 Free Software Foundation, Inc.
40024
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2018.
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 (at your option) any later version.
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #include <config.h>
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #include "gl_hash_map.h"
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #include <stdlib.h>
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <string.h>
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include "gl_array_map.h"
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include "xalloc.h"
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include "macros.h"
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 static const char *objects[30] =
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "<", ">", "[", "]"
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 };
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 #define SIZE_BITS (sizeof (size_t) * CHAR_BIT)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 static bool
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 string_equals (const void *x1, const void *x2)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 const char *s1 = x1;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 const char *s2 = x2;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 return strcmp (s1, s2) == 0;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 /* A hash function for NUL-terminated char* strings using
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 the method described by Bruno Haible.
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 See https://www.haible.de/bruno/hashfunc.html. */
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 static size_t
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 string_hash (const void *x)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 const char *s = x;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 size_t h = 0;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 for (; *s; s++)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 h = *s + ((h << 9) | (h >> (SIZE_BITS - 9)));
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 return h;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 #define RANDOM(n) (rand () % (n))
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 #define RANDOM_OBJECT() objects[RANDOM (SIZEOF (objects))]
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 struct pair
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 const void *key;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 const void *value;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 };
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 static int
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 cmp_pairs_in_array (const void *pairptr1, const void *pairptr2)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 const void *key1 = ((struct pair const *)pairptr1)->key;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 const void *key2 = ((struct pair const *)pairptr2)->key;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 return strcmp ((const char *) key1, (const char *) key2);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 static void
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 check_equals (gl_map_t map1, gl_map_t map2)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 size_t n = gl_map_size (map1);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 struct pair *pairs_of_map1 = XNMALLOC (n, struct pair);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 struct pair *pairs_of_map2 = XNMALLOC (n, struct pair);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 gl_map_iterator_t iter1, iter2;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 const void *key1;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 const void *value1;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 const void *key2;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 const void *value2;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 size_t i;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 iter1 = gl_map_iterator (map1);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 iter2 = gl_map_iterator (map2);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 for (i = 0; i < n; i++)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 ASSERT (gl_map_iterator_next (&iter1, &key1, &value1));
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 ASSERT (gl_map_iterator_next (&iter2, &key2, &value2));
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 pairs_of_map1[i].key = key1;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 pairs_of_map1[i].value = value1;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 pairs_of_map2[i].key = key2;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 pairs_of_map2[i].value = value2;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 ASSERT (!gl_map_iterator_next (&iter1, &key1, &value1));
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 ASSERT (!gl_map_iterator_next (&iter2, &key2, &value2));
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 gl_map_iterator_free (&iter1);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 gl_map_iterator_free (&iter2);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 if (n > 0)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 qsort (pairs_of_map1, n, sizeof (struct pair), cmp_pairs_in_array);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 qsort (pairs_of_map2, n, sizeof (struct pair), cmp_pairs_in_array);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 for (i = 0; i < n; i++)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 ASSERT (pairs_of_map1[i].key == pairs_of_map2[i].key);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 ASSERT (pairs_of_map1[i].value == pairs_of_map2[i].value);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 free (pairs_of_map2);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 free (pairs_of_map1);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 static void
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 check_all (gl_map_t map1, gl_map_t map2)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 check_equals (map1, map2);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 int
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 main (int argc, char *argv[])
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 gl_map_t map1, map2;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 /* Allow the user to provide a non-default random seed on the command line. */
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 if (argc > 1)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 srand (atoi (argv[1]));
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 size_t initial_size = RANDOM (20);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 size_t i;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 unsigned int repeat;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 /* Create map1. */
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 map1 = gl_map_nx_create_empty (GL_ARRAY_MAP,
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 string_equals, string_hash, NULL, NULL);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 ASSERT (map1 != NULL);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 /* Create map2. */
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 map2 = gl_map_nx_create_empty (GL_HASH_MAP,
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 string_equals, string_hash, NULL, NULL);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 ASSERT (map2 != NULL);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 check_all (map1, map2);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 /* Initialize them. */
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 for (i = 0; i < initial_size; i++)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 const char *key = RANDOM_OBJECT ();
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 const char *value = RANDOM_OBJECT ();
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 ASSERT (gl_map_nx_put (map1, key, value) == gl_map_nx_put (map2, key, value));
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 check_all (map1, map2);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 for (repeat = 0; repeat < 100000; repeat++)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 unsigned int operation = RANDOM (3);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 switch (operation)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 case 0:
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 const char *key = RANDOM_OBJECT ();
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 ASSERT (gl_map_get (map1, key) == gl_map_get (map2, key));
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 break;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 case 1:
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 const char *key = RANDOM_OBJECT ();
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 const char *value = RANDOM_OBJECT ();
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 ASSERT (gl_map_nx_put (map1, key, value) == gl_map_nx_put (map2, key, value));
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 break;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180 case 2:
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182 const char *key = RANDOM_OBJECT ();
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 ASSERT (gl_map_remove (map1, key) == gl_map_remove (map2, key));
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 break;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 check_all (map1, map2);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
189
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 gl_map_free (map1);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191 gl_map_free (map2);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
192 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
193
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
194 return 0;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
195 }