From 80dc8e8aea183cd82d5575397795a0fd37c05f66 Mon Sep 17 00:00:00 2001 From: jluehrs2 Date: Sat, 2 Feb 2008 05:19:52 -0500 Subject: test substring functions --- t/014-substrings.t | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 t/014-substrings.t (limited to 't') 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'?"); +} -- cgit v1.2.3-54-g00ecf