Typed Lua · 39 / 69
Reuse a domain type
YOUR TASK
Make this happen
A type alias gives a meaningful name to a record. Use the same dimensions contract for each argument and compute whether their sizes match.
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
type Dimensions = { width: number, height: number }
exports.same = function(a: Dimensions, b: Dimensions): boolean
return a.width == b.width
end
lesson.test.lua
local t = require("test")
local subject = require("cococo.subject")
t.it("both dimensions matter", function()
local s = subject.load()
t.expect(s.same({ width = 2, height = 3 }, { width = 2, height = 4 }))
:eq(false)
end)
t.it("identical dimensions", function()
local s = subject.load()
t.expect(s.same({ width = 2, height = 3 }, { width = 2, height = 3 }))
:eq(true)
end)