-- test_helper.lua
-- Simple test framework for Lua unit tests

local TestHelper = {}

function TestHelper:new()
    local helper = {
        tests = {},
        passed = 0,
        failed = 0,
        startTime = os.clock()
    }
    setmetatable(helper, {__index = self})
    return helper
end

function TestHelper:test(name, func)
    io.write("Running: " .. name .. " ... ")
    io.flush()
    
    local startTime = os.clock()
    local success, err = pcall(func)
    local duration = os.clock() - startTime
    
    if success then
        self.passed = self.passed + 1
        print(string.format("✓ (%.3fs)", duration))
    else
        self.failed = self.failed + 1
        print(string.format("✗ (%.3fs)", duration))
        print("  Error: " .. tostring(err))
    end
end

function TestHelper:describe(suiteName, setupFunc)
    print("\n" .. suiteName)
    print(string.rep("-", string.len(suiteName)))
    setupFunc()
end

function TestHelper:summary()
    local totalTime = os.clock() - self.startTime
    print(string.rep("=", 50))
    print(string.format("Tests: %d passed, %d failed, %d total", 
        self.passed, self.failed, self.passed + self.failed))
    print(string.format("Time:  %.3fs", totalTime))
    
    if self.failed == 0 then
        print("Status: SUCCESS ✓")
    else
        print("Status: FAILED ✗")
    end
    
    return self.failed == 0
end

return TestHelper
