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/substrings.t | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 t/substrings.t (limited to 't/substrings.t') diff --git a/t/substrings.t b/t/substrings.t new file mode 100644 index 0000000..c4f478b --- /dev/null +++ b/t/substrings.t @@ -0,0 +1,43 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +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 %isnt_substring_tests = ( + "" => ["a"], + "abc" => ["z", "ba", "baz", "abz"], + "aaba" => ["c", "abaa"], +); +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"], +); + +for my $word (keys %is_substring_tests) { + ok(is_substring($_, $word), "is '$_' a substring of '$word'?") + for @{ $is_substring_tests{$word} }; +} +for my $word (keys %isnt_substring_tests) { + ok(!is_substring($_, $word), "is '$_' not a substring of '$word'?") + for @{ $isnt_substring_tests{$word} }; +} +for my $word (keys %all_substrings_tests) { + is_deeply( + [sort(all_substrings($word))], + [sort(@{ $all_substrings_tests{$word} })], + "do we get all of the substrings of '$word'?" + ); +} + +done_testing; -- cgit v1.2.3-54-g00ecf