Skip to content

Commit 6a3294e

Browse files
authored
Update kindergarten-garden tests (#584)
1 parent 0492f69 commit 6a3294e

File tree

4 files changed

+151
-53
lines changed

4 files changed

+151
-53
lines changed

exercises/practice/kindergarten-garden/.meta/example.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ end
2727
return function(s)
2828
s = s:lower()
2929

30-
return setmetatable({}, {
31-
__index = function(_, student)
30+
return {
31+
plants = function(student)
3232
local result = {}
3333
plant_string_for_student(s, student:lower()):gsub('.', function(c)
3434
table.insert(result, plant_abbreviations[c])
3535
end)
3636
return result
3737
end
38-
})
38+
}
3939
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
local function map(t, f)
2+
local mapped = {}
3+
for i, v in ipairs(t) do
4+
mapped[i] = f(v)
5+
end
6+
return mapped
7+
end
8+
9+
return {
10+
module_name = 'Garden',
11+
12+
generate_test = function(case)
13+
local diagram = case.input.diagram:gsub('\n', '\\n')
14+
local expected = table.concat(map(case.expected, function(x)
15+
return ("'%s'"):format(x)
16+
end), ', ')
17+
18+
local template = [[
19+
local garden = Garden('%s')
20+
assert.same({ %s }, garden.%s('%s'))]]
21+
return template:format(diagram, expected, case.property, case.input.student)
22+
end
23+
}
Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,61 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

512
[1fc316ed-17ab-4fba-88ef-3ae78296b692]
6-
description = "garden with single student"
13+
description = "partial garden -> garden with single student"
714

815
[acd19dc1-2200-4317-bc2a-08f021276b40]
9-
description = "different garden with single student"
16+
description = "partial garden -> different garden with single student"
1017

1118
[c376fcc8-349c-446c-94b0-903947315757]
12-
description = "garden with two students"
19+
description = "partial garden -> garden with two students"
1320

1421
[2d620f45-9617-4924-9d27-751c80d17db9]
15-
description = "second student's garden"
22+
description = "partial garden -> multiple students for the same garden with three students -> second student's garden"
1623

1724
[57712331-4896-4364-89f8-576421d69c44]
18-
description = "third student's garden"
25+
description = "partial garden -> multiple students for the same garden with three students -> third student's garden"
1926

2027
[149b4290-58e1-40f2-8ae4-8b87c46e765b]
21-
description = "first student's garden"
28+
description = "full garden -> for Alice, first student's garden"
2229

2330
[ba25dbbc-10bd-4a37-b18e-f89ecd098a5e]
24-
description = "second student's garden"
31+
description = "full garden -> for Bob, second student's garden"
32+
33+
[566b621b-f18e-4c5f-873e-be30544b838c]
34+
description = "full garden -> for Charlie"
35+
36+
[3ad3df57-dd98-46fc-9269-1877abf612aa]
37+
description = "full garden -> for David"
38+
39+
[0f0a55d1-9710-46ed-a0eb-399ba8c72db2]
40+
description = "full garden -> for Eve"
41+
42+
[a7e80c90-b140-4ea1-aee3-f4625365c9a4]
43+
description = "full garden -> for Fred"
44+
45+
[9d94b273-2933-471b-86e8-dba68694c615]
46+
description = "full garden -> for Ginny"
47+
48+
[f55bc6c2-ade8-4844-87c4-87196f1b7258]
49+
description = "full garden -> for Harriet"
50+
51+
[759070a3-1bb1-4dd4-be2c-7cce1d7679ae]
52+
description = "full garden -> for Ileana"
53+
54+
[78578123-2755-4d4a-9c7d-e985b8dda1c6]
55+
description = "full garden -> for Joseph"
2556

2657
[6bb66df7-f433-41ab-aec2-3ead6e99f65b]
27-
description = "second to last student's garden"
58+
description = "full garden -> for Kincaid, second to last student's garden"
2859

2960
[d7edec11-6488-418a-94e6-ed509e0fa7eb]
30-
description = "last student's garden"
61+
description = "full garden -> for Larry, last student's garden"
Lines changed: 82 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,94 @@
11
local Garden = require('kindergarten-garden')
22

33
describe('kindergarten-garden', function()
4-
it('should be able to parse a garden with only one student', function()
5-
local garden = Garden('RC\nGG')
6-
assert.same({ 'radishes', 'clover', 'grass', 'grass' }, garden.alice)
7-
end)
4+
describe('partial garden', function()
5+
it('garden with single student', function()
6+
local garden = Garden('RC\nGG')
7+
assert.same({ 'radishes', 'clover', 'grass', 'grass' }, garden.plants('Alice'))
8+
end)
89

9-
it('should be able to parse a graden with more than one student', function()
10-
local garden = Garden('VVCG\nVVRC')
11-
assert.same({ 'violets', 'violets', 'violets', 'violets' }, garden.alice)
12-
assert.same({ 'clover', 'grass', 'radishes', 'clover' }, garden.bob)
13-
end)
10+
it('different garden with single student', function()
11+
local garden = Garden('VC\nRC')
12+
assert.same({ 'violets', 'clover', 'radishes', 'clover' }, garden.plants('Alice'))
13+
end)
1414

15-
it('should be able to parse a garden with plants for all students', function()
16-
local garden = Garden('VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV')
17-
assert.same({ 'violets', 'radishes', 'violets', 'radishes' }, garden.alice)
18-
assert.same({ 'clover', 'grass', 'clover', 'clover' }, garden.bob)
19-
assert.same({ 'violets', 'violets', 'clover', 'grass' }, garden.charlie)
20-
assert.same({ 'radishes', 'violets', 'clover', 'radishes' }, garden.david)
21-
assert.same({ 'clover', 'grass', 'radishes', 'grass' }, garden.eve)
22-
assert.same({ 'grass', 'clover', 'violets', 'clover' }, garden.fred)
23-
assert.same({ 'clover', 'grass', 'grass', 'clover' }, garden.ginny)
24-
assert.same({ 'violets', 'radishes', 'radishes', 'violets' }, garden.harriet)
25-
assert.same({ 'grass', 'clover', 'violets', 'clover' }, garden.ileana)
26-
assert.same({ 'violets', 'clover', 'violets', 'grass' }, garden.joseph)
27-
assert.same({ 'grass', 'clover', 'clover', 'grass' }, garden.kincaid)
28-
assert.same({ 'grass', 'violets', 'clover', 'violets' }, garden.larry)
29-
end)
15+
it('garden with two students', function()
16+
local garden = Garden('VVCG\nVVRC')
17+
assert.same({ 'clover', 'grass', 'radishes', 'clover' }, garden.plants('Bob'))
18+
end)
3019

31-
it('should return an empty result for students that are not present', function()
32-
local garden = Garden('RC\nGG')
33-
assert.same({}, garden.bob)
34-
end)
20+
describe('multiple students for the same garden with three students', function()
21+
it('second student\'s garden', function()
22+
local garden = Garden('VVCCGG\nVVCCGG')
23+
assert.same({ 'clover', 'clover', 'clover', 'clover' }, garden.plants('Bob'))
24+
end)
3525

36-
it('should return an empty result for students that do not exist', function()
37-
local garden = Garden('RC\nGG')
38-
assert.same({}, garden.katrina)
26+
it('third student\'s garden', function()
27+
local garden = Garden('VVCCGG\nVVCCGG')
28+
assert.same({ 'grass', 'grass', 'grass', 'grass' }, garden.plants('Charlie'))
29+
end)
30+
end)
3931
end)
4032

41-
it('should ignore case for gardens', function()
42-
local garden = Garden('Rc\ngG')
43-
assert.same({ 'radishes', 'clover', 'grass', 'grass' }, garden.alice)
44-
end)
33+
describe('full garden', function()
34+
it('for alice, first student\'s garden', function()
35+
local garden = Garden('VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV')
36+
assert.same({ 'violets', 'radishes', 'violets', 'radishes' }, garden.plants('Alice'))
37+
end)
38+
39+
it('for bob, second student\'s garden', function()
40+
local garden = Garden('VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV')
41+
assert.same({ 'clover', 'grass', 'clover', 'clover' }, garden.plants('Bob'))
42+
end)
43+
44+
it('for charlie', function()
45+
local garden = Garden('VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV')
46+
assert.same({ 'violets', 'violets', 'clover', 'grass' }, garden.plants('Charlie'))
47+
end)
48+
49+
it('for david', function()
50+
local garden = Garden('VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV')
51+
assert.same({ 'radishes', 'violets', 'clover', 'radishes' }, garden.plants('David'))
52+
end)
53+
54+
it('for eve', function()
55+
local garden = Garden('VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV')
56+
assert.same({ 'clover', 'grass', 'radishes', 'grass' }, garden.plants('Eve'))
57+
end)
58+
59+
it('for fred', function()
60+
local garden = Garden('VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV')
61+
assert.same({ 'grass', 'clover', 'violets', 'clover' }, garden.plants('Fred'))
62+
end)
63+
64+
it('for ginny', function()
65+
local garden = Garden('VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV')
66+
assert.same({ 'clover', 'grass', 'grass', 'clover' }, garden.plants('Ginny'))
67+
end)
68+
69+
it('for harriet', function()
70+
local garden = Garden('VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV')
71+
assert.same({ 'violets', 'radishes', 'radishes', 'violets' }, garden.plants('Harriet'))
72+
end)
73+
74+
it('for ileana', function()
75+
local garden = Garden('VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV')
76+
assert.same({ 'grass', 'clover', 'violets', 'clover' }, garden.plants('Ileana'))
77+
end)
78+
79+
it('for joseph', function()
80+
local garden = Garden('VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV')
81+
assert.same({ 'violets', 'clover', 'violets', 'grass' }, garden.plants('Joseph'))
82+
end)
83+
84+
it('for kincaid, second to last student\'s garden', function()
85+
local garden = Garden('VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV')
86+
assert.same({ 'grass', 'clover', 'clover', 'grass' }, garden.plants('Kincaid'))
87+
end)
4588

46-
it('should ignore case for students', function()
47-
local garden = Garden('RC\nGG')
48-
assert.same({ 'radishes', 'clover', 'grass', 'grass' }, garden.ALICE)
89+
it('for larry, last student\'s garden', function()
90+
local garden = Garden('VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV')
91+
assert.same({ 'grass', 'violets', 'clover', 'violets' }, garden.plants('Larry'))
92+
end)
4993
end)
5094
end)

0 commit comments

Comments
 (0)