docs improvement

This commit is contained in:
Michael Freno
2025-11-18 13:44:00 -05:00
parent 96150e5cf4
commit d86f7dbd5e
16 changed files with 392 additions and 258 deletions

View File

@@ -27,7 +27,7 @@ function TestAnimationProperties:testColorLerp_MidPoint()
local colorA = Color.new(0, 0, 0, 1) -- Black
local colorB = Color.new(1, 1, 1, 1) -- White
local result = Color.lerp(colorA, colorB, 0.5)
luaunit.assertAlmostEquals(result.r, 0.5, 0.01)
luaunit.assertAlmostEquals(result.g, 0.5, 0.01)
luaunit.assertAlmostEquals(result.b, 0.5, 0.01)
@@ -38,7 +38,7 @@ function TestAnimationProperties:testColorLerp_StartPoint()
local colorA = Color.new(1, 0, 0, 1) -- Red
local colorB = Color.new(0, 0, 1, 1) -- Blue
local result = Color.lerp(colorA, colorB, 0)
luaunit.assertAlmostEquals(result.r, 1, 0.01)
luaunit.assertAlmostEquals(result.g, 0, 0.01)
luaunit.assertAlmostEquals(result.b, 0, 0.01)
@@ -48,7 +48,7 @@ function TestAnimationProperties:testColorLerp_EndPoint()
local colorA = Color.new(1, 0, 0, 1) -- Red
local colorB = Color.new(0, 0, 1, 1) -- Blue
local result = Color.lerp(colorA, colorB, 1)
luaunit.assertAlmostEquals(result.r, 0, 0.01)
luaunit.assertAlmostEquals(result.g, 0, 0.01)
luaunit.assertAlmostEquals(result.b, 1, 0.01)
@@ -58,7 +58,7 @@ function TestAnimationProperties:testColorLerp_Alpha()
local colorA = Color.new(1, 1, 1, 0) -- Transparent white
local colorB = Color.new(1, 1, 1, 1) -- Opaque white
local result = Color.lerp(colorA, colorB, 0.5)
luaunit.assertAlmostEquals(result.a, 0.5, 0.01)
end
@@ -72,11 +72,11 @@ end
function TestAnimationProperties:testColorLerp_ClampT()
local colorA = Color.new(0, 0, 0, 1)
local colorB = Color.new(1, 1, 1, 1)
-- Test t > 1
local result1 = Color.lerp(colorA, colorB, 1.5)
luaunit.assertAlmostEquals(result1.r, 1, 0.01)
-- Test t < 0
local result2 = Color.lerp(colorA, colorB, -0.5)
luaunit.assertAlmostEquals(result2.r, 0, 0.01)
@@ -90,10 +90,10 @@ function TestAnimationProperties:testPositionAnimation_XProperty()
start = { x = 0 },
final = { x = 100 },
})
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertAlmostEquals(result.x, 50, 0.01)
end
@@ -103,10 +103,10 @@ function TestAnimationProperties:testPositionAnimation_YProperty()
start = { y = 0 },
final = { y = 200 },
})
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertAlmostEquals(result.y, 100, 0.01)
end
@@ -116,10 +116,10 @@ function TestAnimationProperties:testPositionAnimation_XY()
start = { x = 10, y = 20 },
final = { x = 110, y = 220 },
})
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertAlmostEquals(result.x, 60, 0.01)
luaunit.assertAlmostEquals(result.y, 120, 0.01)
end
@@ -133,10 +133,10 @@ function TestAnimationProperties:testColorAnimation_BackgroundColor()
final = { backgroundColor = Color.new(0, 0, 1, 1) }, -- Blue
})
anim:setColorModule(Color)
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertNotNil(result.backgroundColor)
luaunit.assertAlmostEquals(result.backgroundColor.r, 0.5, 0.01)
luaunit.assertAlmostEquals(result.backgroundColor.b, 0.5, 0.01)
@@ -157,14 +157,14 @@ function TestAnimationProperties:testColorAnimation_MultipleColors()
},
})
anim:setColorModule(Color)
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertNotNil(result.backgroundColor)
luaunit.assertNotNil(result.borderColor)
luaunit.assertNotNil(result.textColor)
-- Mid-point should be (0.5, 0.5, 0.5) for backgroundColor
luaunit.assertAlmostEquals(result.backgroundColor.r, 0.5, 0.01)
luaunit.assertAlmostEquals(result.backgroundColor.g, 0.5, 0.01)
@@ -178,10 +178,10 @@ function TestAnimationProperties:testColorAnimation_WithoutColorModule()
final = { backgroundColor = Color.new(0, 0, 1, 1) },
})
-- Don't set Color module
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertNil(result.backgroundColor)
end
@@ -192,10 +192,10 @@ function TestAnimationProperties:testColorAnimation_HexColors()
final = { backgroundColor = "#0000FF" }, -- Blue
})
anim:setColorModule(Color)
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertNotNil(result.backgroundColor)
luaunit.assertAlmostEquals(result.backgroundColor.r, 0.5, 0.01)
end
@@ -207,10 +207,10 @@ function TestAnimationProperties:testColorAnimation_NamedColors()
final = { backgroundColor = "blue" },
})
anim:setColorModule(Color)
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertNotNil(result.backgroundColor)
luaunit.assertAlmostEquals(result.backgroundColor.r, 0.5, 0.01)
end
@@ -223,10 +223,10 @@ function TestAnimationProperties:testNumericAnimation_Gap()
start = { gap = 0 },
final = { gap = 20 },
})
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertAlmostEquals(result.gap, 10, 0.01)
end
@@ -236,10 +236,10 @@ function TestAnimationProperties:testNumericAnimation_ImageOpacity()
start = { imageOpacity = 0 },
final = { imageOpacity = 1 },
})
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertAlmostEquals(result.imageOpacity, 0.5, 0.01)
end
@@ -249,10 +249,10 @@ function TestAnimationProperties:testNumericAnimation_BorderWidth()
start = { borderWidth = 1 },
final = { borderWidth = 10 },
})
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertAlmostEquals(result.borderWidth, 5.5, 0.01)
end
@@ -262,10 +262,10 @@ function TestAnimationProperties:testNumericAnimation_FontSize()
start = { fontSize = 12 },
final = { fontSize = 24 },
})
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertAlmostEquals(result.fontSize, 18, 0.01)
end
@@ -275,10 +275,10 @@ function TestAnimationProperties:testNumericAnimation_MultipleProperties()
start = { gap = 0, imageOpacity = 0, borderWidth = 1 },
final = { gap = 20, imageOpacity = 1, borderWidth = 5 },
})
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertAlmostEquals(result.gap, 10, 0.01)
luaunit.assertAlmostEquals(result.imageOpacity, 0.5, 0.01)
luaunit.assertAlmostEquals(result.borderWidth, 3, 0.01)
@@ -292,10 +292,10 @@ function TestAnimationProperties:testTableAnimation_Padding()
start = { padding = { top = 0, right = 0, bottom = 0, left = 0 } },
final = { padding = { top = 10, right = 20, bottom = 10, left = 20 } },
})
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertNotNil(result.padding)
luaunit.assertAlmostEquals(result.padding.top, 5, 0.01)
luaunit.assertAlmostEquals(result.padding.right, 10, 0.01)
@@ -309,10 +309,10 @@ function TestAnimationProperties:testTableAnimation_Margin()
start = { margin = { top = 0, right = 0, bottom = 0, left = 0 } },
final = { margin = { top = 20, right = 20, bottom = 20, left = 20 } },
})
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertNotNil(result.margin)
luaunit.assertAlmostEquals(result.margin.top, 10, 0.01)
luaunit.assertAlmostEquals(result.margin.right, 10, 0.01)
@@ -324,10 +324,10 @@ function TestAnimationProperties:testTableAnimation_CornerRadius()
start = { cornerRadius = { topLeft = 0, topRight = 0, bottomLeft = 0, bottomRight = 0 } },
final = { cornerRadius = { topLeft = 10, topRight = 10, bottomLeft = 10, bottomRight = 10 } },
})
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertNotNil(result.cornerRadius)
luaunit.assertAlmostEquals(result.cornerRadius.topLeft, 5, 0.01)
luaunit.assertAlmostEquals(result.cornerRadius.topRight, 5, 0.01)
@@ -340,10 +340,10 @@ function TestAnimationProperties:testTableAnimation_PartialKeys()
start = { padding = { top = 0, left = 0 } },
final = { padding = { top = 10, right = 20, left = 10 } },
})
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertNotNil(result.padding)
luaunit.assertAlmostEquals(result.padding.top, 5, 0.01)
luaunit.assertAlmostEquals(result.padding.left, 5, 0.01)
@@ -357,10 +357,10 @@ function TestAnimationProperties:testTableAnimation_NonNumericValues()
start = { padding = { top = 0, special = "value" } },
final = { padding = { top = 10, special = "value" } },
})
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertNotNil(result.padding)
luaunit.assertAlmostEquals(result.padding.top, 5, 0.01)
end
@@ -392,10 +392,10 @@ function TestAnimationProperties:testCombinedAnimation_AllTypes()
},
})
anim:setColorModule(Color)
anim:update(0.5)
local result = anim:interpolate()
-- Check all properties interpolated correctly
luaunit.assertAlmostEquals(result.width, 150, 0.01)
luaunit.assertAlmostEquals(result.height, 150, 0.01)
@@ -415,10 +415,10 @@ function TestAnimationProperties:testCombinedAnimation_WithEasing()
easing = "easeInQuad",
})
anim:setColorModule(Color)
anim:update(0.5)
local result = anim:interpolate()
-- With easeInQuad, at t=0.5, eased value should be 0.25
luaunit.assertAlmostEquals(result.x, 25, 0.01)
luaunit.assertAlmostEquals(result.backgroundColor.r, 0.25, 0.01)
@@ -433,10 +433,10 @@ function TestAnimationProperties:testBackwardCompatibility_WidthHeightOpacity()
start = { width = 100, height = 100, opacity = 0 },
final = { width = 200, height = 200, opacity = 1 },
})
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertAlmostEquals(result.width, 150, 0.01)
luaunit.assertAlmostEquals(result.height, 150, 0.01)
luaunit.assertAlmostEquals(result.opacity, 0.5, 0.01)
@@ -444,19 +444,19 @@ end
function TestAnimationProperties:testBackwardCompatibility_FadeHelper()
local anim = Animation.fade(1, 0, 1)
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertAlmostEquals(result.opacity, 0.5, 0.01)
end
function TestAnimationProperties:testBackwardCompatibility_ScaleHelper()
local anim = Animation.scale(1, { width = 100, height = 100 }, { width = 200, height = 200 })
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertAlmostEquals(result.width, 150, 0.01)
luaunit.assertAlmostEquals(result.height, 150, 0.01)
end
@@ -469,10 +469,10 @@ function TestAnimationProperties:testEdgeCase_MissingStartValue()
start = { x = 0 },
final = { x = 100, y = 100 },
})
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertAlmostEquals(result.x, 50, 0.01)
luaunit.assertNil(result.y) -- Should be nil since start.y is missing
end
@@ -483,10 +483,10 @@ function TestAnimationProperties:testEdgeCase_MissingFinalValue()
start = { x = 0, y = 0 },
final = { x = 100 },
})
anim:update(0.5)
local result = anim:interpolate()
luaunit.assertAlmostEquals(result.x, 50, 0.01)
luaunit.assertNil(result.y) -- Should be nil since final.y is missing
end
@@ -497,10 +497,10 @@ function TestAnimationProperties:testEdgeCase_EmptyTables()
start = {},
final = {},
})
anim:update(0.5)
local result = anim:interpolate()
-- Should not error, just return empty result
luaunit.assertNotNil(result)
end
@@ -512,11 +512,11 @@ function TestAnimationProperties:testEdgeCase_CachedResult()
start = { x = 0 },
final = { x = 100 },
})
anim:update(0.5)
local result1 = anim:interpolate()
local result2 = anim:interpolate() -- Should use cached result
luaunit.assertEquals(result1, result2) -- Same table reference
luaunit.assertAlmostEquals(result1.x, 50, 0.01)
end
@@ -527,15 +527,15 @@ function TestAnimationProperties:testEdgeCase_ResultInvalidatedOnUpdate()
start = { x = 0 },
final = { x = 100 },
})
anim:update(0.5)
local result1 = anim:interpolate()
local x1 = result1.x -- Store value, not reference
anim:update(0.25) -- Update again
local result2 = anim:interpolate()
local x2 = result2.x
-- Should recalculate
-- Note: result1 and result2 are the same cached table, but values should be updated
luaunit.assertAlmostEquals(x1, 50, 0.01)
@@ -544,4 +544,6 @@ function TestAnimationProperties:testEdgeCase_ResultInvalidatedOnUpdate()
luaunit.assertAlmostEquals(result1.x, 75, 0.01)
end
os.exit(luaunit.LuaUnit.run())
if not _G.RUNNING_ALL_TESTS then
os.exit(luaunit.LuaUnit.run())
end

View File

@@ -92,55 +92,60 @@ end
-- Test: warn() prints with correct format (backward compatibility)
function TestErrorHandler:test_warn_prints_with_format()
-- Capture print output by mocking print
-- Capture io.write output by mocking io.write
local captured = nil
local originalPrint = print
print = function(msg)
local originalWrite = io.write
io.write = function(msg)
captured = msg
end
ErrorHandler.setLogTarget("console")
ErrorHandler.warn("TestModule", "This is a warning")
ErrorHandler.setLogTarget("none")
print = originalPrint
io.write = originalWrite
luaunit.assertNotNil(captured, "warn() should print")
luaunit.assertEquals(captured, "[FlexLove - TestModule] Warning: This is a warning")
luaunit.assertStrContains(captured, "[WARNING] [TestModule] This is a warning")
end
-- Test: warn() with error code
function TestErrorHandler:test_warn_with_code()
local captured = nil
local originalPrint = print
print = function(msg)
local originalWrite = io.write
io.write = function(msg)
captured = msg
end
ErrorHandler.setLogTarget("console")
ErrorHandler.warn("TestModule", "VAL_001", "Potentially invalid property")
ErrorHandler.setLogTarget("none")
print = originalPrint
io.write = originalWrite
luaunit.assertNotNil(captured, "warn() should print")
luaunit.assertStrContains(captured, "[FlexLove - TestModule] Warning [FLEXLOVE_VAL_001]")
luaunit.assertStrContains(captured, "[WARNING] [TestModule] [VAL_001]")
luaunit.assertStrContains(captured, "Potentially invalid property")
end
-- Test: warn() with details
function TestErrorHandler:test_warn_with_details()
local captured = nil
local originalPrint = print
print = function(msg)
captured = msg
local originalWrite = io.write
io.write = function(msg)
captured = (captured or "") .. msg
end
ErrorHandler.setLogTarget("console")
ErrorHandler.warn("TestModule", "VAL_001", "Check this property", {
property = "height",
value = "auto",
})
ErrorHandler.setLogTarget("none")
print = originalPrint
io.write = originalWrite
luaunit.assertNotNil(captured, "warn() should print")
luaunit.assertStrContains(captured, "Details:")
luaunit.assertStrContains(captured, "Property: height")
luaunit.assertStrContains(captured, "Value: auto")
end
@@ -225,14 +230,16 @@ end
-- Test: warnDeprecated prints deprecation warning
function TestErrorHandler:test_warnDeprecated_prints_message()
local captured = nil
local originalPrint = print
print = function(msg)
local originalWrite = io.write
io.write = function(msg)
captured = msg
end
ErrorHandler.setLogTarget("console")
ErrorHandler.warnDeprecated("TestModule", "oldFunction", "newFunction")
ErrorHandler.setLogTarget("none")
print = originalPrint
io.write = originalWrite
luaunit.assertNotNil(captured, "warnDeprecated should print")
luaunit.assertStrContains(captured, "'oldFunction' is deprecated. Use 'newFunction' instead")
@@ -241,14 +248,16 @@ end
-- Test: warnCommonMistake prints helpful message
function TestErrorHandler:test_warnCommonMistake_prints_message()
local captured = nil
local originalPrint = print
print = function(msg)
local originalWrite = io.write
io.write = function(msg)
captured = msg
end
ErrorHandler.setLogTarget("console")
ErrorHandler.warnCommonMistake("TestModule", "Width is zero", "Set width to positive value")
ErrorHandler.setLogTarget("none")
print = originalPrint
io.write = originalWrite
luaunit.assertNotNil(captured, "warnCommonMistake should print")
luaunit.assertStrContains(captured, "Width is zero. Suggestion: Set width to positive value")

View File

@@ -21,7 +21,7 @@ end
function TestFlexLove:testModuleLoads()
luaunit.assertNotNil(FlexLove)
luaunit.assertNotNil(FlexLove._VERSION)
luaunit.assertEquals(FlexLove._VERSION, "0.2.2")
luaunit.assertEquals(FlexLove._VERSION, "0.2.3")
luaunit.assertNotNil(FlexLove._DESCRIPTION)
luaunit.assertNotNil(FlexLove._URL)
luaunit.assertNotNil(FlexLove._LICENSE)

View File

@@ -16,8 +16,12 @@ TestImageTiling = {}
function TestImageTiling:setUp()
-- Create a mock image
self.mockImage = {
getDimensions = function() return 64, 64 end,
type = function() return "Image" end,
getDimensions = function()
return 64, 64
end,
type = function()
return "Image"
end,
}
end
@@ -30,7 +34,7 @@ function TestImageTiling:testDrawTiledNoRepeat()
local drawCalls = {}
local originalDraw = love.graphics.draw
love.graphics.draw = function(...)
table.insert(drawCalls, {...})
table.insert(drawCalls, { ... })
end
ImageRenderer.drawTiled(self.mockImage, 100, 100, 200, 200, "no-repeat", 1, nil)
@@ -49,11 +53,11 @@ function TestImageTiling:testDrawTiledRepeat()
local drawCalls = {}
local originalDraw = love.graphics.draw
local originalNewQuad = love.graphics.newQuad
love.graphics.draw = function(...)
table.insert(drawCalls, {...})
table.insert(drawCalls, { ... })
end
love.graphics.newQuad = function(...)
return { type = "quad", ... }
end
@@ -75,11 +79,11 @@ function TestImageTiling:testDrawTiledRepeatX()
local drawCalls = {}
local originalDraw = love.graphics.draw
local originalNewQuad = love.graphics.newQuad
love.graphics.draw = function(...)
table.insert(drawCalls, {...})
table.insert(drawCalls, { ... })
end
love.graphics.newQuad = function(...)
return { type = "quad", ... }
end
@@ -100,11 +104,11 @@ function TestImageTiling:testDrawTiledRepeatY()
local drawCalls = {}
local originalDraw = love.graphics.draw
local originalNewQuad = love.graphics.newQuad
love.graphics.draw = function(...)
table.insert(drawCalls, {...})
table.insert(drawCalls, { ... })
end
love.graphics.newQuad = function(...)
return { type = "quad", ... }
end
@@ -124,9 +128,9 @@ function TestImageTiling:testDrawTiledSpace()
-- Test space mode (distributes tiles with even spacing)
local drawCalls = {}
local originalDraw = love.graphics.draw
love.graphics.draw = function(...)
table.insert(drawCalls, {...})
table.insert(drawCalls, { ... })
end
-- Image is 64x64, bounds are 200x200
@@ -142,9 +146,9 @@ function TestImageTiling:testDrawTiledRound()
-- Test round mode (scales tiles to fit exactly)
local drawCalls = {}
local originalDraw = love.graphics.draw
love.graphics.draw = function(...)
table.insert(drawCalls, {...})
table.insert(drawCalls, { ... })
end
-- Image is 64x64, bounds are 200x200
@@ -160,9 +164,9 @@ function TestImageTiling:testDrawTiledWithOpacity()
-- Test tiling with opacity
local setColorCalls = {}
local originalSetColor = love.graphics.setColor
love.graphics.setColor = function(...)
table.insert(setColorCalls, {...})
table.insert(setColorCalls, { ... })
end
ImageRenderer.drawTiled(self.mockImage, 100, 100, 200, 200, "no-repeat", 0.5, nil)
@@ -186,9 +190,9 @@ function TestImageTiling:testDrawTiledWithTint()
-- Test tiling with tint color
local setColorCalls = {}
local originalSetColor = love.graphics.setColor
love.graphics.setColor = function(...)
table.insert(setColorCalls, {...})
table.insert(setColorCalls, { ... })
end
local redTint = Color.new(1, 0, 0, 1)
@@ -219,7 +223,7 @@ function TestImageTiling:testElementImageRepeatProperty()
local Renderer = require("modules.Renderer")
local EventHandler = require("modules.EventHandler")
local ImageCache = require("modules.ImageCache")
local deps = {
utils = utils,
Color = Color,
@@ -231,7 +235,7 @@ function TestImageTiling:testElementImageRepeatProperty()
ImageRenderer = ImageRenderer,
ErrorHandler = ErrorHandler,
}
local element = Element.new({
width = 200,
height = 200,
@@ -251,7 +255,7 @@ function TestImageTiling:testElementImageRepeatDefault()
local Renderer = require("modules.Renderer")
local EventHandler = require("modules.EventHandler")
local ImageCache = require("modules.ImageCache")
local deps = {
utils = utils,
Color = Color,
@@ -263,7 +267,7 @@ function TestImageTiling:testElementImageRepeatDefault()
ImageRenderer = ImageRenderer,
ErrorHandler = ErrorHandler,
}
local element = Element.new({
width = 200,
height = 200,
@@ -282,7 +286,7 @@ function TestImageTiling:testElementSetImageRepeat()
local Renderer = require("modules.Renderer")
local EventHandler = require("modules.EventHandler")
local ImageCache = require("modules.ImageCache")
local deps = {
utils = utils,
Color = Color,
@@ -294,7 +298,7 @@ function TestImageTiling:testElementSetImageRepeat()
ImageRenderer = ImageRenderer,
ErrorHandler = ErrorHandler,
}
local element = Element.new({
width = 200,
height = 200,
@@ -313,9 +317,9 @@ function TestImageTiling:testElementImageTintProperty()
local Renderer = require("modules.Renderer")
local EventHandler = require("modules.EventHandler")
local ImageCache = require("modules.ImageCache")
local redTint = Color.new(1, 0, 0, 1)
local deps = {
utils = utils,
Color = Color,
@@ -327,7 +331,7 @@ function TestImageTiling:testElementImageTintProperty()
ImageRenderer = ImageRenderer,
ErrorHandler = ErrorHandler,
}
local element = Element.new({
width = 200,
height = 200,
@@ -346,7 +350,7 @@ function TestImageTiling:testElementSetImageTint()
local Renderer = require("modules.Renderer")
local EventHandler = require("modules.EventHandler")
local ImageCache = require("modules.ImageCache")
local deps = {
utils = utils,
Color = Color,
@@ -358,7 +362,7 @@ function TestImageTiling:testElementSetImageTint()
ImageRenderer = ImageRenderer,
ErrorHandler = ErrorHandler,
}
local element = Element.new({
width = 200,
height = 200,
@@ -379,7 +383,7 @@ function TestImageTiling:testElementSetImageOpacity()
local Renderer = require("modules.Renderer")
local EventHandler = require("modules.EventHandler")
local ImageCache = require("modules.ImageCache")
local deps = {
utils = utils,
Color = Color,
@@ -391,7 +395,7 @@ function TestImageTiling:testElementSetImageOpacity()
ImageRenderer = ImageRenderer,
ErrorHandler = ErrorHandler,
}
local element = Element.new({
width = 200,
height = 200,
@@ -401,5 +405,6 @@ function TestImageTiling:testElementSetImageOpacity()
luaunit.assertEquals(element.imageOpacity, 0.7)
end
-- Run the tests
os.exit(luaunit.LuaUnit.run())
if not _G.RUNNING_ALL_TESTS then
os.exit(luaunit.LuaUnit.run())
end

View File

@@ -23,18 +23,18 @@ end
function TestPerformanceInstrumentation:testTimerStartStop()
Performance.startTimer("test_operation")
-- Simulate some work
local sum = 0
for i = 1, 1000 do
sum = sum + i
end
local elapsed = Performance.stopTimer("test_operation")
luaunit.assertNotNil(elapsed)
luaunit.assertTrue(elapsed >= 0)
local metrics = Performance.getMetrics()
luaunit.assertNotNil(metrics.timings["test_operation"])
luaunit.assertEquals(metrics.timings["test_operation"].count, 1)
@@ -44,13 +44,15 @@ function TestPerformanceInstrumentation:testMultipleTimers()
-- Start multiple timers
Performance.startTimer("layout")
Performance.startTimer("render")
local sum = 0
for i = 1, 100 do sum = sum + i end
for i = 1, 100 do
sum = sum + i
end
Performance.stopTimer("layout")
Performance.stopTimer("render")
local metrics = Performance.getMetrics()
luaunit.assertNotNil(metrics.timings["layout"])
luaunit.assertNotNil(metrics.timings["render"])
@@ -58,15 +60,15 @@ end
function TestPerformanceInstrumentation:testFrameTiming()
Performance.startFrame()
-- Simulate frame work
local sum = 0
for i = 1, 1000 do
sum = sum + i
end
Performance.endFrame()
local frameMetrics = Performance.getFrameMetrics()
luaunit.assertNotNil(frameMetrics)
luaunit.assertEquals(frameMetrics.frameCount, 1)
@@ -77,10 +79,10 @@ function TestPerformanceInstrumentation:testDrawCallCounting()
Performance.incrementCounter("draw_calls", 1)
Performance.incrementCounter("draw_calls", 1)
Performance.incrementCounter("draw_calls", 1)
local counter = Performance.getFrameCounter("draw_calls")
luaunit.assertEquals(counter, 3)
-- Reset and check
Performance.resetFrameCounters()
counter = Performance.getFrameCounter("draw_calls")
@@ -89,10 +91,10 @@ end
function TestPerformanceInstrumentation:testHUDToggle()
luaunit.assertFalse(Performance.getConfig().hudEnabled)
Performance.toggleHUD()
luaunit.assertTrue(Performance.getConfig().hudEnabled)
Performance.toggleHUD()
luaunit.assertFalse(Performance.getConfig().hudEnabled)
end
@@ -100,10 +102,10 @@ end
function TestPerformanceInstrumentation:testEnableDisable()
Performance.enable()
luaunit.assertTrue(Performance.isEnabled())
Performance.disable()
luaunit.assertFalse(Performance.isEnabled())
-- Timers should not record when disabled
Performance.startTimer("disabled_test")
local elapsed = Performance.stopTimer("disabled_test")
@@ -118,12 +120,12 @@ function TestPerformanceInstrumentation:testMeasureFunction()
end
return sum
end
local wrapped = Performance.measure("expensive_op", expensiveOperation)
local result = wrapped(1000)
luaunit.assertEquals(result, 500500) -- sum of 1 to 1000
local metrics = Performance.getMetrics()
luaunit.assertNotNil(metrics.timings["expensive_op"])
luaunit.assertEquals(metrics.timings["expensive_op"].count, 1)
@@ -131,7 +133,7 @@ end
function TestPerformanceInstrumentation:testMemoryTracking()
Performance.updateMemory()
local memMetrics = Performance.getMemoryMetrics()
luaunit.assertNotNil(memMetrics)
luaunit.assertTrue(memMetrics.currentKb > 0)
@@ -142,7 +144,7 @@ end
function TestPerformanceInstrumentation:testExportJSON()
Performance.startTimer("test_op")
Performance.stopTimer("test_op")
local json = Performance.exportJSON()
luaunit.assertNotNil(json)
luaunit.assertTrue(string.find(json, "fps") ~= nil)
@@ -152,16 +154,13 @@ end
function TestPerformanceInstrumentation:testExportCSV()
Performance.startTimer("test_op")
Performance.stopTimer("test_op")
local csv = Performance.exportCSV()
luaunit.assertNotNil(csv)
luaunit.assertTrue(string.find(csv, "Name,Average") ~= nil)
luaunit.assertTrue(string.find(csv, "test_op") ~= nil)
end
-- Run tests if executed directly
if arg and arg[0]:find("performance_instrumentation_test%.lua$") then
if not _G.RUNNING_ALL_TESTS then
os.exit(luaunit.LuaUnit.run())
end
return TestPerformanceInstrumentation

View File

@@ -153,4 +153,6 @@ function TestPerformanceWarnings:testLayoutRecalculationTracking()
luaunit.assertNotNil(root)
end
return TestPerformanceWarnings
if not _G.RUNNING_ALL_TESTS then
os.exit(luaunit.LuaUnit.run())
end

View File

@@ -243,8 +243,8 @@ function TestTransform:testClone_AllProperties()
luaunit.assertAlmostEquals(clone.originX, 0.25, 0.01)
luaunit.assertAlmostEquals(clone.originY, 0.75, 0.01)
-- Ensure it's a different object
luaunit.assertNotEquals(clone, original)
-- Ensure it's a different object (use raw comparison)
luaunit.assertFalse(rawequal(clone, original), "Clone should be a different table instance")
end
function TestTransform:testClone_Nil()
@@ -289,4 +289,6 @@ function TestTransform:testTransformAnimation()
luaunit.assertAlmostEquals(result.transform.scaleX, 1.5, 0.01)
end
os.exit(luaunit.LuaUnit.run())
if not _G.RUNNING_ALL_TESTS then
os.exit(luaunit.LuaUnit.run())
end

View File

@@ -105,6 +105,9 @@ function love_helper.graphics.newCanvas(width, height)
getDimensions = function()
return width or mockWindowWidth, height or mockWindowHeight
end,
release = function()
-- Mock canvas release
end,
}
end