#! /bin/sh

# Note:  When run via "make check", test output files are automatically deleted.
#	 When run from the command line, output files are left in directory
#	 wordhist.YYYYMMDD.  This is useful when something is different.
#
#	 ./inputs  - test inputs
#	 ./outputs - known correct outputs
#
#	 wordhist.YYYYMMDD:
#		directory containing individual output files

NODB=1 . ${srcdir=.}/t.frame

[ -d "$TMPDIR"/tests ] && rm -rf "$TMPDIR"/tests
mkdir -p "$TMPDIR"/tests

OUT="$TMPDIR"/wordhist.out
REF="$TMPDIR/wordhist.ref"

cat <<EOF > "$REF"
Histogram
score   count  pct  histogram
0.00     3515 66.30 ################################################
0.05        1  0.02 #
0.10        1  0.02 #
0.15        7  0.13 #
0.20       10  0.19 #
0.25       12  0.23 #
0.30       16  0.30 #
0.35       27  0.51 #
0.40       38  0.72 #
0.45       19  0.36 #
0.50       82  1.55 ##
0.55       10  0.19 #
0.60       29  0.55 #
0.65      135  2.55 ##
0.70        7  0.13 #
0.75       22  0.41 #
0.80       63  1.19 #
0.85       14  0.26 #
0.90       28  0.53 #
0.95     1266 23.88 ##################
tot      5302
hapaxes:  ham    2593 (48.91%), spam     784 (14.79%)
   pure:  ham    3515 (66.30%), spam    1257 (23.71%)
EOF

OPTS="-C -y 0"

$BOGOFILTER $OPTS -s < "$SYSTEST/inputs/spam.mbx"
$BOGOFILTER $OPTS -n < "$SYSTEST/inputs/good.mbx"

$BOGOUTIL -C -H "$BOGOFILTER_DIR/wordlist.$DB_EXT" > "$OUT"
$BOGOUTIL -C -d "$BOGOFILTER_DIR/wordlist.$DB_EXT" > "$TMPDIR"/wordlist.txt

if  [ $verbose -eq 0 ]; then
    cmp "$REF" "$OUT"
else
    diff $DIFF_BRIEF "$REF" "$OUT"
fi
