|
From: <jgr...@us...> - 2003-07-27 15:42:46
|
Update of /cvsroot/popfile/engine/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv17399/tests
Modified Files:
TestBayes.tst
Log Message:
More tests for Classifier::Bayes to cover adding and removing messages in a bucket
Index: TestBayes.tst
===================================================================
RCS file: /cvsroot/popfile/engine/tests/TestBayes.tst,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** TestBayes.tst 27 Jul 2003 01:37:58 -0000 1.14
--- TestBayes.tst 27 Jul 2003 15:42:43 -0000 1.15
***************
*** 57,61 ****
# get_bucket_word_list
! # TODO
# get_word_count
--- 57,64 ----
# get_bucket_word_list
! my @words = $b->get_bucket_word_list( 'personal' );
! test_assert_equal( $#words, 1 );
! test_assert_equal( $words[0], '|bar 2||baz 100|' );
! test_assert_equal( $words[1], '|foo 1|' );
# get_word_count
***************
*** 186,197 ****
--- 189,281 ----
$line = <FILE>;
test_assert_regexp( $line, '__CORPUS__ __VERSION__ 1' );
+ $line = <FILE>;
+ test_assert( !defined( $line ) );
close FILE;
# add_message_to_bucket
+ my %words;
+
+ open WORDS, "<TestMailParse021.wrd";
+ while ( <WORDS> ) {
+ if ( /(.+) (\d+)/ ) {
+ $words{$1} = $2;
+ }
+ }
+ close WORDS;
+
+ test_assert( !$b->add_message_to_bucket( 'none', 'TestMailParse021.msg' ) );
+ test_assert( $b->add_message_to_bucket( 'zeotrope', 'TestMailParse021.msg' ) );
+ open FILE, "<corpus/zeotrope/table";
+ $line = <FILE>;
+ test_assert_regexp( $line, '__CORPUS__ __VERSION__ 1' );
+ while ( <FILE> ) {
+ if ( /(.+) (\d+)/ ) {
+ test_assert_equal( $words{$1}, $2, "zeotrope: $1 $2 $words{$1}" );
+ }
+ }
+ close FILE;
+
+ test_assert( $b->add_message_to_bucket( 'zeotrope', 'TestMailParse021.msg' ) );
+
+ open FILE, "<corpus/zeotrope/table";
+ $line = <FILE>;
+ test_assert_regexp( $line, '__CORPUS__ __VERSION__ 1' );
+ while ( <FILE> ) {
+ if ( /(.+) (\d+)/ ) {
+ test_assert_equal( ($words{$1}*2), $2, "zeotrope: $1 $2 $words{$1}" );
+ }
+ }
+ close FILE;
+
# remove_message_from_bucket
+ test_assert( !$b->remove_message_from_bucket( 'none', 'TestMailParse021.msg' ) );
+ test_assert( $b->remove_message_from_bucket( 'zeotrope', 'TestMailParse021.msg' ) );
+ test_assert( $b->remove_message_from_bucket( 'zeotrope', 'TestMailParse021.msg' ) );
+
+ open FILE, "<corpus/zeotrope/table";
+ $line = <FILE>;
+ test_assert_regexp( $line, '__CORPUS__ __VERSION__ 1' );
+ $line = <FILE>;
+ test_assert( !defined( $line ) );
+ close FILE;
+
# add_messages_to_bucket
+ test_assert( $b->add_message_to_bucket( 'zeotrope', [ 'TestMailParse021.msg', 'TestMailParse021.msg' ] ) );
+
+ open FILE, "<corpus/zeotrope/table";
+ $line = <FILE>;
+ test_assert_regexp( $line, '__CORPUS__ __VERSION__ 1' );
+ while ( <FILE> ) {
+ if ( /(.+) (\d+)/ ) {
+ test_assert_equal( ($words{$1}*2), $2, "zeotrope: $1 $2 $words{$1}" );
+ }
+ }
+ close FILE;
+
+ # Test corrupting the corpus
+
+ open FILE, ">corpus/zeotrope/table";
+ print FILE "__CORPUS__ __VERSION__ 2\n";
+ close FILE;
+
+ open STDERR, ">temp.tmp";
+ test_assert( !$b->add_message_to_bucket( 'zeotrope', 'TestMailParse021.msg' ) );
+ close STDERR;
+ open FILE, "<temp.tmp";
+ $line = <FILE>;
+ test_assert_regexp( $line, 'Incompatible corpus version in zeotrope' );
+ close FILE;
+
+ open STDERR, ">temp.tmp";
+ test_assert( !$b->remove_message_from_bucket( 'zeotrope', 'TestMailParse021.msg' ) );
+ close STDERR;
+ open FILE, "<temp.tmp";
+ $line = <FILE>;
+ test_assert_regexp( $line, 'Incompatible corpus version in zeotrope' );
+ close FILE;
+
# delete_bucket
***************
*** 210,213 ****
--- 294,298 ----
# getting and setting values
+
test_assert_equal( $b->get_value_( 'personal', 'foo' ), log(1/103) );
$b->{total__}{personal} = 100;
|