Make roundf-tests module depend on floorf, ceilf.
[gnulib.git] / tests / test-fstrcmp.c
1 /* Test of fuzzy string comparison.
2    Copyright (C) 2007 Free Software Foundation, Inc.
3
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.
8
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.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
16
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
18
19 #include <config.h>
20
21 #include "fstrcmp.h"
22
23 #include <stdbool.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26
27 #define ASSERT(expr) \
28   do                                                                         \
29     {                                                                        \
30       if (!(expr))                                                           \
31         {                                                                    \
32           fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
33           abort ();                                                          \
34         }                                                                    \
35     }                                                                        \
36   while (0)
37
38 static bool
39 check_fstrcmp (const char *string1, const char *string2, double expected)
40 {
41   /* The use of 'volatile' guarantees that excess precision bits are dropped
42      before the addition and before the following comparison at the caller's
43      site.  It is necessary on x86 systems where double-floats are not IEEE
44      compliant by default, to avoid that msgmerge results become platform and
45      compiler option dependent.  'volatile' is a portable alternative to gcc's
46      -ffloat-store option.  */
47   volatile double result = fstrcmp (string1, string2);
48   return (result == expected);
49 }
50
51 int
52 main ()
53 {
54   ASSERT (check_fstrcmp ("Langstrumpf", "Langstrumpf", 1.0));
55   ASSERT (check_fstrcmp ("Levenshtein", "Levenstein", 20./21.));
56   ASSERT (check_fstrcmp ("Levenstein", "Levenshtein", 20./21.));
57   ASSERT (check_fstrcmp ("xy", "yx", 1./2.));
58   ASSERT (check_fstrcmp ("George Bush", "Abraham Lincoln", 2./13.));
59   ASSERT (check_fstrcmp ("George Bush", "George \"Bugs\" Moran", 2./3.));
60
61   return 0;
62 }