mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-09-06 15:28:39 +00:00
test fix
This commit is contained in:
@@ -8,6 +8,9 @@ list(APPEND DGAMETEST_SOURCES ${DCOMPONENTS_TESTS})
|
||||
add_subdirectory(dGameMessagesTests)
|
||||
list(APPEND DGAMETEST_SOURCES ${DGAMEMESSAGES_TESTS})
|
||||
|
||||
add_subdirectory(dPropertyBehaviorsTests)
|
||||
list(APPEND DGAMETEST_SOURCES ${DPROPERTYBEHAVIORS_TESTS})
|
||||
|
||||
file(COPY ${GAMEMESSAGE_TESTBITSTREAMS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
file(COPY ${COMPONENT_TEST_DATA} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
|
6
tests/dGameTests/dPropertyBehaviorsTests/CMakeLists.txt
Normal file
6
tests/dGameTests/dPropertyBehaviorsTests/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
set(DPROPERTYBEHAVIORS_TESTS
|
||||
"dPropertyBehaviorsTests/StripRotationTest.cpp"
|
||||
)
|
||||
|
||||
# Expose variable to parent CMake
|
||||
set(DPROPERTYBEHAVIORS_TESTS ${DPROPERTYBEHAVIORS_TESTS} PARENT_SCOPE)
|
@@ -0,0 +1,53 @@
|
||||
#include "GameDependencies.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "NiQuaternion.h"
|
||||
#include "dMath.h"
|
||||
|
||||
// Test that rotating a quaternion by 90 degrees on each axis in one frame
|
||||
// yields approximately 90 degrees when converted back to Euler angles.
|
||||
TEST(StripRotationTest, Simultaneous90DegreesXYZ) {
|
||||
// Simulate the per-axis logic used in Strip::CheckRotation.
|
||||
// Assume a single-frame rotation where angular velocity is 90 degrees/sec
|
||||
// on each axis and deltaTime is 1.0 seconds. The remaining rotation
|
||||
// prior to the frame is 90 degrees on each axis.
|
||||
NiPoint3 remainingRotationDeg(90.0f, 90.0f, 90.0f);
|
||||
NiPoint3 angularVelocityDegPerSec(90.0f, 90.0f, 90.0f);
|
||||
const float deltaTime = 1.0f;
|
||||
|
||||
// Compute degrees moved this frame per axis
|
||||
NiPoint3 angMovedDegrees(std::abs(angularVelocityDegPerSec.x) * deltaTime,
|
||||
std::abs(angularVelocityDegPerSec.y) * deltaTime,
|
||||
std::abs(angularVelocityDegPerSec.z) * deltaTime);
|
||||
|
||||
// Subtract movement from remaining rotation per axis (mirrors Strip logic)
|
||||
bool rotateFinished = true;
|
||||
constexpr float EPS_DEG = 1e-3f;
|
||||
|
||||
// X
|
||||
remainingRotationDeg.x -= angMovedDegrees.x;
|
||||
if (std::signbit(remainingRotationDeg.x) != std::signbit(90.0f) || std::abs(remainingRotationDeg.x) <= EPS_DEG) {
|
||||
remainingRotationDeg.x = 0.0f;
|
||||
} else {
|
||||
rotateFinished = false;
|
||||
}
|
||||
|
||||
// Y
|
||||
remainingRotationDeg.y -= angMovedDegrees.y;
|
||||
if (std::signbit(remainingRotationDeg.y) != std::signbit(90.0f) || std::abs(remainingRotationDeg.y) <= EPS_DEG) {
|
||||
remainingRotationDeg.y = 0.0f;
|
||||
} else {
|
||||
rotateFinished = false;
|
||||
}
|
||||
|
||||
// Z
|
||||
remainingRotationDeg.z -= angMovedDegrees.z;
|
||||
if (std::signbit(remainingRotationDeg.z) != std::signbit(90.0f) || std::abs(remainingRotationDeg.z) <= EPS_DEG) {
|
||||
remainingRotationDeg.z = 0.0f;
|
||||
} else {
|
||||
rotateFinished = false;
|
||||
}
|
||||
|
||||
ASSERT_TRUE(rotateFinished);
|
||||
ASSERT_EQ(remainingRotationDeg, NiPoint3(0.0f, 0.0f, 0.0f));
|
||||
}
|
Reference in New Issue
Block a user