Debian Codegraph @

tests/test.c

raw
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 */
6
7 #include <stdio.h>
8 #include <string.h>
9
10 extern const char * in_word_set (const char *, size_t);
11
12 #define MAX_LEN 80
13
14 int
15 main (int argc, char *argv[])
16 {
17 int verbose = argc > 1 ? 1 : 0;
18 char buf[MAX_LEN];
19
20 while (fgets (buf, MAX_LEN, stdin))
21 {
22 if (strlen (buf) > 0 && buf[strlen (buf) - 1] == '\n')
23 buf[strlen (buf) - 1] = '\0';
24
25 if (in_word_set (buf, strlen (buf)))
26 {
27 if (verbose)
28 printf ("in word set %s\n", buf);
29 }
30 else
31 {
32 if (verbose)
33 printf ("NOT in word set %s\n", buf);
34 }
35 }
36
37 return 0;
38 }