1 #include <ccan/tally/tally.c>
2 #include <ccan/tap/tap.h>
11 plan_tests(100 + 1 + 10 + 1 + 100 + 1 + 10 + 1 + 10 + 2 + 1);
13 /* Uniform distribution, easy. */
14 tally = tally_new(100);
15 for (i = 0; i < 100; i++)
19 graph = p = tally_histogram(tally, 20, 100);
20 for (i = 0; i < 100; i++) {
21 char *eol = strchr(p, '\n');
23 /* We expect it filled all way to the end. */
32 graph = p = tally_histogram(tally, 20, 10);
33 for (i = 0; i < 10; i++) {
34 char *eol = strchr(p, '\n');
36 /* Last once can be truncated (bucket aliasing) */
41 } else if (eol - p == 20) {
44 fail("Overwidth line %s", p);
47 /* We should, at worst, half-fill graph */
56 /* Enlarged height (gets capped). */
57 graph = p = tally_histogram(tally, 20, 1000);
58 for (i = 0; i < 100; i++) {
59 char *eol = strchr(p, '\n');
60 /* We expect it filled all way to the end. */
68 /* Distinctive increasing pattern. */
69 tally = tally_new(10);
70 for (i = 0; i < 10; i++) {
72 for (j = 0; j <= i; j++)
76 graph = p = tally_histogram(tally, 10, 10);
77 for (i = 0; i < 10; i++) {
78 char *eol = strchr(p, '\n');
83 diag("Here's the pretty: %s", graph);
87 /* With negative values. */
88 tally = tally_new(10);
89 for (i = 0; i < 10; i++) {
90 tally_add(tally, i - 5);
93 graph = p = tally_histogram(tally, 10, 10);
94 for (i = 0; i < 10; i++) {
95 char *eol = strchr(p, '\n');
97 /* We expect it filled all way to the end. */
100 /* Check min/max labels. */
102 ok1(strncmp(p, "-5*", 3) == 0);
104 ok1(strncmp(p, "4*", 2) == 0);
111 return exit_status();