1
exercism fetch perl5 kindergarten-garden

kindergarten.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env perl
use strict;
use warnings;

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

my $full_garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";

my @cases = (
    {
        garden   => "RC\nGG",
        student  => "alice",
        expected => [qw(radishes clover grass grass)],
        name     => "small garden"
    },
    {
        garden   => "VC\nRC",
        student  => "alice",
        expected => [qw(violets clover radishes clover)],
        name     => "small garden"
    },
    {
        garden   => "VVCG\nVVRC",
        student  => "bob",
        expected => [qw(clover grass radishes clover)],
        name     => "small garden"
    },
    {
        garden   => "VVCCGG\nVVCCGG",
        student  => "bob",
        expected => [qw(clover clover clover clover)],
        name     => "small garden"
    },
    {
        garden   => "VVCCGG\nVVCCGG",
        student  => "charlie",
        expected => [qw(grass grass grass grass)],
        name     => "small garden"
    },
    {
        garden   => $full_garden,
        student  => "alice",
        expected => [qw(violets radishes violets radishes)],
        name     => "full garden"
    },
    {
        garden   => $full_garden,
        student  => "bob",
        expected => [qw(clover grass clover clover)],
        name     => "full garden"
    },
    {
        garden   => $full_garden,
        student  => "charlie",
        expected => [qw(violets violets clover grass)],
        name     => "full garden"
    },
    {
        garden   => $full_garden,
        student  => "david",
        expected => [qw(radishes violets clover radishes)],
        name     => "full garden"
    },
    {
        garden   => $full_garden,
        student  => "eve",
        expected => [qw(clover grass radishes grass)],
        name     => "full garden"
    },
    {
        garden   => $full_garden,
        student  => "fred",
        expected => [qw(grass clover violets clover)],
        name     => "full garden"
    },
    {
        garden   => $full_garden,
        student  => "ginny",
        expected => [qw(clover grass grass clover)],
        name     => "full garden"
    },
    {
        garden   => $full_garden,
        student  => "harriet",
        expected => [qw(violets radishes radishes violets)],
        name     => "full garden"
    },
    {
        garden   => $full_garden,
        student  => "ileana",
        expected => [qw(grass clover violets clover)],
        name     => "full garden"
    },
    {
        garden   => $full_garden,
        student  => "joseph",
        expected => [qw(violets clover violets grass)],
        name     => "full garden"
    },
    {
        garden   => $full_garden,
        student  => "kincaid",
        expected => [qw(grass clover clover grass)],
        name     => "full garden"
    },
    {
        garden   => $full_garden,
        student  => "larry",
        expected => [qw(grass violets clover violets)],
        name     => "full garden"
    },
    {
        garden   => "VCRRGVRG\nRVGCCGCV",
        student  => "patricia",
        students => [qw(Samantha Patricia Xander Roger)],
        expected => [qw(violets clover radishes violets)],
        name     => "unsorted students"
    },
    {
        garden   => "VCRRGVRG\nRVGCCGCV",
        student  => "roger",
        students => [qw(Samantha Patricia Xander Roger)],
        expected => [qw(radishes radishes grass clover)],
        name     => "unsorted students"
    },
    {
        garden   => "VCRRGVRG\nRVGCCGCV",
        student  => "samantha",
        students => [qw(Samantha Patricia Xander Roger)],
        expected => [qw(grass violets clover grass)],
        name     => "unsorted students"
    },
    {
        garden   => "VCRRGVRG\nRVGCCGCV",
        student  => "xander",
        students => [qw(Samantha Patricia Xander Roger)],
        expected => [qw(radishes grass clover violets)],
        name     => "unsorted students"
    },
    {
        garden   => "VCRRGVRG\nRVGCCGCV",
        student  => "bob",
        students => [qw(Alice Bob Charlie Dan)],
        expected => [qw(radishes radishes grass clover)],
        name     => "same garden different students"
    },
    {
        garden   => "VCRRGVRG\nRVGCCGCV",
        student  => "bob",
        students => [qw(Bob Charlie Dan Erin)],
        expected => [qw(violets clover radishes violets)],
        name     => "same garden different students"
    },
    {
        garden   => "VCRRGVRG\nRVGCCGCV",
        student  => "charlie",
        students => [qw(Alice Bob Charlie Dan)],
        expected => [qw(grass violets clover grass)],
        name     => "same garden different students"
    },
    {
        garden   => "VCRRGVRG\nRVGCCGCV",
        student  => "charlie",
        students => [qw(Bob Charlie Dan Erin)],
        expected => [qw(radishes radishes grass clover)],
        name     => "same garden different students"
    },
);

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

plan tests => 3 + @cases;

ok -e "${dir}${module}.pm", "Missing $module.pm"
            or BAIL_OUT "You need to create 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()";

foreach my $c (@cases) {
    my $garden = do {
        if ($c->{students}) {
            $module->new($c->{garden}, $c->{students});
        } else {
            $module->new($c->{garden});
        }
    };
    my $student = $c->{student};

    no strict 'refs';
    is_deeply $garden->$student(), $c->{expected}, "$c->{name} : $c->{student}'s garden is [@{ $c->{expected} }]";
}