Thinking in Lua · 6 / 69
Choose a shipping band
YOUR TASK
Make this happen
Conditions choose between behaviours. A boundary deserves its own test: free shipping starts at exactly 100, not above it.
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.shipping = function(total: number): number return 5 end
lesson.test.lua
local t = require("test")
local subject = require("cococo.subject")
t.it("small orders pay shipping", function()
local s = subject.load()
t.expect(s.shipping(99)):eq(5)
end)
t.it("the boundary is free", function()
local s = subject.load()
t.expect(s.shipping(100)):eq(0)
end)
t.it("larger orders are free", function()
local s = subject.load()
t.expect(s.shipping(200)):eq(0)
end)