← Lua Academy

Test-driven development · 41 / 69

Protect the empty case

YOUR TASK

Make this happen

3 steps
  1. 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.

  2. Write a test in lesson.test.lua, then choose Check solution to record a failing test before changing the implementation.

  3. Repair subject.lua and 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.