X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftally%2Ftest%2Frun-histogram.c;h=a9894ecd8539eb3113241a2dfa171bf4bd6a09d2;hb=60b47bf5e0878f014eb1e33e7784c92e43e2fcb6;hp=8f8bd2ff3aaa8b521213727fe7b197489a2e3c1a;hpb=7a36f69eea4ee572bdf191d6048350751cd2ab5b;p=ccan diff --git a/ccan/tally/test/run-histogram.c b/ccan/tally/test/run-histogram.c index 8f8bd2ff..a9894ecd 100644 --- a/ccan/tally/test/run-histogram.c +++ b/ccan/tally/test/run-histogram.c @@ -6,9 +6,8 @@ int main(void) int i; struct tally *tally; char *graph, *p; - bool trunc; - plan_tests(100 + 1 + 10 + 1 + 100 + 1 + 10 + 1 + 10 + 2 + 1); + plan_tests(100 + 1 + 10 + 1 + 100 + 1 + 10 + 1 + 10 * 2 + 1); /* Uniform distribution, easy. */ tally = tally_new(100); @@ -28,21 +27,13 @@ int main(void) free(graph); /* Reduced height. */ - trunc = false; graph = p = tally_histogram(tally, 20, 10); for (i = 0; i < 10; i++) { char *eol = strchr(p, '\n'); - /* Last once can be truncated (bucket aliasing) */ + /* First once can be truncated (bucket aliasing) */ if (eol) { - if (eol - p < 20) { - ok1(!trunc); - trunc = true; - } else if (eol - p == 20) { - ok1(!trunc); - } else { - fail("Overwidth line %s", p); - } + ok1(eol - p == 20 || (eol - p < 20 && i == 0)); } else /* We should, at worst, half-fill graph */ ok1(i > 5); @@ -76,7 +67,7 @@ int main(void) graph = p = tally_histogram(tally, 10, 10); for (i = 0; i < 10; i++) { char *eol = strchr(p, '\n'); - ok1(eol - p == i+1); + ok1(eol - p == 10 - i); p = eol + 1; } ok1(!*p); @@ -99,12 +90,17 @@ int main(void) /* Check min/max labels. */ if (i == 0) - ok1(strncmp(p, "-5*", 3) == 0); - if (i == 9) ok1(strncmp(p, "4*", 2) == 0); + else if (i == 9) + ok1(strncmp(p, "-5*", 3) == 0); + else if (i == 4) + ok1(p[0] == '+'); /* 0 marker */ + else + ok1(p[0] == '|'); p = eol + 1; } ok1(!*p); + diag("Here's the pretty: %s", graph); free(graph); free(tally);