mirror of
https://github.com/samba-team/samba.git
synced 2025-06-28 00:49:42 +03:00
Based on commit 0284423676209380a2e07086b9b356096a2f93e6 from CCAN: Author: Rusty Russell <rusty@rustcorp.com.au> Date: Tue Jun 21 10:43:31 2011 +0930 tally: fix FreeBSD compile, memleak in tests. Posix says ssize_t is in sys/types.h; on Linux stdlib.h is enough. Autobuild-User: Rusty Russell <rusty@rustcorp.com.au> Autobuild-Date: Tue Jun 21 05:52:12 CEST 2011 on sn-devel-104
31 lines
629 B
C
31 lines
629 B
C
#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();
|
|
}
|