← Lua Academy

Thinking in Lua · 6 / 69

Choose a shipping band

YOUR TASK

Make this happen

3 steps
  1. Conditions choose between behaviours. A boundary deserves its own test: free shipping starts at exactly 100, not above it.

  2. Read the cases in lesson.test.lua, then choose Check solution to see what needs to change.

  3. Update subject.lua until 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)