~ubuntu-branches/ubuntu/dapper/dbacl/dapper

« back to all changes in this revision

Viewing changes to src/tests/shannon-2.shin

  • Committer: Bazaar Package Importer
  • Author(s): Clint Adams
  • Date: 2005-05-07 12:59:53 UTC
  • Revision ID: james.westby@ubuntu.com-20050507125953-xzy2bwkb2qamglwm
Tags: upstream-1.9
ImportĀ upstreamĀ versionĀ 1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
# test average shannon entropy calculation for multiple documents
 
3
# we test with -w 2 switch (type -p only counts 2-grams for the shannon entropy)
 
4
# (verification is more accurate with identical mails)
 
5
 
 
6
PATH=/bin:/usr/bin
 
7
DBACL=$TESTBIN/dbacl
 
8
 
 
9
prerequisite_command() {
 
10
    type $2 2>&1 > /dev/null
 
11
    if [ 0 -ne $? ]; then
 
12
        echo "$1: $2 not found, test will be skipped"
 
13
        exit 77
 
14
    fi
 
15
}
 
16
 
 
17
prerequisite_command $0 formail
 
18
prerequisite_command $0 grep
 
19
prerequisite_command $0 awk
 
20
prerequisite_command $0 tr
 
21
 
 
22
DBACL_PATH="`pwd`/`basename $0 .sh`_`date +"%Y%m%dT%H%M%S"`"
 
23
export DBACL_PATH
 
24
 
 
25
mkdir "$DBACL_PATH"
 
26
 
 
27
(echo ; echo "From - -" ; cat sample.spam-1 ; \
 
28
 echo ; echo "From - -" ; cat sample.spam-1 ; \
 
29
 echo ; echo "From - -" ; cat sample.spam-1 ; \
 
30
 echo ; echo "From - -" ; cat sample.spam-1 ; ) \
 
31
    > "$DBACL_PATH/mbox"
 
32
 
 
33
cat "$DBACL_PATH/mbox" \
 
34
    | $DBACL -l dummy -T email -X -d -w 2 \
 
35
    | grep '# shannon' \
 
36
    | awk '{print $3/log(2)}' \
 
37
    | tr '\n' ' ' \
 
38
    > "$DBACL_PATH/out1"
 
39
 
 
40
cat "$DBACL_PATH/mbox" \
 
41
    | formail -s $DBACL -c dummy -vX \
 
42
    | awk '{d += $3; e += $5} END{print (d/4), (e/4)}' \
 
43
    | tr '\n' ' ' \
 
44
    > "$DBACL_PATH/out2"
 
45
 
 
46
echo "`cat \"$DBACL_PATH/out1\"` `cat \"$DBACL_PATH/out2\"`" \
 
47
    | awk '
 
48
function abs(x) { return (x >= 0) ? x : -x }
 
49
{
 
50
    # must invert exit value
 
51
    exit !( abs($1 - $3) < (0.15/2.0) * ($1 + $3) ) 
 
52
}'
 
53
 
 
54
RESULT=$?
 
55
rm -rf "$DBACL_PATH"
 
56
 
 
57
exit $RESULT
 
 
b'\\ No newline at end of file'