--- @class Test
local test = {}
function test:run(complete) end

function test:update(dt) end

--- @class TestRunner
--- @field private tests Test[]
--- @field private state "loading" | "running" | "completed"
--- @field private completedCount integer
local runner = {}
runner.tests = {}
runner.state = "loading"
runner.completedCount = 0

--- глобальный update для тестов, нужен для тестирования фич, зависимых от времени
function runner:update(dt)
    if self.state == "loading" then
        print("[TestRunner]: running " .. #self.tests .. " tests")

        for _, t in ipairs(self.tests) do
            t:run(
                function()
                    self.completedCount = self.completedCount + 1
                    if self.completedCount == #self.tests then
                        self.state = "completed"
                        print("[TestRunner]: tests completed")
                    end
                end
            )
        end
        self.state = "running"
    end

    for _, t in ipairs(self.tests) do
        if t.update then t:update(dt) end
    end
end

--- добавляет тест для прохождения
--- @param t Test
function runner:register(t)
    table.insert(self.tests, t)
end

return runner
