From 46a035455783962edcad336dc659465620908152 Mon Sep 17 00:00:00 2001 From: jluehrs2 Date: Sat, 2 Feb 2008 23:36:16 -0500 Subject: fix up tests based on Devel::Cover reports --- t/004-system-wordlist-nocache.t | 9 ++++++++- t/012-shared-letters.t | 38 ++++++++++++++++++++++++++------------ t/020-random-word.t | 6 +++++- t/023-is-word-nocache.t | 3 ++- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/t/004-system-wordlist-nocache.t b/t/004-system-wordlist-nocache.t index 3692411..7396d51 100644 --- a/t/004-system-wordlist-nocache.t +++ b/t/004-system-wordlist-nocache.t @@ -1,7 +1,7 @@ #!perl -T use strict; use warnings; -use Test::More tests => 2; +use Test::More tests => 4; use Test::Exception; use Games::Word::Wordlist; @@ -18,4 +18,11 @@ SKIP: { open my $fh, '<', $word_file or die "Couldn't open $word_file"; 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"; } diff --git a/t/012-shared-letters.t b/t/012-shared-letters.t index e35e9d6..f3160b1 100644 --- a/t/012-shared-letters.t +++ b/t/012-shared-letters.t @@ -5,22 +5,36 @@ use Test::More; use Games::Word qw/shared_letters shared_letters_by_position/; my @tests = ( - {a => "abcde", b => "edcba", sl => 5, slbp => 1}, - {a => "", b => "", sl => 0, slbp => 0}, - {a => "", b => "abcde", sl => 0, slbp => 0}, - {a => "aaa", b => "aa", sl => 2, slbp => 2}, - {a => "abc", b => "abcde", sl => 3, slbp => 3}, - {a => "cde", b => "abcde", sl => 3, slbp => 0}, - {a => "abcba", b => "aabbc", sl => 5, slbp => 2}, - {a => "abcde", b => "cdefg", sl => 3, slbp => 0}, - {a => "bacaa", b => "gabca", sl => 4, slbp => 2}, + {a => "abcde", b => "edcba", sl => 5, slbp => 1, + slbp_full => [undef, undef, 'c', undef, undef]}, + {a => "", b => "", sl => 0, slbp => 0, + slbp_full => []}, + {a => "", b => "abcde", sl => 0, slbp => 0, + slbp_full => [undef, undef, undef, undef, undef]}, + {a => "aaa", b => "aa", sl => 2, slbp => 2, + slbp_full => ['a', 'a', undef]}, + {a => "abc", b => "abcde", sl => 3, slbp => 3, + slbp_full => ['a', 'b', 'c', undef, undef]}, + {a => "cde", b => "abcde", sl => 3, slbp => 0, + slbp_full => [undef, undef, undef, undef, undef]}, + {a => "abcba", b => "aabbc", sl => 5, slbp => 2, + slbp_full => ['a', undef, undef, 'b', undef]}, + {a => "abcde", b => "cdefg", sl => 3, slbp => 0, + slbp_full => [undef, undef, undef, undef, undef]}, + {a => "bacaa", b => "gabca", sl => 4, slbp => 2, + slbp_full => [undef, 'a', undef, undef, 'a']}, ); -plan tests => 2 * @tests; +plan tests => 3 * @tests; for (@tests) { my %test = %$_; - is(shared_letters($test{a}, $test{b}), $test{sl}, + my $sl = shared_letters($test{a}, $test{b}); + my $slbp = shared_letters_by_position($test{a}, $test{b}); + my @slbp_full = shared_letters_by_position($test{a}, $test{b}); + is($sl, $test{sl}, "testing shared_letters: '$test{a}' vs '$test{b}'"); - is(shared_letters_by_position($test{a}, $test{b}), $test{slbp}, + is($slbp, $test{slbp}, "testing shared_letters_by_position: '$test{a}' vs '$test{b}'"); + is_deeply(\@slbp_full, $test{slbp_full}, + "testing shared_letters_by_position (list): '$test{a}' vs '$test{b}'"); } diff --git a/t/020-random-word.t b/t/020-random-word.t index ad2c830..71b1959 100644 --- a/t/020-random-word.t +++ b/t/020-random-word.t @@ -1,7 +1,7 @@ #!perl -T use strict; use warnings; -use Test::More tests => 5; +use Test::More tests => 6; use Games::Word::Wordlist; my $wl = Games::Word::Wordlist->new(['foo', 'bar', 'baz', 'quux']); @@ -20,3 +20,7 @@ like($word, qr/^(foo|bar|baz)$/, is($wl->random_word(5), undef, "random_word returns undef if no words are found"); + +my $wl2 = Games::Word::Wordlist->new([]); +is($wl2->random_word, undef, + "random word returns undef with an empty word list"); diff --git a/t/023-is-word-nocache.t b/t/023-is-word-nocache.t index b812d07..84fa972 100644 --- a/t/023-is-word-nocache.t +++ b/t/023-is-word-nocache.t @@ -1,7 +1,7 @@ #!perl -T use strict; use warnings; -use Test::More tests => 20; +use Test::More tests => 21; use Test::Exception; use Games::Word::Wordlist; @@ -20,4 +20,5 @@ SKIP: { ok($result, "checking to see if a random word from the word list is a word"); } + ok(!$wl->is_word("notaword"), "testing is_word with a non-word"); } -- cgit v1.2.3-54-g00ecf