Initial commit
[cgperf.git] / tests / test.c
blob52d41d8bbfac614d9b1d76b1221e1c20eeff5fd2
1 /*
2 Tests the generated perfect hash function.
3 The -v option prints diagnostics as to whether a word is in
4 the set or not. Without -v the program is useful for timing.
5 */
7 #include <stdio.h>
8 #include <string.h>
10 extern const char * in_word_set (const char *, size_t);
12 #define MAX_LEN 80
14 int
15 main (int argc, char *argv[])
17 int verbose = argc > 1 ? 1 : 0;
18 char buf[MAX_LEN];
20 while (fgets (buf, MAX_LEN, stdin))
22 if (strlen (buf) > 0 && buf[strlen (buf) - 1] == '\n')
23 buf[strlen (buf) - 1] = '\0';
25 if (in_word_set (buf, strlen (buf)))
27 if (verbose)
28 printf ("in word set %s\n", buf);
30 else
32 if (verbose)
33 printf ("NOT in word set %s\n", buf);
37 return 0;