librfn
An ad-hoc utility library
statstest.c
Go to the documentation of this file.
1 /*
2  * statstest.c
3  *
4  * Part of librfn (a general utility library from redfelineninja.org.uk)
5  *
6  * Copyright (C) 2012 Daniel Thompson <daniel@redfelineninja.org.uk>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published
10  * by the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  */
13 
14 #undef NDEBUG
15 //#define VERBOSE
16 
17 #include <assert.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 
22 #include <librfn.h>
23 
24 int main()
25 {
26  stats_t s;
27 
28  stats_init(&s);
29  for (int i = 0; i < 10; i++)
30  stats_add(&s, 1000);
31  verify(1000 == stats_mean(&s));
32  verify(100000 == stats_per_million(&s, 100000));
33 
34  for (int i = 0; i < 5; i++) {
35  stats_add(&s, 100);
36  stats_add(&s, 1900);
37  }
38  verify(1000 == stats_mean(&s));
39  verify(200000 == stats_per_million(&s, 100000));
40 
41  stats_init(&s);
42  for (int i = 0; i < 10; i++)
43  stats_add(&s, 1000);
44  verify(1000 == stats_mean(&s));
45  verify(100000 == stats_per_million(&s, 100000));
46 
47  return 0;
48 }
void stats_add(stats_t *s, statval_t d)
Definition: stats.c:30
void stats_init(stats_t *s)
Definition: stats.c:16
int main()
Definition: statstest.c:24
#define verify(x)
Definition: util.h:55
Definition: stats.h:41
statval_t stats_per_million(stats_t *s, statval_t total)
Definition: stats.c:51
statval_t stats_mean(stats_t *s)
Definition: stats.c:42