2 * SRE, Tue Oct 28 08:03:10 1997 [Newton Institute, Cambridge UK]
4 * Test driver for tophits.c. Returns 0 if everything is OK.
7 * -v Verbose; print stuff.
18 static char banner[] = "\
19 tophits_test : internal verification of tophits.c";
21 static char usage[] = "\
22 Usage: tophits_test [-options]\n\
23 Available options are:\n\
24 -h : help; display this usage info\n\
25 -s <x> : set random seed to <x>\n\
26 -v : be verbose (default is to simply exit with status 1 or 0)\n\
29 static char experts[] = "\
32 static struct opt_s OPTIONS[] = {
33 { "-h", TRUE, sqdARG_NONE },
34 { "-s", TRUE, sqdARG_INT },
35 { "-v", TRUE, sqdARG_NONE },
37 #define NOPTIONS (sizeof(OPTIONS) / sizeof(struct opt_s))
40 main(int argc, char **argv)
42 struct tophit_s *hit; /* hit list */
43 int i,j; /* counters */
44 int nsamples; /* option: # of random "scores" */
45 int be_verbose; /* option: TRUE to show output */
46 int seed; /* option: random number seed */
47 int paramH; /* option: H parameter */
48 int paramA; /* option: A parameter */
49 double *list; /* list of "scores" */
50 double tmp; /* used for swapping */
53 char *optname; /* name of option found by Getopt() */
54 char *optarg; /* argument found by Getopt() */
55 int optind; /* index in argv[] */
57 /***********************************************
59 ***********************************************/
61 seed = (int) time ((time_t *) NULL);
66 while (Getopt(argc, argv, OPTIONS, NOPTIONS, usage,
67 &optind, &optname, &optarg)) {
68 if (strcmp(optname, "-s") == 0) { seed = atoi(optarg); }
69 else if (strcmp(optname, "-v") == 0) { be_verbose = TRUE; }
70 else if (strcmp(optname, "-h") == 0) {
71 Banner(stdout, banner);
77 if (argc - optind != 0)
78 Die("Incorrect number of arguments.\n%s\n", usage);
82 printf("%d\tSEED\n", seed);
84 /***********************************************
85 * Generate three tiers of numbers:
86 * paramA - really good scores, 1000-2000
87 * paramH - good scores, 100-200
88 * nsamples - paramH - paramA: bad scores, 10-20
90 ***********************************************/
92 list = MallocOrDie (sizeof(double) * nsamples);
93 for (i = 0; i < paramA; i++)
94 list[i] = 1000. + 1000. * sre_random();
95 for (; i < paramA + paramH; i++)
96 list[i] = 100. + 100. * sre_random();
97 for (; i < nsamples; i++)
98 list[i] = 10. + 10. * sre_random();
100 for (i = 0; i < nsamples; i++)
102 j = CHOOSE(nsamples);
109 for (i = 0; i < nsamples; i++)
110 printf("%8.2f\tTest set\n", list[i]);
112 /***********************************************
113 * Test of FullSortTophits().
114 * Fill up a hit list with random numbers;
116 * check that all top H are >= 100 and sorted.
117 ***********************************************/
119 hit = AllocTophits(100);
120 for (i = 0; i < nsamples; i++)
121 RegisterHit(hit, list[i], 0., (float) list[i], 0., 0.,
122 NULL, NULL, NULL, /* name, acc, desc */
127 FullSortTophits(hit);
131 for (i = 0; i < hit->num; i++)
133 GetRankedHit(hit, i, NULL, &score, NULL, NULL,
134 NULL, NULL, NULL, /* name, acc, desc */
139 printf("%8.2f FullSort()\n", score);
143 for (i = 0; i < hit->num-1; i++)
145 GetRankedHit(hit, i, NULL, &score, NULL, NULL,
146 NULL, NULL, NULL, /* name, acc, desc */
151 GetRankedHit(hit, i+1,NULL, &score2,NULL, NULL,
152 NULL, NULL, NULL, /* name, acc, desc */
158 Die("FullSortTophits() fails test: order wrong");
159 if (i < paramA && score < 1000.)
160 Die("FullSortTophits() fails test: lost a number");
161 if (i < paramA + paramH && score < 100.)
162 Die("FullSortTophits() fails test: lost a number");
168 if (be_verbose) printf("tophits_test is OK\n");