| 1 |
15 |
dpavlin |
#!/usr/bin/perl -w |
| 2 |
|
|
|
| 3 |
|
|
use strict; |
| 4 |
|
|
use blib; |
| 5 |
|
|
|
| 6 |
22 |
dpavlin |
use Test::More tests => 80; |
| 7 |
|
|
use Data::Dumper; |
| 8 |
15 |
dpavlin |
|
| 9 |
|
|
my @test_words=( 'cars', 'dogs' ); |
| 10 |
|
|
|
| 11 |
|
|
my $debug = shift @ARGV; |
| 12 |
|
|
|
| 13 |
|
|
BEGIN { use_ok( 'Lingua::Spelling::Alternative' ); } |
| 14 |
|
|
|
| 15 |
|
|
ok(my $a = new Lingua::Spelling::Alternative( DEBUG => $debug ), "new"); |
| 16 |
|
|
|
| 17 |
|
|
ok($a->load_affix('./data/default.aff'), "load_affix default.aff"); |
| 18 |
|
|
|
| 19 |
21 |
dpavlin |
my @out = qw( |
| 20 |
|
|
bat build cloudy convey create |
| 21 |
|
|
cross dirty disposed dog enter |
| 22 |
|
|
fall file fix gray hundred |
| 23 |
|
|
imply late multiply natural prevent |
| 24 |
|
|
quick skate small twenty weak |
| 25 |
|
|
); |
| 26 |
|
|
my @count = ( |
| 27 |
22 |
dpavlin |
15,16,15,15,15, |
| 28 |
|
|
17,15,18,15,18, |
| 29 |
|
|
15,15,15,15,18, |
| 30 |
|
|
16,15,16,15,15, |
| 31 |
|
|
15,15,15,15,15 |
| 32 |
21 |
dpavlin |
); |
| 33 |
22 |
dpavlin |
|
| 34 |
|
|
my %minimal_base = ( |
| 35 |
|
|
'cross' => 14, |
| 36 |
|
|
'dirty' => 15, |
| 37 |
|
|
'multiply' => 14, |
| 38 |
|
|
'file' => 7, |
| 39 |
|
|
'late' => 7, |
| 40 |
|
|
'ent' => 4, |
| 41 |
|
|
'natural' => 15, |
| 42 |
|
|
'hundr' => 1, |
| 43 |
|
|
'dispose' => 1, |
| 44 |
|
|
'imp' => 2, |
| 45 |
|
|
'convey' => 15, |
| 46 |
|
|
'hundre' => 1, |
| 47 |
|
|
'dispos' => 1, |
| 48 |
|
|
'multip' => 2, |
| 49 |
|
|
'hund' => 2, |
| 50 |
|
|
'weak' => 15, |
| 51 |
|
|
'fix' => 15, |
| 52 |
|
|
'ente' => 1, |
| 53 |
|
|
'skat' => 8, |
| 54 |
|
|
'cro' => 2, |
| 55 |
|
|
'enter' => 13, |
| 56 |
|
|
'gray' => 15, |
| 57 |
|
|
'twenty' => 15, |
| 58 |
|
|
'small' => 15, |
| 59 |
|
|
'buil' => 2, |
| 60 |
|
|
'dispo' => 2, |
| 61 |
|
|
'lat' => 8, |
| 62 |
|
|
'fil' => 8, |
| 63 |
|
|
'imply' => 14, |
| 64 |
|
|
'cloudy' => 15, |
| 65 |
|
|
'creat' => 8, |
| 66 |
|
|
'fall' => 15, |
| 67 |
|
|
'disposed' => 14, |
| 68 |
|
|
'create' => 7, |
| 69 |
|
|
'bat' => 15, |
| 70 |
|
|
'prevent' => 15, |
| 71 |
|
|
'build' => 14, |
| 72 |
|
|
'skate' => 7, |
| 73 |
|
|
'hundred' => 14, |
| 74 |
|
|
'dog' => 15, |
| 75 |
|
|
'cros' => 1, |
| 76 |
|
|
'quick' => 15 |
| 77 |
|
|
); |
| 78 |
|
|
|
| 79 |
|
|
my %minimal; |
| 80 |
|
|
|
| 81 |
19 |
dpavlin |
foreach my $w (@out) { |
| 82 |
|
|
my @alt = $a->alternatives($w); |
| 83 |
22 |
dpavlin |
diag "$w -> ".join(",",@alt) if ($debug); |
| 84 |
|
|
cmp_ok(($#alt+1), '==', shift @count, "$w => ".($#alt+1)." alternatives"); |
| 85 |
|
|
my @min = $a->minimal(@alt); |
| 86 |
|
|
diag "minimal: ".join(",",@min) if ($debug); |
| 87 |
|
|
foreach (@min) { |
| 88 |
|
|
$minimal{$_}++; |
| 89 |
|
|
} |
| 90 |
|
|
cmp_ok($#alt, '==', $#min, "minimal $w"); |
| 91 |
|
|
|
| 92 |
|
|
my $tmp = $a->minimal($w); |
| 93 |
|
|
unlike($tmp, qr/ARRAY/, "single minimal is scalar"); |
| 94 |
19 |
dpavlin |
} |
| 95 |
21 |
dpavlin |
|
| 96 |
22 |
dpavlin |
ok(eq_hash(\%minimal, \%minimal_base), "minimal results ok"); |
| 97 |
|
|
|
| 98 |
|
|
ok($a->clear, "clear"); |
| 99 |
|
|
|