1 #include <ccan/tally/tally.c>
2 #include <ccan/tap/tap.h>
7 struct tally *tally = tally_new(100);
8 ssize_t min, max, mode;
11 max = (ssize_t)~(1ULL << (sizeof(max)*CHAR_BIT - 1));
12 min = (ssize_t)(1ULL << (sizeof(max)*CHAR_BIT - 1));
14 plan_tests(100 + 50 + 100 + 100 + 10);
15 /* Simple mode test: should always be around 0 (we add that twice). */
16 for (i = 0; i < 100; i++) {
19 mode = tally_approx_mode(tally, &err);
22 ok1(mode - (ssize_t)err <= 0 && mode + (ssize_t)err >= 0);
25 /* Works for big values too... */
26 for (i = 0; i < 100; i++) {
27 tally_add(tally, max - i);
28 tally_add(tally, min + 1 + i);
29 mode = tally_approx_mode(tally, &err);
30 ok1(mode - (ssize_t)err <= 0 && mode + (ssize_t)err >= 0);
34 tally = tally_new(10);
36 for (i = 0; i < 100; i++) {
38 mode = tally_approx_mode(tally, &err);
41 ok1(mode - (ssize_t)err <= 0 && mode + (ssize_t)err >= 0);