root/maint/gnulib/tests/test-fstrcmp.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. check_fstrcmp
  2. main

   1 /* Test of fuzzy string comparison.
   2    Copyright (C) 2007-2021 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 <https://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 
  25 #include "macros.h"
  26 
  27 static bool
  28 check_fstrcmp (const char *string1, const char *string2, double expected)
     /* [previous][next][first][last][top][bottom][index][help] */
  29 {
  30   /* The use of 'volatile' guarantees that excess precision bits are dropped
  31      before the addition and before the following comparison at the caller's
  32      site.  It is necessary on x86 systems where double-floats are not IEEE
  33      compliant by default, to avoid that msgmerge results become platform and
  34      compiler option dependent.  'volatile' is a portable alternative to gcc's
  35      -ffloat-store option.  */
  36   {
  37     volatile double result = fstrcmp (string1, string2);
  38     if (!(result == expected))
  39       return false;
  40   }
  41   {
  42     volatile double result = fstrcmp_bounded (string1, string2, expected);
  43     if (!(result == expected))
  44       return false;
  45   }
  46   {
  47     double bound = expected * 0.5; /* implies bound <= expected */
  48     volatile double result = fstrcmp_bounded (string1, string2, bound);
  49     if (!(result == expected))
  50       return false;
  51   }
  52   {
  53     double bound = (1 + expected) * 0.5;
  54     if (expected < bound)
  55       {
  56         volatile double result = fstrcmp_bounded (string1, string2, bound);
  57         if (!(result < bound))
  58           return false;
  59       }
  60   }
  61 
  62   return true;
  63 }
  64 
  65 int
  66 main (int argc, char *argv[])
     /* [previous][next][first][last][top][bottom][index][help] */
  67 {
  68   ASSERT (check_fstrcmp ("Langstrumpf", "Langstrumpf", 1.0));
  69   ASSERT (check_fstrcmp ("Levenshtein", "Levenstein", 20./21.));
  70   ASSERT (check_fstrcmp ("Levenstein", "Levenshtein", 20./21.));
  71   ASSERT (check_fstrcmp ("xy", "yx", 1./2.));
  72   ASSERT (check_fstrcmp ("George Bush", "Abraham Lincoln", 2./13.));
  73   ASSERT (check_fstrcmp ("George Bush", "George \"Bugs\" Moran", 2./3.));
  74 
  75   return 0;
  76 }

/* [previous][next][first][last][top][bottom][index][help] */