From 4074f2d6a9bcfb33f0da7933ac26c5df0d2f21f7 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 5 Jul 2012 10:15:42 -0500 Subject: modernize, cleanup, etc --- t/subpermutations.t | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 t/subpermutations.t (limited to 't/subpermutations.t') diff --git a/t/subpermutations.t b/t/subpermutations.t new file mode 100644 index 0000000..bf16ec3 --- /dev/null +++ b/t/subpermutations.t @@ -0,0 +1,36 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +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"], +); + +for my $word (keys %is_subpermutation_tests) { + ok(is_subpermutation($_, $word), "is '$_' a subpermutation of '$word'?") + for @{ $is_subpermutation_tests{$word} }; +} +for my $word (keys %all_subpermutations_tests) { + is_deeply( + [sort(all_subpermutations($word))], + [sort(@{ $all_subpermutations_tests{$word} })], + "do we get all of the subpermutations of '$word'?" + ); +} + +done_testing; -- cgit v1.2.3-54-g00ecf