diff options
author | Jesse Luehrs <doy@tozt.net> | 2012-07-05 10:15:42 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2012-07-05 10:27:29 -0500 |
commit | 4074f2d6a9bcfb33f0da7933ac26c5df0d2f21f7 (patch) | |
tree | 9d34241644d3d8babf199f362a9d2b7ee2180d75 /t | |
parent | a12e592c538f370277e787cd57d01d512e1ca835 (diff) | |
download | games-word-4074f2d6a9bcfb33f0da7933ac26c5df0d2f21f7.tar.gz games-word-4074f2d6a9bcfb33f0da7933ac26c5df0d2f21f7.zip |
modernize, cleanup, etc
Diffstat (limited to 't')
-rw-r--r-- | t/000-load.t | 10 | ||||
-rw-r--r-- | t/010-random-permutation.t | 15 | ||||
-rw-r--r-- | t/anagrams.t (renamed from t/024-anagrams.t) | 10 | ||||
-rw-r--r-- | t/array-wordlist.t (renamed from t/002-array-wordlist.t) | 5 | ||||
-rw-r--r-- | t/is-permutation.t (renamed from t/011-is-permutation.t) | 7 | ||||
-rw-r--r-- | t/is-word-nocache.t (renamed from t/023-is-word-nocache.t) | 6 | ||||
-rw-r--r-- | t/is-word.t (renamed from t/021-is-word.t) | 6 | ||||
-rw-r--r-- | t/random-permutation.t | 20 | ||||
-rw-r--r-- | t/random-string-from.t (renamed from t/013-random-string-from.t) | 16 | ||||
-rw-r--r-- | t/random-word-nocache.t (renamed from t/022-random-word-nocache.t) | 6 | ||||
-rw-r--r-- | t/random-word.t (renamed from t/020-random-word.t) | 5 | ||||
-rw-r--r-- | t/shared-letters.t (renamed from t/012-shared-letters.t) | 6 | ||||
-rw-r--r-- | t/subpermutations.t (renamed from t/015-subpermutations.t) | 22 | ||||
-rw-r--r-- | t/substrings.t (renamed from t/014-substrings.t) | 27 | ||||
-rw-r--r-- | t/subwords.t (renamed from t/025-subwords.t) | 10 | ||||
-rw-r--r-- | t/system-wordlist-nocache.t (renamed from t/003-system-wordlist-nocache.t) | 23 | ||||
-rw-r--r-- | t/system-wordlist.t (renamed from t/001-system-wordlist.t) | 5 |
17 files changed, 117 insertions, 82 deletions
diff --git a/t/000-load.t b/t/000-load.t deleted file mode 100644 index e23f727..0000000 --- a/t/000-load.t +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use Test::More tests => 2; - -my @modules = qw(Games::Word Games::Word::Wordlist); - -for my $module (@modules) { - use_ok $module or BAIL_OUT("couldn't use $module"); -} diff --git a/t/010-random-permutation.t b/t/010-random-permutation.t deleted file mode 100644 index 4adcda3..0000000 --- a/t/010-random-permutation.t +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use Test::More tests => 51; -use Test::Deep; -use Games::Word qw/random_permutation/; - -is(random_permutation(""), "", "testing permutation of empty string"); - -for my $word (qw/foo bar baz quux blah/) { - for (1..10) { - cmp_deeply([split //, random_permutation $word], bag(split //, $word), - "random tests"); - } -} diff --git a/t/024-anagrams.t b/t/anagrams.t index 9de5ad0..68b18d4 100644 --- a/t/024-anagrams.t +++ b/t/anagrams.t @@ -1,8 +1,8 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 1; -use Test::Deep; +use Test::More; + use Games::Word::Wordlist; my @words = qw/stop spot tops post posts stops spartan poster pot sop spa/; @@ -10,5 +10,7 @@ my @words = qw/stop spot tops post posts stops spartan poster pot sop spa/; my $wl = Games::Word::Wordlist->new(\@words); my @anagrams = $wl->anagrams("stop"); -cmp_deeply(\@anagrams, bag('stop', 'spot', 'tops', 'post'), - "anagrams returns the correct words"); +is_deeply([sort @anagrams], [qw(post spot stop tops)], + "anagrams returns the correct words"); + +done_testing; diff --git a/t/002-array-wordlist.t b/t/array-wordlist.t index 4f235c0..f949860 100644 --- a/t/002-array-wordlist.t +++ b/t/array-wordlist.t @@ -1,7 +1,8 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 3; +use Test::More; + use Games::Word::Wordlist; my @words = qw/foo bar baz/; @@ -11,3 +12,5 @@ $wl->add_words(['zab', 'rab', 'oof', 'foo']); is($wl->words, 6, "adding words results in the correct number of words"); $wl->remove_words(qw/rab foo quux/); is($wl->words, 4, "deleting words results in the correct number of words"); + +done_testing; diff --git a/t/011-is-permutation.t b/t/is-permutation.t index e6e1abe..378d992 100644 --- a/t/011-is-permutation.t +++ b/t/is-permutation.t @@ -1,8 +1,9 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 20; -use Games::Word qw/random_permutation is_permutation/; +use Test::More; + +use Games::Word qw(random_permutation is_permutation); ok( is_permutation("", ""), "testing empty string"); ok( is_permutation("blah", "blah"), "testing same string"); @@ -16,3 +17,5 @@ ok(!is_permutation("blaah", "bblah"), "more duplicate letter tests"); for (1..12) { ok(is_permutation("blah", random_permutation("blah")), "random tests"); } + +done_testing; diff --git a/t/023-is-word-nocache.t b/t/is-word-nocache.t index 3b51e15..7ca6939 100644 --- a/t/023-is-word-nocache.t +++ b/t/is-word-nocache.t @@ -1,8 +1,8 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 11; -use Test::Exception; +use Test::More; + use Games::Word::Wordlist; my $word_file = ''; @@ -19,3 +19,5 @@ SKIP: { } ok(!$wl->is_word("notaword"), "testing is_word with a non-word"); } + +done_testing; diff --git a/t/021-is-word.t b/t/is-word.t index 2c6045f..a7daff0 100644 --- a/t/021-is-word.t +++ b/t/is-word.t @@ -1,8 +1,8 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 10; -use Test::Exception; +use Test::More; + use Games::Word::Wordlist; my $wl = Games::Word::Wordlist->new(['foo', 'bar', 'baz']); @@ -10,3 +10,5 @@ for (1..10) { ok($wl->is_word($wl->random_word), "testing checking to see if a random word from the word list is a word"); } + +done_testing; diff --git a/t/random-permutation.t b/t/random-permutation.t new file mode 100644 index 0000000..ca9f004 --- /dev/null +++ b/t/random-permutation.t @@ -0,0 +1,20 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +use Games::Word qw(random_permutation); + +is(random_permutation(""), "", "testing permutation of empty string"); + +for my $word (qw/foo bar baz quux blah/) { + for (1..10) { + is_deeply( + [sort split //, random_permutation($word)], + [sort split //, $word], + "random tests" + ); + } +} + +done_testing; diff --git a/t/013-random-string-from.t b/t/random-string-from.t index 78e907f..b4abc89 100644 --- a/t/013-random-string-from.t +++ b/t/random-string-from.t @@ -1,15 +1,19 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 23; +use Test::More; use Test::Deep; -use Test::Exception; -use Games::Word qw/random_string_from/; +use Test::Fatal; + +use Games::Word qw(random_string_from); is(random_string_from("", 0), "", "0 length random_string_from an empty string"); -throws_ok { random_string_from("", 5) } qr/invalid letter list/, - "random_string_from an empty string"; +like( + exception { random_string_from("", 5) }, + qr/invalid letter list/, + "random_string_from an empty string" +); is(random_string_from("abcde", 0), "", "0 length random_string_from"); my @letters = qw/a b c d e/; @@ -20,3 +24,5 @@ for my $i (1..10) { $bag->add(@letters) for 1..$i; cmp_deeply([split(//, $str)], $bag, "random test of random_string_from"); } + +done_testing; diff --git a/t/022-random-word-nocache.t b/t/random-word-nocache.t index d5c9c19..0c7fb1d 100644 --- a/t/022-random-word-nocache.t +++ b/t/random-word-nocache.t @@ -1,8 +1,8 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 4; -use Test::Exception; +use Test::More; + use Games::Word::Wordlist; my $word_file = ''; @@ -30,3 +30,5 @@ SKIP: { is($wl->random_word(999), undef, "random_word returns undef if no words are found"); } + +done_testing; diff --git a/t/020-random-word.t b/t/random-word.t index b642c27..6c5801d 100644 --- a/t/020-random-word.t +++ b/t/random-word.t @@ -1,7 +1,8 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 6; +use Test::More; + use Games::Word::Wordlist; my $wl = Games::Word::Wordlist->new(['foo', 'bar', 'baz', 'quux']); @@ -24,3 +25,5 @@ is($wl->random_word(5), undef, my $wl2 = Games::Word::Wordlist->new([]); is($wl2->random_word, undef, "random word returns undef with an empty word list"); + +done_testing; diff --git a/t/012-shared-letters.t b/t/shared-letters.t index 9e249c2..238ed23 100644 --- a/t/012-shared-letters.t +++ b/t/shared-letters.t @@ -2,7 +2,8 @@ use strict; use warnings; use Test::More; -use Games::Word qw/shared_letters shared_letters_by_position/; + +use Games::Word qw(shared_letters shared_letters_by_position); my @tests = ( {a => "abcde", b => "edcba", sl => 5, slbp => 1, @@ -24,7 +25,6 @@ my @tests = ( {a => "bacaa", b => "gabca", sl => 4, slbp => 2, slbp_full => [undef, 'a', undef, undef, 'a']}, ); -plan tests => 3 * @tests; for (@tests) { my %test = %$_; @@ -36,3 +36,5 @@ for (@tests) { is_deeply([shared_letters_by_position($a, $b)], $test{slbp_full}, "testing shared_letters_by_position (list): '$a' vs '$b'"); } + +done_testing; diff --git a/t/015-subpermutations.t b/t/subpermutations.t index 36e57d8..bf16ec3 100644 --- a/t/015-subpermutations.t +++ b/t/subpermutations.t @@ -2,9 +2,8 @@ use strict; use warnings; use Test::More; -use Test::Deep; -use List::Util qw/sum/; -use Games::Word qw/is_subpermutation all_subpermutations/; + +use Games::Word qw(is_subpermutation all_subpermutations); my %is_subpermutation_tests = ( "" => [""], @@ -21,14 +20,17 @@ my %all_subpermutations_tests = ( "abc" => ["", "a", "b", "c", "ab", "ac", "bc", "ba", "ca", "cb", "abc", "acb", "bac", "bca", "cab", "cba"], ); -plan tests => (sum map { scalar @$_ } values %is_subpermutation_tests) + - keys %all_subpermutations_tests; -while (my ($word, $subpermutations) = each %is_subpermutation_tests) { +for my $word (keys %is_subpermutation_tests) { ok(is_subpermutation($_, $word), "is '$_' a subpermutation of '$word'?") - for @$subpermutations; + for @{ $is_subpermutation_tests{$word} }; } -while (my ($word, $subpermutations) = each %all_subpermutations_tests) { - cmp_deeply([all_subpermutations($word)], bag(@$subpermutations), - "do we get all of the subpermutations of '$word'?"); +for my $word (keys %all_subpermutations_tests) { + is_deeply( + [sort(all_subpermutations($word))], + [sort(@{ $all_subpermutations_tests{$word} })], + "do we get all of the subpermutations of '$word'?" + ); } + +done_testing; diff --git a/t/014-substrings.t b/t/substrings.t index e61d264..c4f478b 100644 --- a/t/014-substrings.t +++ b/t/substrings.t @@ -2,9 +2,8 @@ use strict; use warnings; use Test::More; -use Test::Deep; -use List::Util qw/sum/; -use Games::Word qw/is_substring all_substrings/; + +use Games::Word qw(is_substring all_substrings); my %is_substring_tests = ( "" => [""], @@ -24,19 +23,21 @@ my %all_substrings_tests = ( "aab" => ['', "a", "a", "b", "aa", "ab", "ab", "aab"], "abc" => ['', "a", "b", "c", "ab", "ac", "bc", "abc"], ); -plan tests => (sum map { scalar @$_ } values %is_substring_tests, - values %isnt_substring_tests) + - keys %all_substrings_tests; -while (my ($word, $substrings) = each %is_substring_tests) { +for my $word (keys %is_substring_tests) { ok(is_substring($_, $word), "is '$_' a substring of '$word'?") - for @$substrings; + for @{ $is_substring_tests{$word} }; } -while (my ($word, $substrings) = each %isnt_substring_tests) { +for my $word (keys %isnt_substring_tests) { ok(!is_substring($_, $word), "is '$_' not a substring of '$word'?") - for @$substrings; + for @{ $isnt_substring_tests{$word} }; } -while (my ($word, $substrings) = each %all_substrings_tests) { - cmp_deeply([all_substrings($word)], bag(@$substrings), - "do we get all of the substrings of '$word'?"); +for my $word (keys %all_substrings_tests) { + is_deeply( + [sort(all_substrings($word))], + [sort(@{ $all_substrings_tests{$word} })], + "do we get all of the substrings of '$word'?" + ); } + +done_testing; diff --git a/t/025-subwords.t b/t/subwords.t index b117158..30b39b2 100644 --- a/t/025-subwords.t +++ b/t/subwords.t @@ -1,8 +1,8 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 1; -use Test::Deep; +use Test::More; + use Games::Word::Wordlist; my @words = qw/stop spot tops post posts stops spartan poster pot sop spa/; @@ -10,5 +10,7 @@ my @words = qw/stop spot tops post posts stops spartan poster pot sop spa/; my $wl = Games::Word::Wordlist->new(\@words); my @subwords = $wl->subwords_of("stop"); -cmp_deeply(\@subwords, bag('stop', 'spot', 'tops', 'post', 'pot', 'sop'), - "subwords_of returns the correct words"); +is_deeply([sort @subwords], [qw(post pot sop spot stop tops)], + "subwords_of returns the correct words"); + +done_testing; diff --git a/t/003-system-wordlist-nocache.t b/t/system-wordlist-nocache.t index d8c0066..417a061 100644 --- a/t/003-system-wordlist-nocache.t +++ b/t/system-wordlist-nocache.t @@ -1,8 +1,9 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 3; -use Test::Exception; +use Test::More; +use Test::Fatal; + use Games::Word::Wordlist; my $word_file = ''; @@ -17,10 +18,16 @@ SKIP: { for (<$fh>) {} is($wl->words, $., "we read in the correct number of words"); - throws_ok { $wl->add_words([qw/foo bar baz/]) } - qr/Can't add words to a non-cached word list/, - "adding words dies"; - throws_ok { $wl->remove_words("word", "throw") } - qr/Can't remove words from a non-cached word list/, - "removing words dies"; + like( + exception { $wl->add_words([qw/foo bar baz/]) }, + qr/Can't add words to a non-cached word list/, + "adding words dies" + ); + like( + exception { $wl->remove_words("word", "throw") }, + qr/Can't remove words from a non-cached word list/, + "removing words dies" + ); } + +done_testing; diff --git a/t/001-system-wordlist.t b/t/system-wordlist.t index 90f1a99..b4bcdda 100644 --- a/t/001-system-wordlist.t +++ b/t/system-wordlist.t @@ -1,7 +1,8 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 1; +use Test::More; + use Games::Word::Wordlist; my $word_file = ''; @@ -16,3 +17,5 @@ SKIP: { for (<$fh>) {} is($wl->words, $., "we read in the correct number of words"); } + +done_testing; |