#!/usr/bin/perl -w use strict; use blib; use Test::More tests => 80; use Data::Dumper; my @test_words=( 'cars', 'dogs' ); my $debug = shift @ARGV; BEGIN { use_ok( 'Lingua::Spelling::Alternative' ); } ok(my $a = new Lingua::Spelling::Alternative( DEBUG => $debug ), "new"); ok($a->load_affix('./data/default.aff'), "load_affix default.aff"); my @out = qw( bat build cloudy convey create cross dirty disposed dog enter fall file fix gray hundred imply late multiply natural prevent quick skate small twenty weak ); my @count = ( 15,16,15,15,15, 17,15,18,15,18, 15,15,15,15,18, 16,15,16,15,15, 15,15,15,15,15 ); my %minimal_base = ( 'cross' => 14, 'dirty' => 15, 'multiply' => 14, 'file' => 7, 'late' => 7, 'ent' => 4, 'natural' => 15, 'hundr' => 1, 'dispose' => 1, 'imp' => 2, 'convey' => 15, 'hundre' => 1, 'dispos' => 1, 'multip' => 2, 'hund' => 2, 'weak' => 15, 'fix' => 15, 'ente' => 1, 'skat' => 8, 'cro' => 2, 'enter' => 13, 'gray' => 15, 'twenty' => 15, 'small' => 15, 'buil' => 2, 'dispo' => 2, 'lat' => 8, 'fil' => 8, 'imply' => 14, 'cloudy' => 15, 'creat' => 8, 'fall' => 15, 'disposed' => 14, 'create' => 7, 'bat' => 15, 'prevent' => 15, 'build' => 14, 'skate' => 7, 'hundred' => 14, 'dog' => 15, 'cros' => 1, 'quick' => 15 ); my %minimal; foreach my $w (@out) { my @alt = $a->alternatives($w); diag "$w -> ".join(",",@alt) if ($debug); cmp_ok(($#alt+1), '==', shift @count, "$w => ".($#alt+1)." alternatives"); my @min = $a->minimal(@alt); diag "minimal: ".join(",",@min) if ($debug); foreach (@min) { $minimal{$_}++; } cmp_ok($#alt, '==', $#min, "minimal $w"); my $tmp = $a->minimal($w); unlike($tmp, qr/ARRAY/, "single minimal is scalar"); } ok(eq_hash(\%minimal, \%minimal_base), "minimal results ok"); ok($a->clear, "clear");