annotate tests/test-tsearch.c @ 40155:84fd38f4932c

tests: Fix some "unused variable" warnings. * tests/test-fts.c (fts_dealloc): Remove unused variable. * tests/unigbrk/test-uc-grapheme-breaks.c (main): Likewise. * tests/test-striconveh.c (main): Move some variable into the '#if HAVE_ICONV'. * tests/test-striconveha.c (main): Likewise. * tests/uniconv/test-u8-conv-from-enc.c (main): Likewise. * tests/uniconv/test-u16-conv-from-enc.c (main): Likewise. * tests/uniconv/test-u32-conv-from-enc.c (main): Likewise. * tests/uniconv/test-u8-conv-to-enc.c (main): Likewise. * tests/uniconv/test-u16-conv-to-enc.c (main): Likewise. * tests/uniconv/test-u32-conv-to-enc.c (main): Likewise. * tests/uniconv/test-u8-strconv-from-enc.c (main): Likewise. * tests/uniconv/test-u16-strconv-from-enc.c (main): Likewise. * tests/uniconv/test-u32-strconv-from-enc.c (main): Likewise. * tests/uniconv/test-u8-strconv-to-enc.c (main): Likewise. * tests/uniconv/test-u16-strconv-to-enc.c (main): Likewise. * tests/uniconv/test-u32-strconv-to-enc.c (main): Likewise. * tests/test-tsearch.c (main): Move some variable into the '#if HAVE_INITSTATE'.
author Bruno Haible <bruno@clisp.org>
date Sun, 27 Jan 2019 12:24:47 +0100
parents b06060465f09
children a315d09bcec4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test program for tsearch et al.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 1997, 2000-2001, 2007-2019 Free Software Foundation, Inc.
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 This file is part of the GNU C Library.
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
9308
7a5f9d09f389 Change copyright notice from LGPLv2.1+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8534
diff changeset
5 The GNU C Library is free software: you can redistribute it and/or
7a5f9d09f389 Change copyright notice from LGPLv2.1+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8534
diff changeset
6 modify it under the terms of the GNU Lesser General Public License as
7a5f9d09f389 Change copyright notice from LGPLv2.1+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8534
diff changeset
7 published by the Free Software Foundation; either version 3 of the
7a5f9d09f389 Change copyright notice from LGPLv2.1+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8534
diff changeset
8 License, or (at your option) any later version.
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 The GNU C Library is distributed in the hope that it will be useful,
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 Lesser General Public License for more details.
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
9308
7a5f9d09f389 Change copyright notice from LGPLv2.1+ to LGPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8534
diff changeset
15 You should have received a copy of the GNU Lesser General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18930
diff changeset
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #include <config.h>
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #include <search.h>
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
12489
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
22 #include "signature.h"
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
23 SIGNATURE_CHECK (tdelete, void *, (void const *, void **,
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
24 int (*) (void const *, void const *)));
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
25 SIGNATURE_CHECK (tfind, void *, (void const *, void * const *,
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
26 int (*) (void const *, void const *)));
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
27 SIGNATURE_CHECK (tsearch, void *, (void const *, void **,
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
28 int (*) (void const *, void const *)));
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
29 SIGNATURE_CHECK (twalk, void, (void const *,
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
30 void (*) (void const *, VISIT, int)));
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
31
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 #include <stdint.h>
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 #include <stdio.h>
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 #include <stdlib.h>
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 #include <string.h>
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36
18930
50d1e186bf78 fallthrough: update for GCC 7/8
Jim Meyering <meyering@fb.com>
parents: 18626
diff changeset
37 #include "macros.h"
50d1e186bf78 fallthrough: update for GCC 7/8
Jim Meyering <meyering@fb.com>
parents: 18626
diff changeset
38
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 #define SEED 0
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 #if HAVE_TSEARCH
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 /* The system's tsearch() is not expected to keep the tree balanced. */
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 # define BALANCED 0
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 #else
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 /* The gnulib replacement tsearch() should keep the tree balanced. */
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 # define BALANCED 1
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 #endif
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 #define PASSES 100
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 #if BALANCED
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 #include <math.h>
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 #define SIZE 1000
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 #else
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 #define SIZE 100
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 #endif
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 #undef random
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 #define random() (int) ((unsigned int) rand () >> 3)
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 enum order
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 {
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 ascending,
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 descending,
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 randomorder
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 };
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 enum action
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 {
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 build,
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 build_and_del,
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 delete,
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 find
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 };
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 /* Set to 1 if a test is flunked. */
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 static int error = 0;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 /* The keys we add to the tree. */
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 static int x[SIZE];
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79
16358
a712776b11ce maint: spelling fixes
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
80 /* Pointers into the key array, possibly permuted, to define an order
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 for insertion/removal. */
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 static int y[SIZE];
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 /* Flags set for each element visited during a tree walk. */
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 static int z[SIZE];
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 /* Depths for all the elements, to check that the depth is constant for
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 all three visits. */
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 static int depths[SIZE];
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 /* Maximum depth during a tree walk. */
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 static int max_depth;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 /* Compare two keys. */
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 static int
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 cmp_fn (const void *a, const void *b)
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 {
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 return *(const int *) a - *(const int *) b;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 }
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 /* Permute an array of integers. */
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 static void
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 memfry (int *string)
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 {
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 int i;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 for (i = 0; i < SIZE; ++i)
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 {
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 int32_t j;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 int c;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 j = random () % SIZE;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 c = string[i];
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 string[i] = string[j];
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 string[j] = c;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 }
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 }
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 static void
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 walk_action (const void *nodep, const VISIT which, const int depth)
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 {
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 int key = **(int **) nodep;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 if (depth > max_depth)
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 max_depth = depth;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 if (which == leaf || which == preorder)
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 {
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 ++z[key];
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 depths[key] = depth;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 }
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 else
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 {
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 if (depths[key] != depth)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
135 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
136 fputs ("Depth for one element is not constant during tree walk.\n",
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
137 stdout);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
138 }
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 }
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 }
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 static void
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 walk_tree (void *root, int expected_count)
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 {
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 int i;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 memset (z, 0, sizeof z);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 max_depth = 0;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 twalk (root, walk_action);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 for (i = 0; i < expected_count; ++i)
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 if (z[i] != 1)
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
154 fputs ("Node was not visited.\n", stdout);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
155 error = 1;
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 }
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 #if BALANCED
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 if (max_depth > log (expected_count) * 2 + 2)
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 #else
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 if (max_depth > expected_count)
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 #endif
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 {
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 fputs ("Depth too large during tree walk.\n", stdout);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 error = 1;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 }
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 }
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 /* Perform an operation on a tree. */
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 static void
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 mangle_tree (enum order how, enum action what, void **root, int lag)
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 {
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 int i;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 if (how == randomorder)
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 {
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 for (i = 0; i < SIZE; ++i)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
178 y[i] = i;
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 memfry (y);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180 }
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182 for (i = 0; i < SIZE + lag; ++i)
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 {
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 void *elem;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 int j, k;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 switch (how)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
188 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
189 case randomorder:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
190 if (i >= lag)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
191 k = y[i - lag];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
192 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
193 /* Ensure that the array index is within bounds. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
194 k = y[(SIZE - i - 1 + lag) % SIZE];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
195 j = y[i % SIZE];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
196 break;
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
197
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
198 case ascending:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
199 k = i - lag;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
200 j = i;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
201 break;
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
202
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
203 case descending:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
204 k = SIZE - i - 1 + lag;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
205 j = SIZE - i - 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
206 break;
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
207
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
208 default:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
209 /* This never should happen, but gcc isn't smart enough to
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
210 recognize it. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
211 abort ();
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
212 }
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
213
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
214 switch (what)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
215 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
216 case build_and_del:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
217 case build:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
218 if (i < SIZE)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
219 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
220 if (tfind (x + j, (void *const *) root, cmp_fn) != NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
221 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
222 fputs ("Found element which is not in tree yet.\n", stdout);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
223 error = 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
224 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
225 elem = tsearch (x + j, root, cmp_fn);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
226 if (elem == 0
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
227 || tfind (x + j, (void *const *) root, cmp_fn) == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
228 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
229 fputs ("Couldn't find element after it was added.\n",
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
230 stdout);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
231 error = 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
232 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
233 }
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
234
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
235 if (what == build || i < lag)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
236 break;
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
237
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
238 j = k;
18930
50d1e186bf78 fallthrough: update for GCC 7/8
Jim Meyering <meyering@fb.com>
parents: 18626
diff changeset
239 FALLTHROUGH;
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
240
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
241 case delete:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
242 elem = tfind (x + j, (void *const *) root, cmp_fn);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
243 if (elem == NULL || tdelete (x + j, root, cmp_fn) == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
244 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
245 fputs ("Error deleting element.\n", stdout);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
246 error = 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
247 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
248 break;
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
249
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
250 case find:
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
251 if (tfind (x + j, (void *const *) root, cmp_fn) == NULL)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
252 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
253 fputs ("Couldn't find element after it was added.\n", stdout);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
254 error = 1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
255 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
256 break;
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
257
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
258 }
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
259 }
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
260 }
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
261
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
262
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
263 int
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
264 main (int argc, char **argv)
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
265 {
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
266 int total_error = 0;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
267 void *root = NULL;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
268 int i, j;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
269
9943
07d10f7b50cd Fix link error on mingw.
Bruno Haible <bruno@clisp.org>
parents: 9308
diff changeset
270 #if HAVE_INITSTATE
40155
84fd38f4932c tests: Fix some "unused variable" warnings.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
271 static char state[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
84fd38f4932c tests: Fix some "unused variable" warnings.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
272
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
273 initstate (SEED, state, 8);
9943
07d10f7b50cd Fix link error on mingw.
Bruno Haible <bruno@clisp.org>
parents: 9308
diff changeset
274 #endif
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
275
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
276 for (i = 0; i < SIZE; ++i)
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
277 x[i] = i;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
278
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
279 /* Do this loop several times to get different permutations for the
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
280 random case. */
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
281 fputs ("Series I\n", stdout);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
282 for (i = 0; i < PASSES; ++i)
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
283 {
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
284 fprintf (stdout, "Pass %d... ", i + 1);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
285 fflush (stdout);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
286 error = 0;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
287
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
288 mangle_tree (ascending, build, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
289 mangle_tree (ascending, find, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
290 mangle_tree (descending, find, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
291 mangle_tree (randomorder, find, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
292 walk_tree (root, SIZE);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
293 mangle_tree (ascending, delete, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
294
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
295 mangle_tree (ascending, build, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
296 walk_tree (root, SIZE);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
297 mangle_tree (descending, delete, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
298
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
299 mangle_tree (ascending, build, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
300 walk_tree (root, SIZE);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
301 mangle_tree (randomorder, delete, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
302
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
303 mangle_tree (descending, build, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
304 mangle_tree (ascending, find, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
305 mangle_tree (descending, find, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
306 mangle_tree (randomorder, find, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
307 walk_tree (root, SIZE);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
308 mangle_tree (descending, delete, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
309
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
310 mangle_tree (descending, build, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
311 walk_tree (root, SIZE);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
312 mangle_tree (descending, delete, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
313
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
314 mangle_tree (descending, build, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
315 walk_tree (root, SIZE);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
316 mangle_tree (randomorder, delete, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
317
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
318 mangle_tree (randomorder, build, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
319 mangle_tree (ascending, find, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
320 mangle_tree (descending, find, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
321 mangle_tree (randomorder, find, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
322 walk_tree (root, SIZE);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
323 mangle_tree (randomorder, delete, &root, 0);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
324
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
325 for (j = 1; j < SIZE; j *= 2)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
326 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
327 mangle_tree (randomorder, build_and_del, &root, j);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9943
diff changeset
328 }
8534
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
329
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
330 fputs (error ? " failed!\n" : " ok.\n", stdout);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
331 total_error |= error;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
332 }
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
333
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
334 fputs ("Series II\n", stdout);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
335 for (i = 1; i < SIZE; i *= 2)
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
336 {
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
337 fprintf (stdout, "For size %d... ", i);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
338 fflush (stdout);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
339 error = 0;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
340
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
341 mangle_tree (ascending, build_and_del, &root, i);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
342 mangle_tree (descending, build_and_del, &root, i);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
343 mangle_tree (ascending, build_and_del, &root, i);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
344 mangle_tree (descending, build_and_del, &root, i);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
345 mangle_tree (ascending, build_and_del, &root, i);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
346 mangle_tree (descending, build_and_del, &root, i);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
347 mangle_tree (ascending, build_and_del, &root, i);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
348 mangle_tree (descending, build_and_del, &root, i);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
349
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
350 fputs (error ? " failed!\n" : " ok.\n", stdout);
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
351 total_error |= error;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
352 }
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
353
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
354 return total_error;
342c23c60847 Tests for module 'tsearch'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
355 }