1 #include <ccan/tally/tally.c>
2 #include <ccan/tap/tap.h>
10 plan_tests(100 + 1 + 10 + 1 + 100 + 1 + 10 + 1 + 10 * 2 + 1);
12 /* Uniform distribution, easy. */
13 tally = tally_new(100);
14 for (i = 0; i < 100; i++)
18 graph = p = tally_histogram(tally, 20, 100);
19 for (i = 0; i < 100; i++) {
20 char *eol = strchr(p, '\n');
22 /* We expect it filled all way to the end. */
30 graph = p = tally_histogram(tally, 20, 10);
31 for (i = 0; i < 10; i++) {
32 char *eol = strchr(p, '\n');
34 /* First once can be truncated (bucket aliasing) */
36 ok1(eol - p == 20 || (eol - p < 20 && i == 0));
38 /* We should, at worst, half-fill graph */
47 /* Enlarged height (gets capped). */
48 graph = p = tally_histogram(tally, 20, 1000);
49 for (i = 0; i < 100; i++) {
50 char *eol = strchr(p, '\n');
51 /* We expect it filled all way to the end. */
59 /* Distinctive increasing pattern. */
60 tally = tally_new(10);
61 for (i = 0; i < 10; i++) {
63 for (j = 0; j <= i; j++)
67 graph = p = tally_histogram(tally, 10, 10);
68 for (i = 0; i < 10; i++) {
69 char *eol = strchr(p, '\n');
70 ok1(eol - p == 10 - i);
74 diag("Here's the pretty: %s", graph);
78 /* With negative values. */
79 tally = tally_new(10);
80 for (i = 0; i < 10; i++) {
81 tally_add(tally, i - 5);
84 graph = p = tally_histogram(tally, 10, 10);
85 for (i = 0; i < 10; i++) {
86 char *eol = strchr(p, '\n');
88 /* We expect it filled all way to the end. */
91 /* Check min/max labels. */
93 ok1(strncmp(p, "4*", 2) == 0);
95 ok1(strncmp(p, "-5*", 3) == 0);
97 ok1(p[0] == '+'); /* 0 marker */
103 diag("Here's the pretty: %s", graph);
107 return exit_status();