summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjluehrs2 <jluehrs2@uiuc.edu>2008-02-02 05:41:40 -0500
committerjluehrs2 <jluehrs2@uiuc.edu>2008-02-02 05:41:40 -0500
commit7e1056629c29d99e75db4dd82b29c0eddb954a4d (patch)
treeadc0863737cc671fb8f936aeca3d7c546319f0ed
parenta62c47ae7885891b7778d26cb81dd25fe82973af (diff)
downloadgames-word-7e1056629c29d99e75db4dd82b29c0eddb954a4d.tar.gz
games-word-7e1056629c29d99e75db4dd82b29c0eddb954a4d.zip
test subpermutations
-rw-r--r--t/015-subpermutations.t34
1 files changed, 34 insertions, 0 deletions
diff --git a/t/015-subpermutations.t b/t/015-subpermutations.t
new file mode 100644
index 0000000..439f7f1
--- /dev/null
+++ b/t/015-subpermutations.t
@@ -0,0 +1,34 @@
+#!perl -T
+use strict;
+use warnings;
+use Test::More;
+use Test::Deep;
+use List::Util qw/sum/;
+use Games::Word qw/is_subpermutation all_subpermutations/;
+
+my %is_subpermutation_tests = (
+ "" => [""],
+ "abc", => ["", "abc", "ab", "ac", "cb", "bac", "ca"],
+ "aaba" => ["a", "aa", "aaa", "aab", "aba"],
+ "abcba" => ["aa", "bb", "c", "abc", "cba", "abba", "bbaac", "caa"],
+);
+my %all_subpermutations_tests = (
+ "" => [""],
+ "a" => ["", "a"],
+ "ab" => ["", "a", "b", "ab", "ba"],
+ "aab" => ["", "a", "a", "b", "aa", "ab", "ab", "ba", "ba", "aa",
+ "aab", "aab", "aba", "aba", "baa", "baa"],
+ "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) {
+ ok(is_subpermutation($_, $word), "is '$_' a subpermutation of '$word'?")
+ for @$subpermutations;
+}
+while (my ($word, $subpermutations) = each %all_subpermutations_tests) {
+ cmp_deeply([all_subpermutations($word)], bag(@$subpermutations),
+ "do we get all of the subpermutations of '$word'?");
+}