General cleanups, and argument validations.
[reservoir_sample] / test / validate-statistics.sh
diff --git a/test/validate-statistics.sh b/test/validate-statistics.sh
new file mode 100755 (executable)
index 0000000..0df8fb1
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/bash
+#
+
+# Collects and counts the output of multiple invocations over the same input stream.
+# Counts ought to be roughly the same, based on quality of random source.
+
+invoke_n() {
+       seq $1 | ./reservoir_sample -r /dev/random 2>/dev/null
+}
+
+invoke_n_i() {
+       local i=0
+       while [ $i -lt $2 ]
+       do
+               invoke_n $1
+               ((i++))
+               local note=`expr $i % 1000`
+               if [ $note -eq 0 ]
+                       then
+                       echo "... iteration $i of $2" 1>&2
+               fi
+       done
+}
+
+tally_n_i() {
+       invoke_n_i $1 $2 | sort -n | uniq -c
+}
+
+tally_n_i 20 10000