From 84e452f5665cbeac02f41dd30b9e43556f12b178 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Sat, 31 Aug 2024 15:21:55 -0400 Subject: test randomness of suffix selection --- test | 6 +++++- tests/stats | 10 ++++++++++ tests/stats.awk | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tests/stats create mode 100644 tests/stats.awk diff --git a/test b/test index dd8e802..2ae88b5 100755 --- a/test +++ b/test @@ -15,4 +15,8 @@ rm out orig=tests/psalms ./markov <$orig > out awk -f tests/match.awk $orig out -rm out \ No newline at end of file +rm out + +# Check that the output has a similar ratio of c's and d's to test randomness of +# suffix selection. +./markov epsilon) { + printf "difference between the number of c's (%d) and 10 times the number of d's (10*%d=%d)is too great (%.1f%% > %.1f%%)\n", + nc, nd, 10*nd, diff*100, epsilon*100 + exit 1 + } +} + +# percdiff: percent difference between a and b +function percdiff(a, b) { + return abs(a - b) / avg(a, b) +} + +function abs(x) { + if (x < 0) + return -x + return x +} + +function avg(a, b) { + return (a + b) / 2 +} \ No newline at end of file -- cgit v1.2.3