summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjluehrs2 <jluehrs2@uiuc.edu>2008-02-02 05:19:52 -0500
committerjluehrs2 <jluehrs2@uiuc.edu>2008-02-02 05:19:52 -0500
commit80dc8e8aea183cd82d5575397795a0fd37c05f66 (patch)
tree44abb80082b63262505500b9b7cffea88c97c60e
parentc462ccb8de508c001004462f1a9e2be8e9dc74cd (diff)
downloadgames-word-80dc8e8aea183cd82d5575397795a0fd37c05f66.tar.gz
games-word-80dc8e8aea183cd82d5575397795a0fd37c05f66.zip
test substring functions
-rw-r--r--t/014-substrings.t32
1 files changed, 32 insertions, 0 deletions
diff --git a/t/014-substrings.t b/t/014-substrings.t
new file mode 100644
index 0000000..4069be2
--- /dev/null
+++ b/t/014-substrings.t
@@ -0,0 +1,32 @@
+#!perl -T
+use strict;
+use warnings;
+use Test::More;
+use Test::Deep;
+use List::Util qw/sum/;
+use Games::Word qw/is_substring all_substrings/;
+
+my %is_substring_tests = (
+ "" => [""],
+ "abc", => ["", "abc", "ab", "ac"],
+ "aaba" => ["a", "aa", "aaa", "aab", "aba"],
+ "abcba" => ["aa", "bb", "c", "abc", "cba", "abba"],
+);
+my %all_substrings_tests = (
+ "" => [''],
+ "a" => ['', "a"],
+ "ab" => ['', "a", "b", "ab"],
+ "aab" => ['', "a", "a", "b", "aa", "ab", "ab", "aab"],
+ "abc" => ['', "a", "b", "c", "ab", "ac", "bc", "abc"],
+);
+plan tests => (sum map { scalar @$_ } values %is_substring_tests) +
+ keys %all_substrings_tests;
+
+while (my ($word, $substrings) = each %is_substring_tests) {
+ ok(is_substring($_, $word), "is '$_' a substring of '$word'?")
+ for @$substrings;
+}
+while (my ($word, $substrings) = each %all_substrings_tests) {
+ cmp_deeply([all_substrings($word)], bag(@$substrings),
+ "do we get all of the substrings of '$word'?");
+}