7 |
use blib; |
use blib; |
8 |
use jsFind; |
use jsFind; |
9 |
|
|
10 |
my $dict = '/usr/share/dict/words'; |
my $dict; |
11 |
|
|
12 |
if (! -r $dict) { |
BEGIN { |
13 |
plan skip_all => "no $dict"; |
$dict = '/usr/share/dict/words'; |
|
} else { |
|
|
plan tests => 1; |
|
|
} |
|
14 |
|
|
15 |
BEGIN { use_ok('jsFind'); } |
if (! -r $dict) { |
16 |
|
plan skip_all => "no $dict"; |
17 |
|
} else { |
18 |
|
plan tests => 2; |
19 |
|
} |
20 |
|
|
21 |
|
use_ok('jsFind'); |
22 |
|
} |
23 |
|
|
24 |
my $t = new jsFind B => 20; |
my $t = new jsFind B => 20; |
25 |
|
|
26 |
my $max = 10000; |
my $max = 10000; |
27 |
|
|
28 |
if (-r $dict) { |
if (-r $dict) { |
29 |
print STDERR " making B-Tree from $max words in $dict\n"; |
diag "making B-Tree from $max words in $dict"; |
30 |
|
|
31 |
open(D, "$dict") || die "can't open '$dict': $!"; |
open(D, "$dict") || die "can't open '$dict': $!"; |
32 |
|
|
35 |
while (<D>) { |
while (<D>) { |
36 |
chomp; |
chomp; |
37 |
|
|
38 |
|
next unless (/^\w+$/); |
39 |
|
|
40 |
$t->B_search(Key => $_, |
$t->B_search(Key => $_, |
41 |
Data => { |
Data => { |
42 |
"$dict" => { |
"$dict" => { |
48 |
Append => 1, |
Append => 1, |
49 |
); |
); |
50 |
$i++; |
$i++; |
51 |
last if ($i > $max); |
last if ($i >= $max); |
52 |
} |
} |
53 |
|
|
54 |
close(D); |
close(D); |
57 |
print T $t->to_string; |
print T $t->to_string; |
58 |
close(T); |
close(T); |
59 |
} |
} |
60 |
print STDERR " words.txt created\n"; |
diag "words.txt created"; |
61 |
|
|
62 |
if (open(T,"> words.dot")) { |
if (open(T,"> words.dot")) { |
63 |
print T $t->to_dot; |
print T $t->to_dot; |
64 |
close(T); |
close(T); |
65 |
} |
} |
66 |
print STDERR " words.dot created\n"; |
diag "words.dot created"; |
67 |
|
|
68 |
cmp_ok($t->to_jsfind("./html/words"), '==', $max, " jsfind index"); |
cmp_ok($t->to_jsfind(dir=>"./html/words"), '==', $max, " jsfind index"); |
69 |
} |
} |
70 |
|
|
71 |
|
|