Test-driven development · 45 / 69
Cover a table of examples
YOUR TASK
Make this happen
t.each creates a named case for each row of data. Read the input/output table before implementing clamp: values below zero become zero, values above ten become ten, and the middle stays unchanged.
Read the cases in
lesson.test.lua, then choose Check solution to see what needs to change.Update
subject.luauntil every test passes. Keep the supplied tests unchanged.
Read the starter and tests
subject.lua
exports.clamp = function(n: number): number return n end
lesson.test.lua
local t = require("test")
local subject = require("cococo.subject")
t.each(
"clamp",
{ { -1, 0 }, { 0, 0 }, { 5, 5 }, { 10, 10 }, { 11, 10 } },
function(input, expected)
local s = subject.load()
t.expect(s.clamp(input)):eq(expected)
end
)