From 5a299da930de7148559e5d9c3b11c208c45c54c8 Mon Sep 17 00:00:00 2001 From: SirLynix Date: Sat, 12 Aug 2023 14:43:59 +0200 Subject: [PATCH] Fix unit tests --- tests/UnitTests/Engine/Core/SerializationTest.cpp | 4 ++++ tests/UnitTests/Engine/Physics2D/RigidBody2DTest.cpp | 11 ++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/UnitTests/Engine/Core/SerializationTest.cpp b/tests/UnitTests/Engine/Core/SerializationTest.cpp index 5b061b91c..3d05db793 100644 --- a/tests/UnitTests/Engine/Core/SerializationTest.cpp +++ b/tests/UnitTests/Engine/Core/SerializationTest.cpp @@ -117,9 +117,13 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]") { context.stream->SetCursorPos(0); Nz::OrientedBoxf zeroOBB = Nz::OrientedBoxf::Zero(); + zeroOBB.Update(Nz::Vector3f::Zero()); + Nz::OrientedBoxf copy(zeroOBB); REQUIRE(Serialize(context, zeroOBB)); zeroOBB = Nz::OrientedBoxf(Nz::Boxf(1, 1, 1, 1, 1, 1)); // Random values + zeroOBB.Update(Nz::Vector3f::Zero()); + REQUIRE(zeroOBB != copy); context.stream->SetCursorPos(0); REQUIRE(Unserialize(context, &zeroOBB)); diff --git a/tests/UnitTests/Engine/Physics2D/RigidBody2DTest.cpp b/tests/UnitTests/Engine/Physics2D/RigidBody2DTest.cpp index 90c698e3a..a03477498 100644 --- a/tests/UnitTests/Engine/Physics2D/RigidBody2DTest.cpp +++ b/tests/UnitTests/Engine/Physics2D/RigidBody2DTest.cpp @@ -15,6 +15,7 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]") { Nz::ChipmunkPhysWorld2D world; world.SetMaxStepCount(std::numeric_limits::max()); + world.SetStepSize(Nz::Time::TickDuration(200)); //< FIXME: Tests fail on Linux with default step size Nz::Vector2f positionAABB(3.f, 4.f); Nz::Rectf aabb(positionAABB.x, positionAABB.y, 1.f, 2.f); @@ -182,20 +183,20 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]") THEN("We expect those to be true") { - CHECK(body.GetAngularVelocity() == angularSpeed); - CHECK(body.GetRotation() == angularSpeed); + CHECK(body.GetAngularVelocity().ApproxEqual(angularSpeed)); + CHECK(body.GetRotation().ApproxEqual(angularSpeed)); CHECK(body.GetAABB().ApproxEqual(Nz::Rectf(-6.f, 3.f, 2.f, 1.f), 0.00001f)); world.Step(Nz::Time::Second()); - CHECK(body.GetRotation() == 2.f * angularSpeed); + CHECK(body.GetRotation().ApproxEqual(2.f * angularSpeed)); CHECK(body.GetAABB().ApproxEqual(Nz::Rectf(-4.f, -6.f, 1.f, 2.f), 0.00001f)); world.Step(Nz::Time::Second()); - CHECK(body.GetRotation() == 3.f * angularSpeed); + CHECK(body.GetRotation().ApproxEqual(3.f * angularSpeed)); CHECK(body.GetAABB().ApproxEqual(Nz::Rectf(4.f, -4.f, 2.f, 1.f), 0.00001f)); world.Step(Nz::Time::Second()); - CHECK(body.GetRotation() == 4.f * angularSpeed); + CHECK(body.GetRotation().ApproxEqual(4.f * angularSpeed)); } }