General cleanups, and argument validations.
[reservoir_sample] / test / validate-statistics.sh
1 #!/bin/bash
2 #
3
4 # Collects and counts the output of multiple invocations over the same input stream.
5 # Counts ought to be roughly the same, based on quality of random source.
6
7 invoke_n() {
8 seq $1 | ./reservoir_sample -r /dev/random 2>/dev/null
9 }
10
11 invoke_n_i() {
12 local i=0
13 while [ $i -lt $2 ]
14 do
15 invoke_n $1
16 ((i++))
17 local note=`expr $i % 1000`
18 if [ $note -eq 0 ]
19 then
20 echo "... iteration $i of $2" 1>&2
21 fi
22 done
23 }
24
25 tally_n_i() {
26 invoke_n_i $1 $2 | sort -n | uniq -c
27 }
28
29 tally_n_i 20 10000