diff options
author | Jesse Luehrs <doy@tozt.net> | 2009-11-17 00:29:08 -0600 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2009-11-17 00:29:08 -0600 |
commit | beb5c4cccf9eff7885cbc0253f17a243cce54a4f (patch) | |
tree | e380ed9e7c3d7294b0d67bab15aba4980f42f1e8 | |
parent | 5c83076fed12c431a9345ba9feb41047966428c4 (diff) | |
download | games-word-beb5c4cccf9eff7885cbc0253f17a243cce54a4f.tar.gz games-word-beb5c4cccf9eff7885cbc0253f17a243cce54a4f.zip |
clean up a bunch of tests
-rw-r--r-- | t/000-load.t | 6 | ||||
-rw-r--r-- | t/001-basic.t | 11 | ||||
-rw-r--r-- | t/001-system-wordlist.t (renamed from t/002-system-wordlist.t) | 9 | ||||
-rw-r--r-- | t/002-array-wordlist.t (renamed from t/003-array-wordlist.t) | 7 | ||||
-rw-r--r-- | t/003-system-wordlist-nocache.t (renamed from t/004-system-wordlist-nocache.t) | 8 | ||||
-rw-r--r-- | t/012-shared-letters.t | 16 | ||||
-rw-r--r-- | t/013-random-string-from.t | 6 | ||||
-rw-r--r-- | t/022-random-word-nocache.t | 8 | ||||
-rw-r--r-- | t/023-is-word-nocache.t | 9 | ||||
-rw-r--r-- | t/024-anagrams.t | 1 | ||||
-rw-r--r-- | t/025-subwords.t | 2 |
11 files changed, 29 insertions, 54 deletions
diff --git a/t/000-load.t b/t/000-load.t index dfe613f..e23f727 100644 --- a/t/000-load.t +++ b/t/000-load.t @@ -3,6 +3,8 @@ use strict; use warnings; use Test::More tests => 2; -use_ok 'Games::Word'; -use_ok 'Games::Word::Wordlist'; +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/001-basic.t b/t/001-basic.t deleted file mode 100644 index e939d77..0000000 --- a/t/001-basic.t +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use Test::More tests => 2; -use Test::Exception; -use Games::Word::Wordlist; - -my $wl; -lives_ok { $wl = Games::Word::Wordlist->new([]) } - "creating a wordlist succeeds"; -isa_ok $wl, "Games::Word::Wordlist"; diff --git a/t/002-system-wordlist.t b/t/001-system-wordlist.t index 336d2d4..90f1a99 100644 --- a/t/002-system-wordlist.t +++ b/t/001-system-wordlist.t @@ -1,8 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 2; -use Test::Exception; +use Test::More tests => 1; use Games::Word::Wordlist; my $word_file = ''; @@ -10,11 +9,9 @@ $word_file = '/usr/dict/words' if -r '/usr/dict/words'; $word_file = '/usr/share/dict/words' if -r '/usr/share/dict/words'; SKIP: { - skip "Can't find a system word list", 2 if $word_file eq ''; + skip "Can't find a system word list", 1 if $word_file eq ''; - my $wl; - lives_ok { $wl = Games::Word::Wordlist->new($word_file) } - "opening a word list from a file doesn't die"; + my $wl = Games::Word::Wordlist->new($word_file); 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"); diff --git a/t/003-array-wordlist.t b/t/002-array-wordlist.t index b752080..4f235c0 100644 --- a/t/003-array-wordlist.t +++ b/t/002-array-wordlist.t @@ -1,14 +1,11 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 4; -use Test::Exception; +use Test::More tests => 3; use Games::Word::Wordlist; my @words = qw/foo bar baz/; -my $wl; -lives_ok { $wl = Games::Word::Wordlist->new(\@words) } - "creating a wordlist from an array succeeds"; +my $wl = Games::Word::Wordlist->new(\@words); is($wl->words, 3, "created the correct number of words in the word list"); $wl->add_words(['zab', 'rab', 'oof', 'foo']); is($wl->words, 6, "adding words results in the correct number of words"); diff --git a/t/004-system-wordlist-nocache.t b/t/003-system-wordlist-nocache.t index 368229c..d8c0066 100644 --- a/t/004-system-wordlist-nocache.t +++ b/t/003-system-wordlist-nocache.t @@ -1,7 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 4; +use Test::More tests => 3; use Test::Exception; use Games::Word::Wordlist; @@ -10,11 +10,9 @@ $word_file = '/usr/dict/words' if -r '/usr/dict/words'; $word_file = '/usr/share/dict/words' if -r '/usr/share/dict/words'; SKIP: { - skip "Can't find a system word list", 4 if $word_file eq ''; + skip "Can't find a system word list", 3 if $word_file eq ''; - my $wl; - lives_ok { $wl = Games::Word::Wordlist->new($word_file, cache => 0) } - "opening a word list from a file doesn't die"; + my $wl = Games::Word::Wordlist->new($word_file, cache => 0); 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"); diff --git a/t/012-shared-letters.t b/t/012-shared-letters.t index e9fb431..9e249c2 100644 --- a/t/012-shared-letters.t +++ b/t/012-shared-letters.t @@ -28,13 +28,11 @@ plan tests => 3 * @tests; for (@tests) { my %test = %$_; - 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($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}'"); + my ($a, $b) = ($test{a}, $test{b}); + is(shared_letters($a, $b), $test{sl}, + "testing shared_letters: '$a' vs '$b'"); + is(shared_letters_by_position($a, $b), $test{slbp}, + "testing shared_letters_by_position: '$a' vs '$b'"); + is_deeply([shared_letters_by_position($a, $b)], $test{slbp_full}, + "testing shared_letters_by_position (list): '$a' vs '$b'"); } diff --git a/t/013-random-string-from.t b/t/013-random-string-from.t index ef8bc61..78e907f 100644 --- a/t/013-random-string-from.t +++ b/t/013-random-string-from.t @@ -3,13 +3,13 @@ use strict; use warnings; use Test::More tests => 23; use Test::Deep; +use Test::Exception; use Games::Word qw/random_string_from/; is(random_string_from("", 0), "", "0 length random_string_from an empty string"); -eval { random_string_from("", 5) }; -like($@, qr/invalid letter list/, - "random_string_from an empty string"); +throws_ok { 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/; diff --git a/t/022-random-word-nocache.t b/t/022-random-word-nocache.t index 08ed1fc..d5c9c19 100644 --- a/t/022-random-word-nocache.t +++ b/t/022-random-word-nocache.t @@ -1,7 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 5; +use Test::More tests => 4; use Test::Exception; use Games::Word::Wordlist; @@ -10,7 +10,7 @@ $word_file = '/usr/dict/words' if -r '/usr/dict/words'; $word_file = '/usr/share/dict/words' if -r '/usr/share/dict/words'; SKIP: { - skip "Can't find a system word list", 5 if $word_file eq ''; + skip "Can't find a system word list", 4 if $word_file eq ''; my $wl = Games::Word::Wordlist->new($word_file, cache => 0); my $word = $wl->random_word; @@ -24,9 +24,7 @@ SKIP: { } ok($passed, "testing that the word is actually in the word list"); - lives_ok(sub { $word = $wl->random_word(4) }, - "random_word doesn't die when given a length"); - + $word = $wl->random_word(4); is(length $word, 4, "testing random_word with a given length"); is($wl->random_word(999), undef, diff --git a/t/023-is-word-nocache.t b/t/023-is-word-nocache.t index 8555fbd..3b51e15 100644 --- a/t/023-is-word-nocache.t +++ b/t/023-is-word-nocache.t @@ -1,7 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 21; +use Test::More tests => 11; use Test::Exception; use Games::Word::Wordlist; @@ -10,14 +10,11 @@ $word_file = '/usr/dict/words' if -r '/usr/dict/words'; $word_file = '/usr/share/dict/words' if -r '/usr/share/dict/words'; SKIP: { - skip "Can't find a system word list", 21 if $word_file eq ''; + skip "Can't find a system word list", 11 if $word_file eq ''; my $wl = Games::Word::Wordlist->new($word_file, cache => 0); - my $result; for (1..10) { - lives_ok(sub { $result = $wl->is_word($wl->random_word) }, - "testing calling is_word"); - ok($result, + ok($wl->is_word($wl->random_word), "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"); diff --git a/t/024-anagrams.t b/t/024-anagrams.t index d71e908..9de5ad0 100644 --- a/t/024-anagrams.t +++ b/t/024-anagrams.t @@ -2,7 +2,6 @@ use strict; use warnings; use Test::More tests => 1; -use Test::Exception; use Test::Deep; use Games::Word::Wordlist; diff --git a/t/025-subwords.t b/t/025-subwords.t index c484788..b117158 100644 --- a/t/025-subwords.t +++ b/t/025-subwords.t @@ -2,7 +2,6 @@ use strict; use warnings; use Test::More tests => 1; -use Test::Exception; use Test::Deep; use Games::Word::Wordlist; @@ -10,5 +9,6 @@ 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"); |