annotate tests/test-array_oset.c @ 40231:9b3c79fdfe0b

strtod: fix clash with strtold Problem reported for RHEL 5 by Jesse Caldwell (Bug#34817). * lib/strtod.c (compute_minus_zero, minus_zero): Simplify by remving the macro / external variable, and having just a function. User changed. This avoids the need for an external variable that might clash.
author Paul Eggert <eggert@cs.ucla.edu>
date Mon, 11 Mar 2019 16:40:29 -0700
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7868
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of ordered set data type implementation.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2006-2019 Free Software Foundation, Inc.
7868
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2007.
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
5 This program is free software: you can redistribute it and/or modify
7868
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
8 (at your option) any later version.
7868
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
7868
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
8891
633babea5f62 Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents: 8754
diff changeset
18 #include <config.h>
7868
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #include "gl_array_oset.h"
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #include <stdlib.h>
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <string.h>
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
12445
a8c91b846640 Move the malloc checking from module 'list' to new module 'xlist'.
Bruno Haible <bruno@clisp.org>
parents: 12444
diff changeset
25 #include "gl_xlist.h"
7868
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include "gl_array_list.h"
12496
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12445
diff changeset
27 #include "macros.h"
7868
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 static const char *objects[30] =
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 {
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "<", ">", "[", "]"
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 };
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 #define RANDOM(n) (rand () % (n))
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 #define RANDOM_OBJECT() objects[RANDOM (SIZEOF (objects))]
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 static void
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 check_equals (gl_oset_t set1, gl_list_t set2)
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 {
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 size_t n = gl_oset_size (set1);
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 gl_oset_iterator_t iter1;
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 gl_list_iterator_t iter2;
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 const void *elt1;
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 const void *elt2;
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 gl_list_node_t node2;
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 size_t i;
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 iter1 = gl_oset_iterator (set1);
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 iter2 = gl_list_iterator (set2);
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 for (i = 0; i < n; i++)
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 {
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 ASSERT (gl_oset_iterator_next (&iter1, &elt1));
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 ASSERT (gl_list_iterator_next (&iter2, &elt2, &node2));
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 ASSERT (elt1 == elt2);
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 }
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 ASSERT (!gl_oset_iterator_next (&iter1, &elt1));
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 ASSERT (!gl_list_iterator_next (&iter2, &elt2, &node2));
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 gl_oset_iterator_free (&iter1);
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 gl_list_iterator_free (&iter2);
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 }
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 static void
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 check_all (gl_oset_t set1, gl_list_t set2)
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 {
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 check_equals (set1, set2);
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 }
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 int
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 main (int argc, char *argv[])
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 {
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 gl_oset_t set1;
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 gl_list_t set2;
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 /* Allow the user to provide a non-default random seed on the command line. */
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 if (argc > 1)
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 srand (atoi (argv[1]));
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 {
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 size_t initial_size = RANDOM (20);
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 size_t i;
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 unsigned int repeat;
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 /* Create set1. */
12444
29d240cb21b2 Move the malloc checking from module 'oset' to new module 'xoset'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
85 set1 = gl_oset_nx_create_empty (GL_ARRAY_OSET, (gl_setelement_compar_fn) strcmp, NULL);
29d240cb21b2 Move the malloc checking from module 'oset' to new module 'xoset'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
86 ASSERT (set1 != NULL);
7868
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 /* Create set2. */
8438
238942284e2f Allow the use of a destructor for the values stored in the list.
Bruno Haible <bruno@clisp.org>
parents: 8436
diff changeset
89 set2 = gl_list_create_empty (GL_ARRAY_LIST, NULL, NULL, NULL, false);
7868
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 check_all (set1, set2);
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 /* Initialize them. */
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 for (i = 0; i < initial_size; i++)
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 {
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 const char *obj = RANDOM_OBJECT ();
12444
29d240cb21b2 Move the malloc checking from module 'oset' to new module 'xoset'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
97 ASSERT (gl_oset_nx_add (set1, obj)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
98 == (gl_sortedlist_search (set2, (gl_listelement_compar_fn)strcmp, obj) != NULL
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
99 ? false
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
100 : (gl_sortedlist_add (set2, (gl_listelement_compar_fn)strcmp, obj), true)));
7868
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 check_all (set1, set2);
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 }
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 for (repeat = 0; repeat < 100000; repeat++)
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 {
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 unsigned int operation = RANDOM (3);
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 switch (operation)
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 {
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 case 0:
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 {
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 const char *obj = RANDOM_OBJECT ();
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 ASSERT (gl_oset_search (set1, obj)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
113 == (gl_sortedlist_search (set2, (gl_listelement_compar_fn)strcmp, obj) != NULL));
7868
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 }
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 break;
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 case 1:
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 {
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 const char *obj = RANDOM_OBJECT ();
12444
29d240cb21b2 Move the malloc checking from module 'oset' to new module 'xoset'.
Bruno Haible <bruno@clisp.org>
parents: 12421
diff changeset
119 ASSERT (gl_oset_nx_add (set1, obj)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
120 == (gl_sortedlist_search (set2, (gl_listelement_compar_fn)strcmp, obj) != NULL
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
121 ? false
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
122 : (gl_sortedlist_add (set2, (gl_listelement_compar_fn)strcmp, obj), true)));
7868
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 }
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 break;
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 case 2:
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 {
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 const char *obj = RANDOM_OBJECT ();
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 ASSERT (gl_oset_remove (set1, obj)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
129 == gl_sortedlist_remove (set2, (gl_listelement_compar_fn)strcmp, obj));
7868
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 }
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 break;
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 }
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 check_all (set1, set2);
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 }
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 gl_oset_free (set1);
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 gl_list_free (set2);
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 }
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 return 0;
12fdd0de44d5 Test for array-oset module.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 }