Thinking in Lua · 8 / 69
Double until ready
YOUR TASK
Make this happen
A while loop tests its condition before each iteration. Starting at 1, double the capacity until it is at least the requested size. Ensure each iteration moves towards termination.
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.capacity = function(required: number): number return 1 end
lesson.test.lua
local t = require("test")
local subject = require("cococo.subject")
t.it("rounds up", function()
local s = subject.load()
t.expect(s.capacity(5)):eq(8)
end)
t.it("exact capacity", function()
local s = subject.load()
t.expect(s.capacity(8)):eq(8)
end)
t.it("minimum capacity", function()
local s = subject.load()
t.expect(s.capacity(0)):eq(1)
end)