summaryrefslogtreecommitdiff
path: root/lib/ccan/tally/test/run-min-max.c
blob: c92f6d382a490356224826ed96f121d4bfd7ef2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <ccan/tally/tally.c>
#include <ccan/tap/tap.h>

int main(void)
{
	int i;
	struct tally *tally = tally_new(0);

	plan_tests(100 * 4);
	/* Test max, min and num. */
	for (i = 0; i < 100; i++) {
		tally_add(tally, i);
		ok1(tally_num(tally) == i*2 + 1);
		tally_add(tally, -i);
		ok1(tally_num(tally) == i*2 + 2);
		ok1(tally_max(tally) == i);
		ok1(tally_min(tally) == -i);
	}
	free(tally);
	return exit_status();
}