tally: fix FreeBSD compile, memleak in tests.
[ccan] / ccan / tally / test / run-mean.c
1 #include <ccan/tally/tally.c>
2 #include <ccan/tap/tap.h>
3
4 int main(void)
5 {
6         int i;
7         struct tally *tally = tally_new(0);
8         ssize_t min, max;
9
10         max = (ssize_t)~(1ULL << (sizeof(max)*CHAR_BIT - 1));
11         min = (ssize_t)(1ULL << (sizeof(max)*CHAR_BIT - 1));
12
13         plan_tests(100 + 100);
14         /* Simple mean test: should always be 0. */
15         for (i = 0; i < 100; i++) {
16                 tally_add(tally, i);
17                 tally_add(tally, -i);
18                 ok1(tally_mean(tally) == 0);
19         }
20
21         /* Works for big values too... */
22         for (i = 0; i < 100; i++) {
23                 tally_add(tally, max - i);
24                 tally_add(tally, min + 1 + i);
25                 ok1(tally_mean(tally) == 0);
26         }
27
28         free(tally);
29         return exit_status();
30 }