/[jsFind]/trunk/t/10homer.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/t/10homer.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 24 by dpavlin, Thu Oct 7 16:21:54 2004 UTC revision 25 by dpavlin, Thu Oct 7 17:30:03 2004 UTC
# Line 10  use Data::Dumper; Line 10  use Data::Dumper;
10    
11  BEGIN { use_ok('jsFind'); }  BEGIN { use_ok('jsFind'); }
12    
13  my $t = new jsFind B => 100;  my $t = new jsFind B => 10;
14    
15  ok(-e "t/homer.txt", "Homer: The Odyssey preface");  ok(-e "t/homer.txt", "Homer: The Odyssey preface");
16    
17  my $p = 0;  my $line = 0;
18  my $text = '';  my $text = '';
19  my %words;  my %words;
20  my $word_count = 0;  my $word_count = 0;
21  my $max_words = 100;  my $max_words = 10;
22    
23  my $res;  my $res;
24    
# Line 27  my $full_text; Line 27  my $full_text;
27  ok(open(U, "t/homer.txt"), "open homer.txt");  ok(open(U, "t/homer.txt"), "open homer.txt");
28  while(<U>) {  while(<U>) {
29          chomp;          chomp;
30          if (/^\s*$/) {          $line++;
31                  $p++;          next if (/^\s*$/);
32    
33                  $full_text .= "\n" if ($full_text);          $full_text = "$line: ";
                 $full_text = "paragraph $p\n\n";  
34    
35                  diag "paragraph $p";          my %usage;
36    
37                  my %usage;          my @words = split(/\s+/,lc($_));
38    
39                  my @words = split(/\s+/,lc($text));          foreach (@words) {
40                    $usage{$_}++;
41            }
42    
43                  foreach (@words) {          foreach my $word (@words) {
                         $usage{$_}++;  
                 }  
44    
45                  foreach my $word (@words) {                  next if ($word eq '');
46    
47                          $words{$word} += $usage{$word};                  $words{$word} += $usage{$word};
48    
49                          $res->{$word}->{$p} = $usage{$word};                  $res->{$word}->{$line} = $usage{$word};
50    
51                          $t->B_search(                  $t->B_search(
52                                  Key => $word,                          Key => $word,
53                                  Data => { "$p" => {                          Data => { "$line" => {
54                                          t => "Ulyss paragraph $p",                                  t => "Odyssey line $line",
55                                          f => $usage{$word},                                  f => $usage{$word},
                                         },  
56                                  },                                  },
57                                  Insert => 1,                          },
58                                  Append => 1,                          Insert => 1,
59                          );                          Append => 1,
60                    );
                         $word_count++;  
   
                         $full_text .= "$word ";  
61    
62                          last if ($max_words && $word_count >= $max_words);                  $word_count++;
                 }  
63    
64                  $text = '';                  $full_text .= "$word ";
65    
                 last if ($max_words && $word_count >= $max_words);  
         } else {  
                 $text .= $_;  
66          }          }
67    
68            $full_text = "\n";
69    
70            last if ($max_words && $word_count >= $max_words);
71  }  }
72    
73  my $test_data = Dumper($res);  my $test_data = Dumper($res);
# Line 106  diag "homer_words.txt created"; Line 100  diag "homer_words.txt created";
100  my $total_words = scalar keys %words;  my $total_words = scalar keys %words;
101    
102  cmp_ok($t->to_jsfind("./html/homer"), '==', $total_words, " jsfind index with $total_words words");  cmp_ok($t->to_jsfind("./html/homer"), '==', $total_words, " jsfind index with $total_words words");
103    
104    print Dumper($t);

Legend:
Removed from v.24  
changed lines
  Added in v.25

  ViewVC Help
Powered by ViewVC 1.1.26