Test-driven development · 40 / 69
Test the boundary first
YOUR TASK
Make this happen
Write a test that exposes the faulty free-shipping boundary. Then repair the implementation. Your tests will also run against a correct implementation and a deliberately broken one; an always-passing test is not enough.
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.shipping = function(total: number): number
if total > 100 then
return 0
end
return 5
end
lesson.test.lua
local t = require("test")
local subject = require("cococo.subject")
-- Write a test that reveals the defect before editing subject.lua.