summaryrefslogtreecommitdiff
path: root/lib/ccan/tally/test/run-mean.c
blob: b43dea6b2861cd062fb52ff83d1840aaa2304497 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <ccan/tally/tally.c>
#include <ccan/tap/tap.h>

int main(void)
{
	int i;
	struct tally *tally = tally_new(0);
	ssize_t min, max;

	max = (ssize_t)~(1ULL << (sizeof(max)*CHAR_BIT - 1));
	min = (ssize_t)(1ULL << (sizeof(max)*CHAR_BIT - 1));

	plan_tests(100 + 100);
	/* Simple mean test: should always be 0. */
	for (i = 0; i < 100; i++) {
		tally_add(tally, i);
		tally_add(tally, -i);
		ok1(tally_mean(tally) == 0);
	}

	/* Works for big values too... */
	for (i = 0; i < 100; i++) {
		tally_add(tally, max - i);
		tally_add(tally, min + 1 + i);
		ok1(tally_mean(tally) == 0);
	}

	free(tally);
	return exit_status();
}