usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-fstrcmp.c
blob7c0114e70bff073871e9d9ff3c991631c3702921
1 /* Test of fuzzy string comparison.
2 Copyright (C) 2007-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
19 #include <config.h>
21 #include "fstrcmp.h"
24 #include "macros.h"
26 static bool
27 check_fstrcmp (const char *string1, const char *string2, double expected)
29 /* The use of 'volatile' guarantees that excess precision bits are dropped
30 before the addition and before the following comparison at the caller's
31 site. It is necessary on x86 systems where double-floats are not IEEE
32 compliant by default, to avoid that msgmerge results become platform and
33 compiler option dependent. 'volatile' is a portable alternative to gcc's
34 -ffloat-store option. */
36 volatile double result = fstrcmp (string1, string2);
37 if (!(result == expected))
38 return false;
41 volatile double result = fstrcmp_bounded (string1, string2, expected);
42 if (!(result == expected))
43 return false;
46 double bound = expected * 0.5; /* implies bound <= expected */
47 volatile double result = fstrcmp_bounded (string1, string2, bound);
48 if (!(result == expected))
49 return false;
52 double bound = (1 + expected) * 0.5;
53 if (expected < bound)
55 volatile double result = fstrcmp_bounded (string1, string2, bound);
56 if (!(result < bound))
57 return false;
61 return true;
64 int
65 main (int argc, char *argv[])
67 ASSERT (check_fstrcmp ("Langstrumpf", "Langstrumpf", 1.0));
68 ASSERT (check_fstrcmp ("Levenshtein", "Levenstein", 20./21.));
69 ASSERT (check_fstrcmp ("Levenstein", "Levenshtein", 20./21.));
70 ASSERT (check_fstrcmp ("xy", "yx", 1./2.));
71 ASSERT (check_fstrcmp ("George Bush", "Abraham Lincoln", 2./13.));
72 ASSERT (check_fstrcmp ("George Bush", "George \"Bugs\" Moran", 2./3.));
74 return test_exit_status;