lovexp/asteroids/test_phys.lua

50 lines
1.4 KiB
Lua
Raw Normal View History

2025-11-16 22:51:51 -05:00
t = require('luaunit')
local phys = require('phys')
function TestUpdate()
local actor = { x = 0, y = 0, speed = 1, angle = math.pi }
phys.update(actor, 0.1)
t.assertAlmostEquals(
actor,
{ x = -0.1, y = 0, speed = 1, angle = math.pi })
end
function TestApply()
local actor = { x = 0, y = 0, speed = 1, angle = math.pi }
phys.apply(actor, { speed = 1, angle = 0 })
t.assertAlmostEquals(
{ x = actor.x, y = actor.y, speed = actor.speed },
{ x = 0, y = 0, speed = 0 })
phys.apply(actor, { speed = 1, angle = math.pi })
t.assertAlmostEquals(
actor,
{ x = 0, y = 0, speed = 1, angle = math.pi }
)
phys.apply(actor, { speed = 1, angle = math.pi / 2 })
t.assertAlmostEquals(
actor,
{ x = 0, y = 0, speed = math.sqrt(2), angle = math.pi * 3 / 4 })
actor = { x = 0, y = 0, speed = 0, angle = 0 }
phys.apply(actor, { speed = 1, angle = math.pi / 2 })
t.assertAlmostEquals(
actor,
{ x = 0, y = 0, speed = 1, angle = math.pi / 2 })
phys.apply(actor, { speed = 1, angle = math.pi / 2 })
t.assertAlmostEquals(
actor,
{ x = 0, y = 0, speed = 2, angle = math.pi / 2 })
phys.apply(actor, { speed = 1, angle = math.pi })
t.assertAlmostEquals(
actor,
{ x = 0, y = 0, speed = 0, angle = 0 }
2025-11-16 22:51:51 -05:00
)
end
os.exit(t.LuaUnit.run())