From 29c1c728b20c838bc94c7342f4664e5ecbdac113 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Sat, 31 Aug 2024 15:20:11 -0400 Subject: test that all generated words, pairs, and triples also occur in the input --- tests/match.awk | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/match.awk (limited to 'tests/match.awk') diff --git a/tests/match.awk b/tests/match.awk new file mode 100644 index 0000000..8f35452 --- /dev/null +++ b/tests/match.awk @@ -0,0 +1,25 @@ +# Check that all words, pairs, and triples in output ARGV[2] are in original ARGV[1] +BEGIN { + while (getline 0) { + for (i = 1; i <= NF; i++) { + wd[++nw] = $i # input words + single[$i]++ + } + } + for (i = 1; i < nw; i++) + pair[wd[i],wd[i+1]]++ + for (i = 1; i < nw-1; i++) + triple[wd[i],wd[i+1],wd[i+2]]++ + + while (getline 0) { + outwd[++ow] = $0 # output words + if (!($0 in single)) + print "unexpected word:", $0 + } + for (i = 1; i < ow; i++) + if (!((outwd[i],outwd[i+1]) in pair)) + print "unexpected pair:", outwd[i], outwd[i+1] + for (i = 1; i < ow-1; i++) + if (!((outwd[i],outwd[i+1],outwd[i+2]) in triple)) + print "unexpected triple:", outwd[i], outwd[i+1], outwd[i+2] +} \ No newline at end of file -- cgit v1.2.3