Blame tests/test.c

Packit b27855
/*
Packit b27855
   Tests the generated perfect hash function.
Packit b27855
   The -v option prints diagnostics as to whether a word is in
Packit b27855
   the set or not.  Without -v the program is useful for timing.
Packit b27855
*/
Packit b27855
Packit b27855
#include <stdio.h>
Packit b27855
#include <string.h>
Packit b27855
Packit b27855
extern const char * in_word_set (const char *, size_t);
Packit b27855
Packit b27855
#define MAX_LEN 80
Packit b27855
Packit b27855
int
Packit b27855
main (int argc, char *argv[])
Packit b27855
{
Packit b27855
  int  verbose = argc > 1 ? 1 : 0;
Packit b27855
  char buf[MAX_LEN];
Packit b27855
Packit b27855
  while (fgets (buf, MAX_LEN, stdin))
Packit b27855
    {
Packit b27855
      if (strlen (buf) > 0 && buf[strlen (buf) - 1] == '\n')
Packit b27855
        buf[strlen (buf) - 1] = '\0';
Packit b27855
Packit b27855
      if (in_word_set (buf, strlen (buf)))
Packit b27855
        {
Packit b27855
          if (verbose)
Packit b27855
            printf ("in word set %s\n", buf);
Packit b27855
        }
Packit b27855
      else
Packit b27855
        {
Packit b27855
          if (verbose)
Packit b27855
            printf ("NOT in word set %s\n", buf);
Packit b27855
        }
Packit b27855
    }
Packit b27855
Packit b27855
  return 0;
Packit b27855
}