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
9 changes: 9 additions & 0 deletions exercises/practice/leap/.meta/spec_generator.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
return {
module_name = 'is_leap_year',

generate_test = function(case)
local template = [[
assert.is_%s(is_leap_year(%d))]]
return template:format(case.expected, case.input.year)
end
}
10 changes: 5 additions & 5 deletions exercises/practice/leap/leap_spec.lua
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
local is_leap_year = require('leap')

describe('leap', function()
it('year not divisible by 4 is common year', function()
it('year not divisible by 4 in common year', function()
assert.is_false(is_leap_year(2015))
end)

it('year divisible by 2, not divisible by 4 is common year', function()
it('year divisible by 2, not divisible by 4 in common year', function()
assert.is_false(is_leap_year(1970))
end)

it('year divisible by 4, not divisible by 100 is leap year', function()
it('year divisible by 4, not divisible by 100 in leap year', function()
assert.is_true(is_leap_year(1996))
end)

it('year divisible by 4 and 5 is still a leap year', function()
assert.is_true(is_leap_year(1960))
end)

it('year divisible by 100, not divisible by 400 is common year', function()
it('year divisible by 100, not divisible by 400 in common year', function()
assert.is_false(is_leap_year(2100))
end)

Expand All @@ -33,7 +33,7 @@ describe('leap', function()
assert.is_true(is_leap_year(2400))
end)

it('year divisible by 200, not divisible by 400 is common year', function()
it('year divisible by 200, not divisible by 400 in common year', function()
assert.is_false(is_leap_year(1800))
end)
end)
9 changes: 9 additions & 0 deletions exercises/practice/raindrops/.meta/spec_generator.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
return {
module_name = 'raindrops',

generate_test = function(case)
local template = [[
assert.equal('%s', raindrops(%d))]]
return template:format(case.expected, case.input.number)
end
}
30 changes: 15 additions & 15 deletions exercises/practice/raindrops/raindrops_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,71 @@ describe('raindrops', function()
assert.equal('1', raindrops(1))
end)

it('the sound for 3 is Pling', function()
it('the sound for 3 is pling', function()
assert.equal('Pling', raindrops(3))
end)

it('the sound for 5 is Plang', function()
it('the sound for 5 is plang', function()
assert.equal('Plang', raindrops(5))
end)

it('the sound for 7 is Plong', function()
it('the sound for 7 is plong', function()
assert.equal('Plong', raindrops(7))
end)

it('the sound for 6 is Pling as it has a factor 3', function()
it('the sound for 6 is pling as it has a factor 3', function()
assert.equal('Pling', raindrops(6))
end)

it('2 to the power 3 does not make a raindrop sound as 3 is the exponent not the base', function()
assert.equal('8', raindrops(8))
end)

it('the sound for 9 is Pling as it has a factor 3', function()
it('the sound for 9 is pling as it has a factor 3', function()
assert.equal('Pling', raindrops(9))
end)

it('the sound for 10 is Plang as it has a factor 5', function()
it('the sound for 10 is plang as it has a factor 5', function()
assert.equal('Plang', raindrops(10))
end)

it('the sound for 14 is Plong as it has a factor 7', function()
it('the sound for 14 is plong as it has a factor of 7', function()
assert.equal('Plong', raindrops(14))
end)

it('the sound for 15 is PlingPlang as it has a factor 3 and 5', function()
it('the sound for 15 is plingplang as it has factors 3 and 5', function()
assert.equal('PlingPlang', raindrops(15))
end)

it('the sound for 21 is PlingPlong as it has factors 3 and 7', function()
it('the sound for 21 is plingplong as it has factors 3 and 7', function()
assert.equal('PlingPlong', raindrops(21))
end)

it('the sound for 25 is Plang as it has a factor 5', function()
it('the sound for 25 is plang as it has a factor 5', function()
assert.equal('Plang', raindrops(25))
end)

it('the sound for 27 is Pling as it has a factor 3', function()
it('the sound for 27 is pling as it has a factor 3', function()
assert.equal('Pling', raindrops(27))
end)

it('the sound for 35 is PlangPlong as it has factors 5 and 7', function()
it('the sound for 35 is plangplong as it has factors 5 and 7', function()
assert.equal('PlangPlong', raindrops(35))
end)

it('the sound for 49 is Plong as it has a factor 7', function()
it('the sound for 49 is plong as it has a factor 7', function()
assert.equal('Plong', raindrops(49))
end)

it('the sound for 52 is 52', function()
assert.equal('52', raindrops(52))
end)

it('the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7', function()
it('the sound for 105 is plingplangplong as it has factors 3, 5 and 7', function()
assert.equal('PlingPlangPlong', raindrops(105))
end)

it('the sound for 3125 is Plang as it has a factor 5', function()
it('the sound for 3125 is plang as it has a factor 5', function()
assert.equal('Plang', raindrops(3125))
end)
end)
32 changes: 20 additions & 12 deletions exercises/practice/resistor-color/.meta/example.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
local value = {
black = 0,
brown = 1,
red = 2,
orange = 3,
yellow = 4,
green = 5,
blue = 6,
violet = 7,
grey = 8,
white = 9
local colors = {
'black', --
'brown', --
'red', --
'orange', --
'yellow', --
'green', --
'blue', --
'violet', --
'grey', --
'white'
}

return {
colors = function()
return colors
end,

color_code = function(color)
return value[color]
for i, v in ipairs(colors) do
if v == color then
return i - 1
end
end
end
}
29 changes: 29 additions & 0 deletions exercises/practice/resistor-color/.meta/spec_generator.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
local map = function(t, f)
local mapped = {}
for i, v in ipairs(t) do
mapped[i] = f(v)
end
return mapped
end

local function render_table(t)
return table.concat(map(t, function(element)
return "'" .. element .. "'"
end), ', --\n')
end

return {
module_name = 'rc',

generate_test = function(case)
if case.property == 'colors' then
local template = [[
assert.same({ %s }, rc.colors())]]
return template:format(render_table(case.expected))
else
local template = [[
assert.equal(%d, rc.color_code('%s'))]]
return template:format(case.expected, case.input.color)
end
end
}
1 change: 0 additions & 1 deletion exercises/practice/resistor-color/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ description = "Color codes -> Orange"

[581d68fa-f968-4be2-9f9d-880f2fb73cf7]
description = "Colors"
include = false
67 changes: 28 additions & 39 deletions exercises/practice/resistor-color/resistor-color_spec.lua
Original file line number Diff line number Diff line change
@@ -1,43 +1,32 @@
local rc = require 'resistor-color'
local rc = require('resistor-color')

describe('resistor-color', function()
it('Black', function()
assert.equal(0, rc.color_code('black'))
end)

it('Brown', function()
assert.equal(1, rc.color_code('brown'))
end)

it('Red', function()
assert.equal(2, rc.color_code('red'))
end)

it('Orange', function()
assert.equal(3, rc.color_code('orange'))
end)

it('Yellow', function()
assert.equal(4, rc.color_code('yellow'))
end)

it('Green', function()
assert.equal(5, rc.color_code('green'))
end)

it('Blue', function()
assert.equal(6, rc.color_code('blue'))
end)

it('Violet', function()
assert.equal(7, rc.color_code('violet'))
end)

it('Grey', function()
assert.equal(8, rc.color_code('grey'))
end)

it('White', function()
assert.equal(9, rc.color_code('white'))
describe('color codes', function()
it('black', function()
assert.equal(0, rc.color_code('black'))
end)

it('white', function()
assert.equal(9, rc.color_code('white'))
end)

it('orange', function()
assert.equal(3, rc.color_code('orange'))
end)
end)

it('colors', function()
assert.same({
'black', --
'brown', --
'red', --
'orange', --
'yellow', --
'green', --
'blue', --
'violet', --
'grey', --
'white'
}, rc.colors())
end)
end)
Loading