annotate tests/test-hash_map.c @ 40174:b76c7bdde2bf

*-map tests: Fix compilation error. * tests/test-array_map.c: Include <limits.h>, for CHAR_BIT. * tests/test-hash_map.c: Likewise. * tests/test-linkedhash_map.c: Likewise.
author Colin Watson <cjwatson@debian.org>
date Sat, 02 Feb 2019 16:12:09 +0100
parents b06060465f09
children
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
40174
b76c7bdde2bf *-map tests: Fix compilation error.
Colin Watson <cjwatson@debian.org>
parents: 40057
diff changeset
22 #include <limits.h>
40024
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <stdlib.h>
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <string.h>
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include "gl_array_map.h"
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include "xalloc.h"
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include "macros.h"
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 static const char *objects[30] =
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 "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
33 "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "<", ">", "[", "]"
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
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 #define SIZE_BITS (sizeof (size_t) * CHAR_BIT)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 static bool
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 string_equals (const void *x1, const void *x2)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 const char *s1 = x1;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 const char *s2 = x2;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 return strcmp (s1, s2) == 0;
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
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 /* A hash function for NUL-terminated char* strings using
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 the method described by Bruno Haible.
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 See https://www.haible.de/bruno/hashfunc.html. */
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 static size_t
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 string_hash (const void *x)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 const char *s = x;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 size_t h = 0;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 for (; *s; s++)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 h = *s + ((h << 9) | (h >> (SIZE_BITS - 9)));
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 return h;
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
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 #define RANDOM(n) (rand () % (n))
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 #define RANDOM_OBJECT() objects[RANDOM (SIZEOF (objects))]
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 struct pair
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 const void *key;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 const void *value;
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
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 static int
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 cmp_pairs_in_array (const void *pairptr1, const void *pairptr2)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 const void *key1 = ((struct pair const *)pairptr1)->key;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 const void *key2 = ((struct pair const *)pairptr2)->key;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 return strcmp ((const char *) key1, (const char *) key2);
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
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 static void
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 check_equals (gl_map_t map1, gl_map_t map2)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 size_t n = gl_map_size (map1);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 struct pair *pairs_of_map1 = XNMALLOC (n, struct pair);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 struct pair *pairs_of_map2 = XNMALLOC (n, struct pair);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 gl_map_iterator_t iter1, iter2;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 const void *key1;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 const void *value1;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 const void *key2;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 const void *value2;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 size_t i;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 iter1 = gl_map_iterator (map1);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 iter2 = gl_map_iterator (map2);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 for (i = 0; i < n; i++)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 ASSERT (gl_map_iterator_next (&iter1, &key1, &value1));
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 ASSERT (gl_map_iterator_next (&iter2, &key2, &value2));
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 pairs_of_map1[i].key = key1;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 pairs_of_map1[i].value = value1;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 pairs_of_map2[i].key = key2;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 pairs_of_map2[i].value = value2;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 ASSERT (!gl_map_iterator_next (&iter1, &key1, &value1));
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 ASSERT (!gl_map_iterator_next (&iter2, &key2, &value2));
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 gl_map_iterator_free (&iter1);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 gl_map_iterator_free (&iter2);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 if (n > 0)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 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
111 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
112 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 for (i = 0; i < n; i++)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 ASSERT (pairs_of_map1[i].key == pairs_of_map2[i].key);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 ASSERT (pairs_of_map1[i].value == pairs_of_map2[i].value);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 free (pairs_of_map2);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 free (pairs_of_map1);
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
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 static void
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 check_all (gl_map_t map1, gl_map_t map2)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 check_equals (map1, map2);
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
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 int
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 main (int argc, char *argv[])
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 gl_map_t map1, map2;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 /* 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
134 if (argc > 1)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 srand (atoi (argv[1]));
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 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 size_t initial_size = RANDOM (20);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 size_t i;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 unsigned int repeat;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 /* Create map1. */
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 map1 = gl_map_nx_create_empty (GL_ARRAY_MAP,
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 string_equals, string_hash, NULL, NULL);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 ASSERT (map1 != NULL);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 /* Create map2. */
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 map2 = gl_map_nx_create_empty (GL_HASH_MAP,
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 string_equals, string_hash, NULL, NULL);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 ASSERT (map2 != NULL);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 check_all (map1, map2);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 /* Initialize them. */
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 for (i = 0; i < initial_size; i++)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 const char *key = RANDOM_OBJECT ();
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 const char *value = RANDOM_OBJECT ();
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 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
160 check_all (map1, map2);
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
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 for (repeat = 0; repeat < 100000; repeat++)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 unsigned int operation = RANDOM (3);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 switch (operation)
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 case 0:
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 const char *key = RANDOM_OBJECT ();
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 ASSERT (gl_map_get (map1, key) == gl_map_get (map2, key));
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 break;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 case 1:
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 const char *key = RANDOM_OBJECT ();
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 const char *value = RANDOM_OBJECT ();
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 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
179 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180 break;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181 case 2:
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182 {
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 const char *key = RANDOM_OBJECT ();
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 ASSERT (gl_map_remove (map1, key) == gl_map_remove (map2, key));
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186 break;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 }
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188 check_all (map1, map2);
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
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191 gl_map_free (map1);
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
192 gl_map_free (map2);
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
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
195 return 0;
493211f9fd3d hash-map: Add tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
196 }