--- trunk/t/10homer.t 2004/10/07 16:26:31 24 +++ trunk/t/10homer.t 2004/10/07 17:30:03 25 @@ -10,15 +10,15 @@ BEGIN { use_ok('jsFind'); } -my $t = new jsFind B => 100; +my $t = new jsFind B => 10; ok(-e "t/homer.txt", "Homer: The Odyssey preface"); -my $p = 0; +my $line = 0; my $text = ''; my %words; my $word_count = 0; -my $max_words = 100; +my $max_words = 10; my $res; @@ -27,53 +27,47 @@ ok(open(U, "t/homer.txt"), "open homer.txt"); while() { chomp; - if (/^\s*$/) { - $p++; + $line++; + next if (/^\s*$/); - $full_text .= "\n" if ($full_text); - $full_text = "paragraph $p\n\n"; + $full_text = "$line: "; - diag "paragraph $p"; + my %usage; - my %usage; + my @words = split(/\s+/,lc($_)); - my @words = split(/\s+/,lc($text)); + foreach (@words) { + $usage{$_}++; + } - foreach (@words) { - $usage{$_}++; - } + foreach my $word (@words) { - foreach my $word (@words) { + next if ($word eq ''); - $words{$word} += $usage{$word}; + $words{$word} += $usage{$word}; - $res->{$word}->{$p} = $usage{$word}; + $res->{$word}->{$line} = $usage{$word}; - $t->B_search( - Key => $word, - Data => { "$p" => { - t => "Ulyss paragraph $p", - f => $usage{$word}, - }, + $t->B_search( + Key => $word, + Data => { "$line" => { + t => "Odyssey line $line", + f => $usage{$word}, }, - Insert => 1, - Append => 1, - ); - - $word_count++; - - $full_text .= "$word "; + }, + Insert => 1, + Append => 1, + ); - last if ($max_words && $word_count >= $max_words); - } + $word_count++; - $text = ''; + $full_text .= "$word "; - last if ($max_words && $word_count >= $max_words); - } else { - $text .= $_; } + $full_text = "\n"; + + last if ($max_words && $word_count >= $max_words); } my $test_data = Dumper($res); @@ -106,3 +100,5 @@ my $total_words = scalar keys %words; cmp_ok($t->to_jsfind("./html/homer"), '==', $total_words, " jsfind index with $total_words words"); + +print Dumper($t);