From 7b6e6c87bf10203dabaf007ad155fd29fd550989 Mon Sep 17 00:00:00 2001 From: jluehrs2 Date: Thu, 31 Jan 2008 03:50:50 -0500 Subject: add tests for random_permutation and is_permutation --- t/010-random-permutation.t | 25 +++++++++++++++++++++++++ t/011-is-permutation.t | 18 ++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 t/010-random-permutation.t create mode 100644 t/011-is-permutation.t (limited to 't') diff --git a/t/010-random-permutation.t b/t/010-random-permutation.t new file mode 100644 index 0000000..0420492 --- /dev/null +++ b/t/010-random-permutation.t @@ -0,0 +1,25 @@ +#!perl -T +use strict; +use warnings; +use Test::More; +use List::Util 'sum'; +use Games::Word qw/random_permutation/; + +my %blah_permutations = ( + 0 => "blah", 1 => "blha", 2 => "balh", 3 => "bahl", + 4 => "bhla", 5 => "bhal", 6 => "lbah", 7 => "lbha", + 8 => "labh", 9 => "lahb", 10 => "lhba", 11 => "lhab", + 12 => "ablh", 13 => "abhl", 14 => "albh", 15 => "alhb", + 16 => "ahbl", 17 => "ahlb", 18 => "hbla", 19 => "hbal", + 20 => "hlba", 21 => "hlab", 22 => "habl", 23 => "halb", +); +plan tests => 1 + (scalar keys %blah_permutations) + 2; + +is(random_permutation(""), "", "testing permutation of empty string"); +while (my ($k, $v) = each %blah_permutations) { + is(random_permutation("blah", $k), $v, "testing random_permutation of 'blah'"); +} +eval { random_permutation("blah", 24) }; +like($@, qr/^invalid permutation index/, "testing permutation index bounds"); +eval { random_permutation("blah", -1) }; +like($@, qr/^invalid permutation index/, "testing permutation index bounds"); diff --git a/t/011-is-permutation.t b/t/011-is-permutation.t new file mode 100644 index 0000000..96e959a --- /dev/null +++ b/t/011-is-permutation.t @@ -0,0 +1,18 @@ +#!perl -T +use strict; +use warnings; +use Test::More tests => 20; +use Games::Word qw/random_permutation is_permutation/; + +ok( is_permutation("", ""), "testing empty string"); +ok( is_permutation("blah", "blah"), "testing same string"); +ok( is_permutation("blah", "alhb"), "testing permuted string"); +ok(!is_permutation("blah", "blh"), "testing word with letter deleted"); +ok(!is_permutation("blah", "blahs"), "testing word with letter added"); +ok(!is_permutation("blah", "blahh"), "testing word with repeated letter"); +ok( is_permutation("blaah", "hbala"), "testing word with duplicate letters"); +ok(!is_permutation("blaah", "bblah"), "more duplicate letter tests"); + +for (1..12) { + ok(is_permutation("blah", random_permutation("blah")), "random tests"); +} -- cgit v1.2.3-54-g00ecf