image and animation progress
This commit is contained in:
536
testing/__tests__/animation_properties_test.lua
Normal file
536
testing/__tests__/animation_properties_test.lua
Normal file
@@ -0,0 +1,536 @@
|
||||
local luaunit = require("testing.luaunit")
|
||||
require("testing.loveStub")
|
||||
|
||||
local Animation = require("modules.Animation")
|
||||
local Color = require("modules.Color")
|
||||
|
||||
TestAnimationProperties = {}
|
||||
|
||||
function TestAnimationProperties:setUp()
|
||||
-- Reset state before each test
|
||||
end
|
||||
|
||||
-- Test Color.lerp() method
|
||||
|
||||
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)
|
||||
luaunit.assertAlmostEquals(result.a, 1, 0.01)
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
function TestAnimationProperties:testColorLerp_InvalidInputs()
|
||||
-- Should handle invalid inputs gracefully
|
||||
local result = Color.lerp("invalid", "invalid", 0.5)
|
||||
luaunit.assertNotNil(result)
|
||||
luaunit.assertEquals(getmetatable(result), Color)
|
||||
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)
|
||||
end
|
||||
|
||||
-- Test Position Animation (x, y)
|
||||
|
||||
function TestAnimationProperties:testPositionAnimation_XProperty()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
start = { x = 0 },
|
||||
final = { x = 100 },
|
||||
})
|
||||
|
||||
anim:update(0.5)
|
||||
local result = anim:interpolate()
|
||||
|
||||
luaunit.assertAlmostEquals(result.x, 50, 0.01)
|
||||
end
|
||||
|
||||
function TestAnimationProperties:testPositionAnimation_YProperty()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
start = { y = 0 },
|
||||
final = { y = 200 },
|
||||
})
|
||||
|
||||
anim:update(0.5)
|
||||
local result = anim:interpolate()
|
||||
|
||||
luaunit.assertAlmostEquals(result.y, 100, 0.01)
|
||||
end
|
||||
|
||||
function TestAnimationProperties:testPositionAnimation_XY()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
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
|
||||
|
||||
-- Test Color Property Animation
|
||||
|
||||
function TestAnimationProperties:testColorAnimation_BackgroundColor()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
start = { backgroundColor = Color.new(1, 0, 0, 1) }, -- Red
|
||||
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)
|
||||
end
|
||||
|
||||
function TestAnimationProperties:testColorAnimation_MultipleColors()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
start = {
|
||||
backgroundColor = Color.new(1, 0, 0, 1),
|
||||
borderColor = Color.new(0, 1, 0, 1),
|
||||
textColor = Color.new(0, 0, 1, 1),
|
||||
},
|
||||
final = {
|
||||
backgroundColor = Color.new(0, 1, 0, 1),
|
||||
borderColor = Color.new(0, 0, 1, 1),
|
||||
textColor = Color.new(1, 0, 0, 1),
|
||||
},
|
||||
})
|
||||
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)
|
||||
end
|
||||
|
||||
function TestAnimationProperties:testColorAnimation_WithoutColorModule()
|
||||
-- Should not interpolate colors without Color module set
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
start = { backgroundColor = Color.new(1, 0, 0, 1) },
|
||||
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
|
||||
|
||||
function TestAnimationProperties:testColorAnimation_HexColors()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
start = { backgroundColor = "#FF0000" }, -- Red
|
||||
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
|
||||
|
||||
function TestAnimationProperties:testColorAnimation_NamedColors()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
start = { backgroundColor = "red" },
|
||||
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
|
||||
|
||||
-- Test Numeric Property Animation
|
||||
|
||||
function TestAnimationProperties:testNumericAnimation_Gap()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
start = { gap = 0 },
|
||||
final = { gap = 20 },
|
||||
})
|
||||
|
||||
anim:update(0.5)
|
||||
local result = anim:interpolate()
|
||||
|
||||
luaunit.assertAlmostEquals(result.gap, 10, 0.01)
|
||||
end
|
||||
|
||||
function TestAnimationProperties:testNumericAnimation_ImageOpacity()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
start = { imageOpacity = 0 },
|
||||
final = { imageOpacity = 1 },
|
||||
})
|
||||
|
||||
anim:update(0.5)
|
||||
local result = anim:interpolate()
|
||||
|
||||
luaunit.assertAlmostEquals(result.imageOpacity, 0.5, 0.01)
|
||||
end
|
||||
|
||||
function TestAnimationProperties:testNumericAnimation_BorderWidth()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
start = { borderWidth = 1 },
|
||||
final = { borderWidth = 10 },
|
||||
})
|
||||
|
||||
anim:update(0.5)
|
||||
local result = anim:interpolate()
|
||||
|
||||
luaunit.assertAlmostEquals(result.borderWidth, 5.5, 0.01)
|
||||
end
|
||||
|
||||
function TestAnimationProperties:testNumericAnimation_FontSize()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
start = { fontSize = 12 },
|
||||
final = { fontSize = 24 },
|
||||
})
|
||||
|
||||
anim:update(0.5)
|
||||
local result = anim:interpolate()
|
||||
|
||||
luaunit.assertAlmostEquals(result.fontSize, 18, 0.01)
|
||||
end
|
||||
|
||||
function TestAnimationProperties:testNumericAnimation_MultipleProperties()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
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)
|
||||
end
|
||||
|
||||
-- Test Table Property Animation (padding, margin, cornerRadius)
|
||||
|
||||
function TestAnimationProperties:testTableAnimation_Padding()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
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)
|
||||
luaunit.assertAlmostEquals(result.padding.bottom, 5, 0.01)
|
||||
luaunit.assertAlmostEquals(result.padding.left, 10, 0.01)
|
||||
end
|
||||
|
||||
function TestAnimationProperties:testTableAnimation_Margin()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
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)
|
||||
end
|
||||
|
||||
function TestAnimationProperties:testTableAnimation_CornerRadius()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
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)
|
||||
end
|
||||
|
||||
function TestAnimationProperties:testTableAnimation_PartialKeys()
|
||||
-- Test when start and final have different keys
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
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)
|
||||
luaunit.assertNotNil(result.padding.right)
|
||||
end
|
||||
|
||||
function TestAnimationProperties:testTableAnimation_NonNumericValues()
|
||||
-- Should skip non-numeric values in tables
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
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
|
||||
|
||||
-- Test Combined Animations
|
||||
|
||||
function TestAnimationProperties:testCombinedAnimation_AllTypes()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
start = {
|
||||
width = 100,
|
||||
height = 100,
|
||||
x = 0,
|
||||
y = 0,
|
||||
opacity = 0,
|
||||
backgroundColor = Color.new(1, 0, 0, 1),
|
||||
gap = 0,
|
||||
padding = { top = 0, left = 0 },
|
||||
},
|
||||
final = {
|
||||
width = 200,
|
||||
height = 200,
|
||||
x = 100,
|
||||
y = 100,
|
||||
opacity = 1,
|
||||
backgroundColor = Color.new(0, 0, 1, 1),
|
||||
gap = 20,
|
||||
padding = { top = 10, left = 10 },
|
||||
},
|
||||
})
|
||||
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)
|
||||
luaunit.assertAlmostEquals(result.x, 50, 0.01)
|
||||
luaunit.assertAlmostEquals(result.y, 50, 0.01)
|
||||
luaunit.assertAlmostEquals(result.opacity, 0.5, 0.01)
|
||||
luaunit.assertAlmostEquals(result.gap, 10, 0.01)
|
||||
luaunit.assertNotNil(result.backgroundColor)
|
||||
luaunit.assertNotNil(result.padding)
|
||||
end
|
||||
|
||||
function TestAnimationProperties:testCombinedAnimation_WithEasing()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
start = { x = 0, backgroundColor = Color.new(0, 0, 0, 1) },
|
||||
final = { x = 100, backgroundColor = Color.new(1, 1, 1, 1) },
|
||||
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)
|
||||
end
|
||||
|
||||
-- Test Backward Compatibility
|
||||
|
||||
function TestAnimationProperties:testBackwardCompatibility_WidthHeightOpacity()
|
||||
-- Ensure old animations still work
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
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)
|
||||
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
|
||||
|
||||
-- Test Edge Cases
|
||||
|
||||
function TestAnimationProperties:testEdgeCase_MissingStartValue()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
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
|
||||
|
||||
function TestAnimationProperties:testEdgeCase_MissingFinalValue()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
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
|
||||
|
||||
function TestAnimationProperties:testEdgeCase_EmptyTables()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
start = {},
|
||||
final = {},
|
||||
})
|
||||
|
||||
anim:update(0.5)
|
||||
local result = anim:interpolate()
|
||||
|
||||
-- Should not error, just return empty result
|
||||
luaunit.assertNotNil(result)
|
||||
end
|
||||
|
||||
function TestAnimationProperties:testEdgeCase_CachedResult()
|
||||
-- Test that cached results work correctly
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
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
|
||||
|
||||
function TestAnimationProperties:testEdgeCase_ResultInvalidatedOnUpdate()
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
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)
|
||||
luaunit.assertAlmostEquals(x2, 75, 0.01)
|
||||
-- result1.x will actually be 75 now since it's the same table reference
|
||||
luaunit.assertAlmostEquals(result1.x, 75, 0.01)
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
405
testing/__tests__/image_tiling_test.lua
Normal file
405
testing/__tests__/image_tiling_test.lua
Normal file
@@ -0,0 +1,405 @@
|
||||
-- Image Tiling Tests
|
||||
-- Tests for ImageRenderer tiling functionality
|
||||
|
||||
local luaunit = require("testing.luaunit")
|
||||
require("testing.loveStub")
|
||||
|
||||
local ImageRenderer = require("modules.ImageRenderer")
|
||||
local ErrorHandler = require("modules.ErrorHandler")
|
||||
local Color = require("modules.Color")
|
||||
|
||||
-- Initialize ImageRenderer with ErrorHandler
|
||||
ImageRenderer.init({ ErrorHandler = ErrorHandler })
|
||||
|
||||
TestImageTiling = {}
|
||||
|
||||
function TestImageTiling:setUp()
|
||||
-- Create a mock image
|
||||
self.mockImage = {
|
||||
getDimensions = function() return 64, 64 end,
|
||||
type = function() return "Image" end,
|
||||
}
|
||||
end
|
||||
|
||||
function TestImageTiling:tearDown()
|
||||
self.mockImage = nil
|
||||
end
|
||||
|
||||
function TestImageTiling:testDrawTiledNoRepeat()
|
||||
-- Test no-repeat mode (single image)
|
||||
local drawCalls = {}
|
||||
local originalDraw = love.graphics.draw
|
||||
love.graphics.draw = function(...)
|
||||
table.insert(drawCalls, {...})
|
||||
end
|
||||
|
||||
ImageRenderer.drawTiled(self.mockImage, 100, 100, 200, 200, "no-repeat", 1, nil)
|
||||
|
||||
-- Should draw once
|
||||
luaunit.assertEquals(#drawCalls, 1)
|
||||
luaunit.assertEquals(drawCalls[1][1], self.mockImage)
|
||||
luaunit.assertEquals(drawCalls[1][2], 100)
|
||||
luaunit.assertEquals(drawCalls[1][3], 100)
|
||||
|
||||
love.graphics.draw = originalDraw
|
||||
end
|
||||
|
||||
function TestImageTiling:testDrawTiledRepeat()
|
||||
-- Test repeat mode (tiles in both directions)
|
||||
local drawCalls = {}
|
||||
local originalDraw = love.graphics.draw
|
||||
local originalNewQuad = love.graphics.newQuad
|
||||
|
||||
love.graphics.draw = function(...)
|
||||
table.insert(drawCalls, {...})
|
||||
end
|
||||
|
||||
love.graphics.newQuad = function(...)
|
||||
return { type = "quad", ... }
|
||||
end
|
||||
|
||||
-- Image is 64x64, bounds are 200x200
|
||||
-- Should tile 4 times (4 tiles total: 2x2 with partials)
|
||||
ImageRenderer.drawTiled(self.mockImage, 100, 100, 200, 200, "repeat", 1, nil)
|
||||
|
||||
-- 4 tiles: (0,0), (64,0), (0,64), (64,64)
|
||||
-- 2 full tiles + 2 partial tiles = 4 draws
|
||||
luaunit.assertTrue(#drawCalls >= 4)
|
||||
|
||||
love.graphics.draw = originalDraw
|
||||
love.graphics.newQuad = originalNewQuad
|
||||
end
|
||||
|
||||
function TestImageTiling:testDrawTiledRepeatX()
|
||||
-- Test repeat-x mode (tiles horizontally only)
|
||||
local drawCalls = {}
|
||||
local originalDraw = love.graphics.draw
|
||||
local originalNewQuad = love.graphics.newQuad
|
||||
|
||||
love.graphics.draw = function(...)
|
||||
table.insert(drawCalls, {...})
|
||||
end
|
||||
|
||||
love.graphics.newQuad = function(...)
|
||||
return { type = "quad", ... }
|
||||
end
|
||||
|
||||
-- Image is 64x64, bounds are 200x64
|
||||
-- Should tile 4 times horizontally: (0), (64), (128), (192)
|
||||
ImageRenderer.drawTiled(self.mockImage, 100, 100, 200, 64, "repeat-x", 1, nil)
|
||||
|
||||
-- 3 full tiles + 1 partial tile = 4 draws
|
||||
luaunit.assertTrue(#drawCalls >= 3)
|
||||
|
||||
love.graphics.draw = originalDraw
|
||||
love.graphics.newQuad = originalNewQuad
|
||||
end
|
||||
|
||||
function TestImageTiling:testDrawTiledRepeatY()
|
||||
-- Test repeat-y mode (tiles vertically only)
|
||||
local drawCalls = {}
|
||||
local originalDraw = love.graphics.draw
|
||||
local originalNewQuad = love.graphics.newQuad
|
||||
|
||||
love.graphics.draw = function(...)
|
||||
table.insert(drawCalls, {...})
|
||||
end
|
||||
|
||||
love.graphics.newQuad = function(...)
|
||||
return { type = "quad", ... }
|
||||
end
|
||||
|
||||
-- Image is 64x64, bounds are 64x200
|
||||
-- Should tile 4 times vertically
|
||||
ImageRenderer.drawTiled(self.mockImage, 100, 100, 64, 200, "repeat-y", 1, nil)
|
||||
|
||||
-- 3 full tiles + 1 partial tile = 4 draws
|
||||
luaunit.assertTrue(#drawCalls >= 3)
|
||||
|
||||
love.graphics.draw = originalDraw
|
||||
love.graphics.newQuad = originalNewQuad
|
||||
end
|
||||
|
||||
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, {...})
|
||||
end
|
||||
|
||||
-- Image is 64x64, bounds are 200x200
|
||||
ImageRenderer.drawTiled(self.mockImage, 100, 100, 200, 200, "space", 1, nil)
|
||||
|
||||
-- Should draw multiple tiles with spacing
|
||||
luaunit.assertTrue(#drawCalls > 1)
|
||||
|
||||
love.graphics.draw = originalDraw
|
||||
end
|
||||
|
||||
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, {...})
|
||||
end
|
||||
|
||||
-- Image is 64x64, bounds are 200x200
|
||||
ImageRenderer.drawTiled(self.mockImage, 100, 100, 200, 200, "round", 1, nil)
|
||||
|
||||
-- Should draw tiles with scaling
|
||||
luaunit.assertTrue(#drawCalls > 1)
|
||||
|
||||
love.graphics.draw = originalDraw
|
||||
end
|
||||
|
||||
function TestImageTiling:testDrawTiledWithOpacity()
|
||||
-- Test tiling with opacity
|
||||
local setColorCalls = {}
|
||||
local originalSetColor = love.graphics.setColor
|
||||
|
||||
love.graphics.setColor = function(...)
|
||||
table.insert(setColorCalls, {...})
|
||||
end
|
||||
|
||||
ImageRenderer.drawTiled(self.mockImage, 100, 100, 200, 200, "no-repeat", 0.5, nil)
|
||||
|
||||
-- Should set color with opacity
|
||||
luaunit.assertTrue(#setColorCalls > 0)
|
||||
-- Check that opacity 0.5 was used
|
||||
local found = false
|
||||
for _, call in ipairs(setColorCalls) do
|
||||
if call[4] == 0.5 then
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
luaunit.assertTrue(found)
|
||||
|
||||
love.graphics.setColor = originalSetColor
|
||||
end
|
||||
|
||||
function TestImageTiling:testDrawTiledWithTint()
|
||||
-- Test tiling with tint color
|
||||
local setColorCalls = {}
|
||||
local originalSetColor = love.graphics.setColor
|
||||
|
||||
love.graphics.setColor = function(...)
|
||||
table.insert(setColorCalls, {...})
|
||||
end
|
||||
|
||||
local redTint = Color.new(1, 0, 0, 1)
|
||||
ImageRenderer.drawTiled(self.mockImage, 100, 100, 200, 200, "no-repeat", 1, redTint)
|
||||
|
||||
-- Should set color with tint
|
||||
luaunit.assertTrue(#setColorCalls > 0)
|
||||
-- Check that red tint was used (r=1, g=0, b=0)
|
||||
local found = false
|
||||
for _, call in ipairs(setColorCalls) do
|
||||
if call[1] == 1 and call[2] == 0 and call[3] == 0 then
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
luaunit.assertTrue(found)
|
||||
|
||||
love.graphics.setColor = originalSetColor
|
||||
end
|
||||
|
||||
function TestImageTiling:testElementImageRepeatProperty()
|
||||
-- Test that Element accepts imageRepeat property
|
||||
local Element = require("modules.Element")
|
||||
local utils = require("modules.utils")
|
||||
local Color = require("modules.Color")
|
||||
local Units = require("modules.Units")
|
||||
local LayoutEngine = require("modules.LayoutEngine")
|
||||
local Renderer = require("modules.Renderer")
|
||||
local EventHandler = require("modules.EventHandler")
|
||||
local ImageCache = require("modules.ImageCache")
|
||||
|
||||
local deps = {
|
||||
utils = utils,
|
||||
Color = Color,
|
||||
Units = Units,
|
||||
LayoutEngine = LayoutEngine,
|
||||
Renderer = Renderer,
|
||||
EventHandler = EventHandler,
|
||||
ImageCache = ImageCache,
|
||||
ImageRenderer = ImageRenderer,
|
||||
ErrorHandler = ErrorHandler,
|
||||
}
|
||||
|
||||
local element = Element.new({
|
||||
width = 200,
|
||||
height = 200,
|
||||
imageRepeat = "repeat",
|
||||
}, deps)
|
||||
|
||||
luaunit.assertEquals(element.imageRepeat, "repeat")
|
||||
end
|
||||
|
||||
function TestImageTiling:testElementImageRepeatDefault()
|
||||
-- Test that imageRepeat defaults to "no-repeat"
|
||||
local Element = require("modules.Element")
|
||||
local utils = require("modules.utils")
|
||||
local Color = require("modules.Color")
|
||||
local Units = require("modules.Units")
|
||||
local LayoutEngine = require("modules.LayoutEngine")
|
||||
local Renderer = require("modules.Renderer")
|
||||
local EventHandler = require("modules.EventHandler")
|
||||
local ImageCache = require("modules.ImageCache")
|
||||
|
||||
local deps = {
|
||||
utils = utils,
|
||||
Color = Color,
|
||||
Units = Units,
|
||||
LayoutEngine = LayoutEngine,
|
||||
Renderer = Renderer,
|
||||
EventHandler = EventHandler,
|
||||
ImageCache = ImageCache,
|
||||
ImageRenderer = ImageRenderer,
|
||||
ErrorHandler = ErrorHandler,
|
||||
}
|
||||
|
||||
local element = Element.new({
|
||||
width = 200,
|
||||
height = 200,
|
||||
}, deps)
|
||||
|
||||
luaunit.assertEquals(element.imageRepeat, "no-repeat")
|
||||
end
|
||||
|
||||
function TestImageTiling:testElementSetImageRepeat()
|
||||
-- Test setImageRepeat method
|
||||
local Element = require("modules.Element")
|
||||
local utils = require("modules.utils")
|
||||
local Color = require("modules.Color")
|
||||
local Units = require("modules.Units")
|
||||
local LayoutEngine = require("modules.LayoutEngine")
|
||||
local Renderer = require("modules.Renderer")
|
||||
local EventHandler = require("modules.EventHandler")
|
||||
local ImageCache = require("modules.ImageCache")
|
||||
|
||||
local deps = {
|
||||
utils = utils,
|
||||
Color = Color,
|
||||
Units = Units,
|
||||
LayoutEngine = LayoutEngine,
|
||||
Renderer = Renderer,
|
||||
EventHandler = EventHandler,
|
||||
ImageCache = ImageCache,
|
||||
ImageRenderer = ImageRenderer,
|
||||
ErrorHandler = ErrorHandler,
|
||||
}
|
||||
|
||||
local element = Element.new({
|
||||
width = 200,
|
||||
height = 200,
|
||||
}, deps)
|
||||
|
||||
element:setImageRepeat("repeat-x")
|
||||
luaunit.assertEquals(element.imageRepeat, "repeat-x")
|
||||
end
|
||||
|
||||
function TestImageTiling:testElementImageTintProperty()
|
||||
-- Test that Element accepts imageTint property
|
||||
local Element = require("modules.Element")
|
||||
local utils = require("modules.utils")
|
||||
local Units = require("modules.Units")
|
||||
local LayoutEngine = require("modules.LayoutEngine")
|
||||
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,
|
||||
Units = Units,
|
||||
LayoutEngine = LayoutEngine,
|
||||
Renderer = Renderer,
|
||||
EventHandler = EventHandler,
|
||||
ImageCache = ImageCache,
|
||||
ImageRenderer = ImageRenderer,
|
||||
ErrorHandler = ErrorHandler,
|
||||
}
|
||||
|
||||
local element = Element.new({
|
||||
width = 200,
|
||||
height = 200,
|
||||
imageTint = redTint,
|
||||
}, deps)
|
||||
|
||||
luaunit.assertEquals(element.imageTint, redTint)
|
||||
end
|
||||
|
||||
function TestImageTiling:testElementSetImageTint()
|
||||
-- Test setImageTint method
|
||||
local Element = require("modules.Element")
|
||||
local utils = require("modules.utils")
|
||||
local Units = require("modules.Units")
|
||||
local LayoutEngine = require("modules.LayoutEngine")
|
||||
local Renderer = require("modules.Renderer")
|
||||
local EventHandler = require("modules.EventHandler")
|
||||
local ImageCache = require("modules.ImageCache")
|
||||
|
||||
local deps = {
|
||||
utils = utils,
|
||||
Color = Color,
|
||||
Units = Units,
|
||||
LayoutEngine = LayoutEngine,
|
||||
Renderer = Renderer,
|
||||
EventHandler = EventHandler,
|
||||
ImageCache = ImageCache,
|
||||
ImageRenderer = ImageRenderer,
|
||||
ErrorHandler = ErrorHandler,
|
||||
}
|
||||
|
||||
local element = Element.new({
|
||||
width = 200,
|
||||
height = 200,
|
||||
}, deps)
|
||||
|
||||
local blueTint = Color.new(0, 0, 1, 1)
|
||||
element:setImageTint(blueTint)
|
||||
luaunit.assertEquals(element.imageTint, blueTint)
|
||||
end
|
||||
|
||||
function TestImageTiling:testElementSetImageOpacity()
|
||||
-- Test setImageOpacity method
|
||||
local Element = require("modules.Element")
|
||||
local utils = require("modules.utils")
|
||||
local Color = require("modules.Color")
|
||||
local Units = require("modules.Units")
|
||||
local LayoutEngine = require("modules.LayoutEngine")
|
||||
local Renderer = require("modules.Renderer")
|
||||
local EventHandler = require("modules.EventHandler")
|
||||
local ImageCache = require("modules.ImageCache")
|
||||
|
||||
local deps = {
|
||||
utils = utils,
|
||||
Color = Color,
|
||||
Units = Units,
|
||||
LayoutEngine = LayoutEngine,
|
||||
Renderer = Renderer,
|
||||
EventHandler = EventHandler,
|
||||
ImageCache = ImageCache,
|
||||
ImageRenderer = ImageRenderer,
|
||||
ErrorHandler = ErrorHandler,
|
||||
}
|
||||
|
||||
local element = Element.new({
|
||||
width = 200,
|
||||
height = 200,
|
||||
}, deps)
|
||||
|
||||
element:setImageOpacity(0.7)
|
||||
luaunit.assertEquals(element.imageOpacity, 0.7)
|
||||
end
|
||||
|
||||
-- Run the tests
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
292
testing/__tests__/transform_test.lua
Normal file
292
testing/__tests__/transform_test.lua
Normal file
@@ -0,0 +1,292 @@
|
||||
local luaunit = require("testing.luaunit")
|
||||
require("testing.loveStub")
|
||||
|
||||
local Transform = require("modules.Transform")
|
||||
|
||||
TestTransform = {}
|
||||
|
||||
function TestTransform:setUp()
|
||||
-- Reset state before each test
|
||||
end
|
||||
|
||||
-- Test Transform.new()
|
||||
|
||||
function TestTransform:testNew_DefaultValues()
|
||||
local transform = Transform.new()
|
||||
|
||||
luaunit.assertNotNil(transform)
|
||||
luaunit.assertEquals(transform.rotate, 0)
|
||||
luaunit.assertEquals(transform.scaleX, 1)
|
||||
luaunit.assertEquals(transform.scaleY, 1)
|
||||
luaunit.assertEquals(transform.translateX, 0)
|
||||
luaunit.assertEquals(transform.translateY, 0)
|
||||
luaunit.assertEquals(transform.skewX, 0)
|
||||
luaunit.assertEquals(transform.skewY, 0)
|
||||
luaunit.assertEquals(transform.originX, 0.5)
|
||||
luaunit.assertEquals(transform.originY, 0.5)
|
||||
end
|
||||
|
||||
function TestTransform:testNew_CustomValues()
|
||||
local transform = Transform.new({
|
||||
rotate = math.pi / 4,
|
||||
scaleX = 2,
|
||||
scaleY = 3,
|
||||
translateX = 100,
|
||||
translateY = 200,
|
||||
skewX = 0.1,
|
||||
skewY = 0.2,
|
||||
originX = 0,
|
||||
originY = 1,
|
||||
})
|
||||
|
||||
luaunit.assertAlmostEquals(transform.rotate, math.pi / 4, 0.01)
|
||||
luaunit.assertEquals(transform.scaleX, 2)
|
||||
luaunit.assertEquals(transform.scaleY, 3)
|
||||
luaunit.assertEquals(transform.translateX, 100)
|
||||
luaunit.assertEquals(transform.translateY, 200)
|
||||
luaunit.assertAlmostEquals(transform.skewX, 0.1, 0.01)
|
||||
luaunit.assertAlmostEquals(transform.skewY, 0.2, 0.01)
|
||||
luaunit.assertEquals(transform.originX, 0)
|
||||
luaunit.assertEquals(transform.originY, 1)
|
||||
end
|
||||
|
||||
function TestTransform:testNew_PartialValues()
|
||||
local transform = Transform.new({
|
||||
rotate = math.pi,
|
||||
scaleX = 2,
|
||||
})
|
||||
|
||||
luaunit.assertAlmostEquals(transform.rotate, math.pi, 0.01)
|
||||
luaunit.assertEquals(transform.scaleX, 2)
|
||||
luaunit.assertEquals(transform.scaleY, 1) -- default
|
||||
luaunit.assertEquals(transform.translateX, 0) -- default
|
||||
end
|
||||
|
||||
function TestTransform:testNew_EmptyProps()
|
||||
local transform = Transform.new({})
|
||||
|
||||
-- Should use all defaults
|
||||
luaunit.assertEquals(transform.rotate, 0)
|
||||
luaunit.assertEquals(transform.scaleX, 1)
|
||||
luaunit.assertEquals(transform.originX, 0.5)
|
||||
end
|
||||
|
||||
function TestTransform:testNew_NilProps()
|
||||
local transform = Transform.new(nil)
|
||||
|
||||
-- Should use all defaults
|
||||
luaunit.assertEquals(transform.rotate, 0)
|
||||
luaunit.assertEquals(transform.scaleX, 1)
|
||||
end
|
||||
|
||||
-- Test Transform.lerp()
|
||||
|
||||
function TestTransform:testLerp_MidPoint()
|
||||
local from = Transform.new({ rotate = 0, scaleX = 1, scaleY = 1 })
|
||||
local to = Transform.new({ rotate = math.pi, scaleX = 2, scaleY = 3 })
|
||||
|
||||
local result = Transform.lerp(from, to, 0.5)
|
||||
|
||||
luaunit.assertAlmostEquals(result.rotate, math.pi / 2, 0.01)
|
||||
luaunit.assertAlmostEquals(result.scaleX, 1.5, 0.01)
|
||||
luaunit.assertAlmostEquals(result.scaleY, 2, 0.01)
|
||||
end
|
||||
|
||||
function TestTransform:testLerp_StartPoint()
|
||||
local from = Transform.new({ rotate = 0, scaleX = 1 })
|
||||
local to = Transform.new({ rotate = math.pi, scaleX = 2 })
|
||||
|
||||
local result = Transform.lerp(from, to, 0)
|
||||
|
||||
luaunit.assertAlmostEquals(result.rotate, 0, 0.01)
|
||||
luaunit.assertAlmostEquals(result.scaleX, 1, 0.01)
|
||||
end
|
||||
|
||||
function TestTransform:testLerp_EndPoint()
|
||||
local from = Transform.new({ rotate = 0, scaleX = 1 })
|
||||
local to = Transform.new({ rotate = math.pi, scaleX = 2 })
|
||||
|
||||
local result = Transform.lerp(from, to, 1)
|
||||
|
||||
luaunit.assertAlmostEquals(result.rotate, math.pi, 0.01)
|
||||
luaunit.assertAlmostEquals(result.scaleX, 2, 0.01)
|
||||
end
|
||||
|
||||
function TestTransform:testLerp_AllProperties()
|
||||
local from = Transform.new({
|
||||
rotate = 0,
|
||||
scaleX = 1,
|
||||
scaleY = 1,
|
||||
translateX = 0,
|
||||
translateY = 0,
|
||||
skewX = 0,
|
||||
skewY = 0,
|
||||
originX = 0,
|
||||
originY = 0,
|
||||
})
|
||||
|
||||
local to = Transform.new({
|
||||
rotate = math.pi,
|
||||
scaleX = 2,
|
||||
scaleY = 3,
|
||||
translateX = 100,
|
||||
translateY = 200,
|
||||
skewX = 0.2,
|
||||
skewY = 0.4,
|
||||
originX = 1,
|
||||
originY = 1,
|
||||
})
|
||||
|
||||
local result = Transform.lerp(from, to, 0.5)
|
||||
|
||||
luaunit.assertAlmostEquals(result.rotate, math.pi / 2, 0.01)
|
||||
luaunit.assertAlmostEquals(result.scaleX, 1.5, 0.01)
|
||||
luaunit.assertAlmostEquals(result.scaleY, 2, 0.01)
|
||||
luaunit.assertAlmostEquals(result.translateX, 50, 0.01)
|
||||
luaunit.assertAlmostEquals(result.translateY, 100, 0.01)
|
||||
luaunit.assertAlmostEquals(result.skewX, 0.1, 0.01)
|
||||
luaunit.assertAlmostEquals(result.skewY, 0.2, 0.01)
|
||||
luaunit.assertAlmostEquals(result.originX, 0.5, 0.01)
|
||||
luaunit.assertAlmostEquals(result.originY, 0.5, 0.01)
|
||||
end
|
||||
|
||||
function TestTransform:testLerp_InvalidInputs()
|
||||
-- Should handle nil gracefully
|
||||
local result = Transform.lerp(nil, nil, 0.5)
|
||||
|
||||
luaunit.assertNotNil(result)
|
||||
luaunit.assertEquals(result.rotate, 0)
|
||||
luaunit.assertEquals(result.scaleX, 1)
|
||||
end
|
||||
|
||||
function TestTransform:testLerp_ClampT()
|
||||
local from = Transform.new({ scaleX = 1 })
|
||||
local to = Transform.new({ scaleX = 2 })
|
||||
|
||||
-- Test t > 1
|
||||
local result1 = Transform.lerp(from, to, 1.5)
|
||||
luaunit.assertAlmostEquals(result1.scaleX, 2, 0.01)
|
||||
|
||||
-- Test t < 0
|
||||
local result2 = Transform.lerp(from, to, -0.5)
|
||||
luaunit.assertAlmostEquals(result2.scaleX, 1, 0.01)
|
||||
end
|
||||
|
||||
function TestTransform:testLerp_InvalidT()
|
||||
local from = Transform.new({ scaleX = 1 })
|
||||
local to = Transform.new({ scaleX = 2 })
|
||||
|
||||
-- Test NaN
|
||||
local result1 = Transform.lerp(from, to, 0 / 0)
|
||||
luaunit.assertAlmostEquals(result1.scaleX, 1, 0.01) -- Should default to 0
|
||||
|
||||
-- Test Infinity
|
||||
local result2 = Transform.lerp(from, to, math.huge)
|
||||
luaunit.assertAlmostEquals(result2.scaleX, 2, 0.01) -- Should clamp to 1
|
||||
end
|
||||
|
||||
-- Test Transform.isIdentity()
|
||||
|
||||
function TestTransform:testIsIdentity_True()
|
||||
local transform = Transform.new()
|
||||
luaunit.assertTrue(Transform.isIdentity(transform))
|
||||
end
|
||||
|
||||
function TestTransform:testIsIdentity_Nil()
|
||||
luaunit.assertTrue(Transform.isIdentity(nil))
|
||||
end
|
||||
|
||||
function TestTransform:testIsIdentity_FalseRotate()
|
||||
local transform = Transform.new({ rotate = 0.1 })
|
||||
luaunit.assertFalse(Transform.isIdentity(transform))
|
||||
end
|
||||
|
||||
function TestTransform:testIsIdentity_FalseScale()
|
||||
local transform = Transform.new({ scaleX = 2 })
|
||||
luaunit.assertFalse(Transform.isIdentity(transform))
|
||||
end
|
||||
|
||||
function TestTransform:testIsIdentity_FalseTranslate()
|
||||
local transform = Transform.new({ translateX = 10 })
|
||||
luaunit.assertFalse(Transform.isIdentity(transform))
|
||||
end
|
||||
|
||||
function TestTransform:testIsIdentity_FalseSkew()
|
||||
local transform = Transform.new({ skewX = 0.1 })
|
||||
luaunit.assertFalse(Transform.isIdentity(transform))
|
||||
end
|
||||
|
||||
-- Test Transform.clone()
|
||||
|
||||
function TestTransform:testClone_AllProperties()
|
||||
local original = Transform.new({
|
||||
rotate = math.pi / 4,
|
||||
scaleX = 2,
|
||||
scaleY = 3,
|
||||
translateX = 100,
|
||||
translateY = 200,
|
||||
skewX = 0.1,
|
||||
skewY = 0.2,
|
||||
originX = 0.25,
|
||||
originY = 0.75,
|
||||
})
|
||||
|
||||
local clone = Transform.clone(original)
|
||||
|
||||
luaunit.assertAlmostEquals(clone.rotate, math.pi / 4, 0.01)
|
||||
luaunit.assertEquals(clone.scaleX, 2)
|
||||
luaunit.assertEquals(clone.scaleY, 3)
|
||||
luaunit.assertEquals(clone.translateX, 100)
|
||||
luaunit.assertEquals(clone.translateY, 200)
|
||||
luaunit.assertAlmostEquals(clone.skewX, 0.1, 0.01)
|
||||
luaunit.assertAlmostEquals(clone.skewY, 0.2, 0.01)
|
||||
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)
|
||||
end
|
||||
|
||||
function TestTransform:testClone_Nil()
|
||||
local clone = Transform.clone(nil)
|
||||
|
||||
luaunit.assertNotNil(clone)
|
||||
luaunit.assertEquals(clone.rotate, 0)
|
||||
luaunit.assertEquals(clone.scaleX, 1)
|
||||
end
|
||||
|
||||
function TestTransform:testClone_Mutation()
|
||||
local original = Transform.new({ rotate = 0 })
|
||||
local clone = Transform.clone(original)
|
||||
|
||||
-- Mutate clone
|
||||
clone.rotate = math.pi
|
||||
|
||||
-- Original should be unchanged
|
||||
luaunit.assertEquals(original.rotate, 0)
|
||||
luaunit.assertAlmostEquals(clone.rotate, math.pi, 0.01)
|
||||
end
|
||||
|
||||
-- Integration Tests
|
||||
|
||||
function TestTransform:testTransformAnimation()
|
||||
local Animation = require("modules.Animation")
|
||||
local Transform = require("modules.Transform")
|
||||
|
||||
local anim = Animation.new({
|
||||
duration = 1,
|
||||
start = { transform = Transform.new({ rotate = 0, scaleX = 1 }) },
|
||||
final = { transform = Transform.new({ rotate = math.pi, scaleX = 2 }) },
|
||||
})
|
||||
|
||||
anim:setTransformModule(Transform)
|
||||
anim:update(0.5)
|
||||
|
||||
local result = anim:interpolate()
|
||||
|
||||
luaunit.assertNotNil(result.transform)
|
||||
luaunit.assertAlmostEquals(result.transform.rotate, math.pi / 2, 0.01)
|
||||
luaunit.assertAlmostEquals(result.transform.scaleX, 1.5, 0.01)
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
Reference in New Issue
Block a user