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

Contents of /trunk/t/10ulyss.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 20 - (show annotations)
Mon Oct 4 19:51:05 2004 UTC (19 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 1353 byte(s)
start of tests for jsFind

1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 5;
7 use blib;
8 use jsFind;
9 use Data::Dumper;
10
11 BEGIN { use_ok('jsFind'); }
12
13 my $t = new jsFind B => 100;
14
15 ok(-e "t/ulyss12.txt", "The Project Gutenberg EBook of Ulysses, by James Joyce");
16
17 my $p = 0;
18 my $text = '';
19 my %words;
20 my $max = 1;
21
22 my $res;
23
24 ok(open(U, "t/ulyss12.txt"), "open ulyss12.txt");
25 while(<U>) {
26 chomp;
27 if (/^\s*$/) {
28 $p++;
29
30 diag "paragraph $p";
31
32 my %usage;
33 foreach (split(/\s+/,lc($text))) {
34 $usage{$_}++;
35 }
36
37 foreach my $word (keys %usage) {
38
39 $words{$word} += $usage{$word};
40
41 $res->{$word}->{$p} = $usage{$word};
42
43 $t->B_search(
44 Key => $word,
45 Data => { "$p" => {
46 t => "Ulyss paragraph $p",
47 f => $usage{$word},
48 },
49 },
50 Insert => 1,
51 Append => 1,
52 );
53 }
54
55 $text = '';
56
57 last if ($max && $max == $p);
58 } else {
59 $text .= $_;
60 }
61
62 }
63
64 my $test_data = Dumper($res);
65 $test_data =~ s/=>/:/gs;
66 $test_data =~ s/\$VAR1/var test_data/;
67 open(JS, "> html/test_data.js") || die "can't open test_data.js: $!";
68 print JS $test_data;
69 close(JS);
70
71 ok($test_data, "test_data saved");
72
73 #my $sum = 0;
74 #foreach my $w (keys %words) {
75 # print STDERR "$w: $words{$w}\n";
76 # $sum += $words{$w};
77 #}
78
79 my $total_words = scalar keys %words;
80
81 cmp_ok($t->to_jsfind("./html/ulyss"), '==', $total_words, " jsfind index with $total_words words");

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26