1
exercism fetch perl5 matrix

matrix.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
#!/usr/bin/env perl
use strict;
use warnings;

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

my $module = $ENV{EXERCISM} ? 'Example' : 'Matrix';

plan tests => 11;

ok -e "${dir}${module}.pm", "Missing $module.pm" or BAIL_OUT "You need to create the file: $module.pm";
eval "use $module";
ok !$@, "Cannot load $module" or BAIL_OUT "Cannot load $module. Does it compile? Does it end with 1;?";
can_ok $module, "new"     or BAIL_OUT "Missing package $module; or missing sub new()";
can_ok $module, "rows"    or BAIL_OUT "Missing package $module; or missing sub rows()";
can_ok $module, "columns" or BAIL_OUT "Missing package $module; or missing sub columns()";

is_deeply $module->new("1 2\n10 20")->rows(0), [1, 2], "extract a row";
is_deeply $module->new("9 7\n8 6")->rows(0), [9, 7], "extract another row";
is_deeply $module->new("9 8 7\n19 18 17")->rows(1), [19, 18, 17], "extract 2nd row";
is_deeply $module->new("1 4 9\n16 25 36")->rows(1), [16, 25, 36], "extract 2nd row";
is_deeply $module->new("1 2 3\n4 5 6\n7 8 9\n8 7 6")->columns(0), [1, 4, 7, 8], "extract a column";
is_deeply $module->new("89 1903 3\n18 3 1\n9 4 800")->columns(1), [1903, 3, 4], "extract another column";