Test-driven development · 41 / 69
Protect the empty case
YOUR TASK
Make this happen
A useful test suite covers ordinary input and a boundary. Write tests for summing quantities, including the empty list. Then implement the function and refactor it while keeping tests green.
Write a test in
lesson.test.lua, then choose Check solution to record a failing test before changing the implementation.Repair
subject.luaand check again. Your tests must pass and catch the supplied defects. Then refactor.
Read the starter and tests
subject.lua
exports.sum = function(values: { number }): number
return 1
end
lesson.test.lua
local t = require("test")
local subject = require("cococo.subject")
-- Write a test that reveals the defect before editing subject.lua.