1 |
dpavlin |
1 |
#!/usr/bin/perl |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use warnings; |
5 |
|
|
|
6 |
|
|
use Test::More; |
7 |
|
|
use blib; |
8 |
|
|
use jsFind; |
9 |
|
|
|
10 |
|
|
my $dict = '/usr/share/dict/words'; |
11 |
|
|
|
12 |
|
|
if (! -r $dict) { |
13 |
|
|
plan skip_all => "no $dict"; |
14 |
|
|
} else { |
15 |
|
|
plan tests => 1; |
16 |
|
|
} |
17 |
|
|
|
18 |
|
|
BEGIN { use_ok('jsFind'); } |
19 |
|
|
|
20 |
|
|
my $t = new jsFind B => 6; |
21 |
|
|
|
22 |
|
|
my $max = 10000; |
23 |
|
|
|
24 |
|
|
if (-r $dict) { |
25 |
|
|
print STDERR " making B-Tree from $max words in $dict\n"; |
26 |
|
|
|
27 |
|
|
open(D, "$dict") || die "can't open '$dict': $!"; |
28 |
|
|
|
29 |
|
|
my $i = 0; |
30 |
|
|
|
31 |
|
|
while (<D>) { |
32 |
|
|
chomp; |
33 |
|
|
|
34 |
|
|
$t->B_search(Key => $_, |
35 |
|
|
Data => { |
36 |
dpavlin |
4 |
"$dict" => { |
37 |
dpavlin |
1 |
t => "word: $_", |
38 |
|
|
f => 1, |
39 |
|
|
} |
40 |
|
|
}, |
41 |
|
|
Insert => 1, |
42 |
|
|
Append => 1, |
43 |
|
|
); |
44 |
|
|
$i++; |
45 |
|
|
last if ($i > $max); |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
close(D); |
49 |
|
|
|
50 |
|
|
if (open(T,"> words.txt")) { |
51 |
|
|
print T $t->to_string; |
52 |
|
|
close(T); |
53 |
|
|
} |
54 |
|
|
print STDERR " words.txt created\n"; |
55 |
|
|
|
56 |
|
|
if (open(T,"> words.dot")) { |
57 |
|
|
print T $t->to_dot; |
58 |
|
|
close(T); |
59 |
|
|
} |
60 |
dpavlin |
4 |
print STDERR " words.dot created\n"; |
61 |
dpavlin |
1 |
|
62 |
dpavlin |
4 |
cmp_ok($t->to_jsfind("./html/words"), '==', $max, " jsfind index"); |
63 |
dpavlin |
1 |
} |
64 |
|
|
|
65 |
|
|
|