From beb5c4cccf9eff7885cbc0253f17a243cce54a4f Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 17 Nov 2009 00:29:08 -0600 Subject: clean up a bunch of tests --- t/000-load.t | 6 ++++-- t/001-basic.t | 11 ----------- t/001-system-wordlist.t | 18 ++++++++++++++++++ t/002-array-wordlist.t | 13 +++++++++++++ t/002-system-wordlist.t | 21 --------------------- t/003-array-wordlist.t | 16 ---------------- t/003-system-wordlist-nocache.t | 26 ++++++++++++++++++++++++++ t/004-system-wordlist-nocache.t | 28 ---------------------------- t/012-shared-letters.t | 16 +++++++--------- t/013-random-string-from.t | 6 +++--- t/022-random-word-nocache.t | 8 +++----- t/023-is-word-nocache.t | 9 +++------ t/024-anagrams.t | 1 - t/025-subwords.t | 2 +- 14 files changed, 78 insertions(+), 103 deletions(-) delete mode 100644 t/001-basic.t create mode 100644 t/001-system-wordlist.t create mode 100644 t/002-array-wordlist.t delete mode 100644 t/002-system-wordlist.t delete mode 100644 t/003-array-wordlist.t create mode 100644 t/003-system-wordlist-nocache.t delete mode 100644 t/004-system-wordlist-nocache.t (limited to 't') 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/001-system-wordlist.t b/t/001-system-wordlist.t new file mode 100644 index 0000000..90f1a99 --- /dev/null +++ b/t/001-system-wordlist.t @@ -0,0 +1,18 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More tests => 1; +use Games::Word::Wordlist; + +my $word_file = ''; +$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", 1 if $word_file eq ''; + + 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/002-array-wordlist.t b/t/002-array-wordlist.t new file mode 100644 index 0000000..4f235c0 --- /dev/null +++ b/t/002-array-wordlist.t @@ -0,0 +1,13 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More tests => 3; +use Games::Word::Wordlist; + +my @words = qw/foo bar baz/; +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"); +$wl->remove_words(qw/rab foo quux/); +is($wl->words, 4, "deleting words results in the correct number of words"); diff --git a/t/002-system-wordlist.t b/t/002-system-wordlist.t deleted file mode 100644 index 336d2d4..0000000 --- a/t/002-system-wordlist.t +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use Test::More tests => 2; -use Test::Exception; -use Games::Word::Wordlist; - -my $word_file = ''; -$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 ''; - - my $wl; - lives_ok { $wl = Games::Word::Wordlist->new($word_file) } - "opening a word list from a file doesn't die"; - 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/003-array-wordlist.t deleted file mode 100644 index b752080..0000000 --- a/t/003-array-wordlist.t +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use Test::More tests => 4; -use Test::Exception; -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"; -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"); -$wl->remove_words(qw/rab foo quux/); -is($wl->words, 4, "deleting words results in the correct number of words"); diff --git a/t/003-system-wordlist-nocache.t b/t/003-system-wordlist-nocache.t new file mode 100644 index 0000000..d8c0066 --- /dev/null +++ b/t/003-system-wordlist-nocache.t @@ -0,0 +1,26 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More tests => 3; +use Test::Exception; +use Games::Word::Wordlist; + +my $word_file = ''; +$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", 3 if $word_file eq ''; + + 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"); + + 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/004-system-wordlist-nocache.t b/t/004-system-wordlist-nocache.t deleted file mode 100644 index 368229c..0000000 --- a/t/004-system-wordlist-nocache.t +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use Test::More tests => 4; -use Test::Exception; -use Games::Word::Wordlist; - -my $word_file = ''; -$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 ''; - - my $wl; - lives_ok { $wl = Games::Word::Wordlist->new($word_file, cache => 0) } - "opening a word list from a file doesn't die"; - 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 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"); -- cgit v1.2.3-54-g00ecf