← Lua Academy

Test-driven development · 43 / 69

Compare calculated decimals

YOUR TASK

Make this happen

3 steps
  1. Floating-point arithmetic can introduce tiny rounding differences. near expresses a deliberate numeric tolerance; it does not excuse a substantially wrong calculation.

  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.third = function(): number
  return 0.3
end

lesson.test.lua

local t = require("test")
local subject = require("cococo.subject")
t.it("one third", function()
  local s = subject.load()
  t.expect(s.third()):near(0.333333333333, 0.000000001)
end)