Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exercises/practice/flower-field/.meta/spec_generator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end
local function render_garden(garden)
return table.concat(map(garden, function(row)
return "'" .. row .. "', --"
end), ',\n ')
end), '\n ')
end

return {
Expand Down
100 changes: 50 additions & 50 deletions exercises/practice/flower-field/flower-field_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,55 +19,55 @@ describe('flower-field', function()

it('no flowers', function()
local garden = {
' ', -- ,
' ', -- ,
' ', --
' ', --
' ' --
}
local expected = {
' ', -- ,
' ', -- ,
' ', --
' ', --
' ' --
}
assert.same(expected, flower_field.annotate(garden))
end)

it('garden full of flowers', function()
local garden = {
'***', -- ,
'***', -- ,
'***', --
'***', --
'***' --
}
local expected = {
'***', -- ,
'***', -- ,
'***', --
'***', --
'***' --
}
assert.same(expected, flower_field.annotate(garden))
end)

it('flower surrounded by spaces', function()
local garden = {
' ', -- ,
' * ', -- ,
' ', --
' * ', --
' ' --
}
local expected = {
'111', -- ,
'1*1', -- ,
'111', --
'1*1', --
'111' --
}
assert.same(expected, flower_field.annotate(garden))
end)

it('space surrounded by flowers', function()
local garden = {
'***', -- ,
'* *', -- ,
'***', --
'* *', --
'***' --
}
local expected = {
'***', -- ,
'*8*', -- ,
'***', --
'*8*', --
'***' --
}
assert.same(expected, flower_field.annotate(garden))
Expand Down Expand Up @@ -95,73 +95,73 @@ describe('flower-field', function()

it('vertical line', function()
local garden = {
' ', -- ,
'*', -- ,
' ', -- ,
'*', -- ,
' ', --
'*', --
' ', --
'*', --
' ' --
}
local expected = {
'1', -- ,
'*', -- ,
'2', -- ,
'*', -- ,
'1', --
'*', --
'2', --
'*', --
'1' --
}
assert.same(expected, flower_field.annotate(garden))
end)

it('vertical line, flowers at edges', function()
local garden = {
'*', -- ,
' ', -- ,
' ', -- ,
' ', -- ,
'*', --
' ', --
' ', --
' ', --
'*' --
}
local expected = {
'*', -- ,
'1', -- ,
' ', -- ,
'1', -- ,
'*', --
'1', --
' ', --
'1', --
'*' --
}
assert.same(expected, flower_field.annotate(garden))
end)

it('cross', function()
local garden = {
' * ', -- ,
' * ', -- ,
'*****', -- ,
' * ', -- ,
' * ', --
' * ', --
'*****', --
' * ', --
' * ' --
}
local expected = {
' 2*2 ', -- ,
'25*52', -- ,
'*****', -- ,
'25*52', -- ,
' 2*2 ', --
'25*52', --
'*****', --
'25*52', --
' 2*2 ' --
}
assert.same(expected, flower_field.annotate(garden))
end)

it('large garden', function()
local garden = {
' * * ', -- ,
' * ', -- ,
' * ', -- ,
' * *', -- ,
' * * ', -- ,
' * * ', --
' * ', --
' * ', --
' * *', --
' * * ', --
' ' --
}
local expected = {
'1*22*1', -- ,
'12*322', -- ,
' 123*2', -- ,
'112*4*', -- ,
'1*22*2', -- ,
'1*22*1', --
'12*322', --
' 123*2', --
'112*4*', --
'1*22*2', --
'111111' --
}
assert.same(expected, flower_field.annotate(garden))
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/rectangles/.meta/spec_generator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end
local function render_strings(strings)
return table.concat(map(strings, function(row)
return "'" .. row .. "', --"
end), ',\n ')
end), '\n ')
end

return {
Expand Down
78 changes: 39 additions & 39 deletions exercises/practice/rectangles/rectangles_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,105 +19,105 @@ describe('rectangles', function()

it('one rectangle', function()
assert.equal(1, rectangles.count({
'+-+', -- ,
'| |', -- ,
'+-+', --
'| |', --
'+-+' --
}))
end)

it('two rectangles without shared parts', function()
assert.equal(2, rectangles.count({
' +-+', -- ,
' | |', -- ,
'+-+-+', -- ,
'| | ', -- ,
' +-+', --
' | |', --
'+-+-+', --
'| | ', --
'+-+ ' --
}))
end)

it('five rectangles with shared parts', function()
assert.equal(5, rectangles.count({
' +-+', -- ,
' | |', -- ,
'+-+-+', -- ,
'| | |', -- ,
' +-+', --
' | |', --
'+-+-+', --
'| | |', --
'+-+-+' --
}))
end)

it('rectangle of height 1 is counted', function()
assert.equal(1, rectangles.count({
'+--+', -- ,
'+--+', --
'+--+' --
}))
end)

it('rectangle of width 1 is counted', function()
assert.equal(1, rectangles.count({
'++', -- ,
'||', -- ,
'++', --
'||', --
'++' --
}))
end)

it('1x1 square is counted', function()
assert.equal(1, rectangles.count({
'++', -- ,
'++', --
'++' --
}))
end)

it('only complete rectangles are counted', function()
assert.equal(1, rectangles.count({
' +-+', -- ,
' |', -- ,
'+-+-+', -- ,
'| | -', -- ,
' +-+', --
' |', --
'+-+-+', --
'| | -', --
'+-+-+' --
}))
end)

it('rectangles can be of different sizes', function()
assert.equal(3, rectangles.count({
'+------+----+', -- ,
'| | |', -- ,
'+---+--+ |', -- ,
'| | |', -- ,
'+------+----+', --
'| | |', --
'+---+--+ |', --
'| | |', --
'+---+-------+' --
}))
end)

it('corner is required for a rectangle to be complete', function()
assert.equal(2, rectangles.count({
'+------+----+', -- ,
'| | |', -- ,
'+------+ |', -- ,
'| | |', -- ,
'+------+----+', --
'| | |', --
'+------+ |', --
'| | |', --
'+---+-------+' --
}))
end)

it('large input with many rectangles', function()
assert.equal(60, rectangles.count({
'+---+--+----+', -- ,
'| +--+----+', -- ,
'+---+--+ |', -- ,
'| +--+----+', -- ,
'+---+--+--+-+', -- ,
'+---+--+--+-+', -- ,
'+------+ | |', -- ,
'+---+--+----+', --
'| +--+----+', --
'+---+--+ |', --
'| +--+----+', --
'+---+--+--+-+', --
'+---+--+--+-+', --
'+------+ | |', --
' +-+' --
}))
end)

it('rectangles must have four sides', function()
assert.equal(5, rectangles.count({
'+-+ +-+', -- ,
'| | | |', -- ,
'+-+-+-+', -- ,
' | | ', -- ,
'+-+-+-+', -- ,
'| | | |', -- ,
'+-+ +-+', --
'| | | |', --
'+-+-+-+', --
' | | ', --
'+-+-+-+', --
'| | | |', --
'+-+ +-+' --
}))
end)
Expand Down
Loading