lovexp/asteroids/test_phys.lua
Donald Ball f5df911707 fix atan issue
the love2d that I'm using doesn't have the new atan arity lol
2025-11-17 20:21:42 -05:00

49 lines
1.4 KiB
Lua

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 }
)
end
os.exit(t.LuaUnit.run())