summaryrefslogtreecommitdiffstats
path: root/t/012-shared-letters.t
blob: 773f0b5c1aa5608ec7f6d36a54d242244f7fa753 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!perl -T
use strict;
use warnings;
use Test::More;
use Games::Word qw/shared_letters shared_letters_by_position/;

my @tests = (
    {a => "abcde", b => "edcba", sl => 5, slbp => 1},
    {a => "",      b => "",      sl => 0, slbp => 0},
    {a => "",      b => "abcde", sl => 0, slbp => 0},
    {a => "aaa",   b => "aa",    sl => 2, slbp => 2},
    {a => "abc",   b => "abcde", sl => 3, slbp => 3},
    {a => "cde",   b => "abcde", sl => 3, slbp => 0},
    {a => "abcba", b => "aabbc", sl => 5, slbp => 2},
    {a => "abcde", b => "cdefg", sl => 3, slbp => 0},
    {a => "bacaa", b => "gabca", sl => 4, slbp => 2},
);
plan tests => 2 * @tests;

for (@tests) {
    my %test = %$_;
    is(shared_letters($test{a}, $test{b}), $test{sl},
       "testing shared_letters");
    is(shared_letters_by_position($test{a}, $test{b}), $test{slbp},
       "testing shared_letters_by_position");
}