1
exercism fetch perl5 sublist

sublist.t

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
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env perl
use strict;
use warnings;

use Test::More tests => 17;
use FindBin;
my $dir;
BEGIN { $dir = $FindBin::Bin . '/' };
use lib $dir;

my $module = $ENV{EXERCISM} ? 'Example' : 'Sublist';
my $name = "check_lists";
my $sub = join('::', $module, $name);

use_ok($module) or BAIL_OUT("You need to create a module called $module.pm");

can_ok($module, $name) or BAIL_OUT("You need to implement the function '$name'");

my $f = \&{"${module}::$name"};


is( $f->([], []), "equal", "empty lists are equal" );
is( $f->([], [1,2,3]), "sublist", "empty list is subset of everything" );
is( $f->([1], []), "superlist", "non-empty list is always superset of empty set" );
is( $f->([0,1,2], [0,1,2]), "equal", "non-empty lists are equal" );
is( $f->([0..1000000], [1..1000001]), "unequal", "large list, small difference" );
is( $f->([1,2,5], [0,1,2,3,1,2,5,6]), "sublist", "false start" );
is( $f->([1,1,2], [0,1,1,1,2,1,2]), "sublist", "sublist with duplicates" );
is( $f->([0,1,2], [0,1,2,3,4,5]), "sublist", "sublist at start" );
is( $f->([2,3,4], [0,1,2,3,4,5]), "sublist", "sublist in middle" );
is( $f->([3,4,5], [0,1,2,3,4,5]), "sublist", "sublist at end" );
is( $f->([0,1,2,3,4,5], [0,1,2]), "superlist", "start of superlist" );
is( $f->([0,1,2,3,4,5], [2,3]), "superlist", "middle of superlist" );
is( $f->([0,1,2,3,4,5], [3,4,5]), "superlist", "end of superlist" );
is( $f->([(0..999)x100, 1000..1099], [900..1049]), "superlist", "large list" );
is( $f->([ grep { !($_ % 15) } 3..200 ], [ grep { !($_ % 3) } 3..200 ]), "unequal", "spread sublist" );