Add test to make sure player rotation does not lead to nan

pull/3236/head
elsid 6 months ago
parent 75d9ab4d57
commit 323a8355d5
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -97,6 +97,30 @@ testing.registerLocalTest('playerPitchAndYawRotation',
testing.expectEqualWithDelta(gamma2, math.rad(-16), 0.05, 'Incorrect gamma rotation in ZYX convention') testing.expectEqualWithDelta(gamma2, math.rad(-16), 0.05, 'Incorrect gamma rotation in ZYX convention')
end) end)
testing.registerLocalTest('playerRotation',
function()
local rotation = math.sqrt(2)
local endTime = core.getSimulationTime() + 3
while core.getSimulationTime() < endTime do
self.controls.jump = false
self.controls.run = true
self.controls.movement = 0
self.controls.sideMovement = 0
self.controls.pitchChange = rotation
self.controls.yawChange = rotation
coroutine.yield()
local alpha1, gamma1 = self.rotation:getAnglesXZ()
testing.expectThat(alpha1, testing.isNotNan(), 'Alpha rotation in XZ convention is nan')
testing.expectThat(gamma1, testing.isNotNan(), 'Gamma rotation in XZ convention is nan')
local alpha2, beta2, gamma2 = self.rotation:getAnglesZYX()
testing.expectThat(alpha2, testing.isNotNan(), 'Alpha rotation in ZYX convention is nan')
testing.expectThat(beta2, testing.isNotNan(), 'Beta rotation in ZYX convention is nan')
testing.expectThat(gamma2, testing.isNotNan(), 'Gamma rotation in ZYX convention is nan')
end
end)
testing.registerLocalTest('playerForwardRunning', testing.registerLocalTest('playerForwardRunning',
function() function()
local startPos = self.position local startPos = self.position

@ -225,6 +225,10 @@ tests = {
initPlayer() initPlayer()
testing.runLocalTest(player, 'playerPitchAndYawRotation') testing.runLocalTest(player, 'playerPitchAndYawRotation')
end}, end},
{'rotating player should not lead to nan rotation', function()
initPlayer()
testing.runLocalTest(player, 'playerRotation')
end},
{'playerForwardRunning', function() {'playerForwardRunning', function()
initPlayer() initPlayer()
testing.runLocalTest(player, 'playerForwardRunning') testing.runLocalTest(player, 'playerForwardRunning')

@ -133,6 +133,20 @@ function M.elementsAreArray(expected)
end end
end end
---
-- Matcher verifying that given number is not a nan.
-- @function isNotNan
-- @usage
-- expectThat(value, isNotNan())
function M.isNotNan(expected)
return function(actual)
if actual ~= actual then
return 'actual value is nan, expected to be not nan'
end
return ''
end
end
--- ---
-- Verifies that given value matches provided matcher. -- Verifies that given value matches provided matcher.
-- @function expectThat -- @function expectThat

Loading…
Cancel
Save