Fix unit tests
This commit is contained in:
@@ -80,7 +80,7 @@ SCENARIO("PhysWorld2D", "[PHYSICS2D][PHYSWORLD2D]")
|
||||
{
|
||||
const Nz::PhysWorld2D::RaycastHit& result = results[i];
|
||||
CHECK(result.nearestBody == &bodies[i]);
|
||||
CHECK(result.fraction == Approx(i / 4.f).epsilon(0.1f));
|
||||
CHECK(result.fraction == Approx(i / 4.f).margin(0.1f));
|
||||
CHECK(result.hitPos == Nz::Vector2f(0.f, i * 10.f));
|
||||
CHECK(result.hitNormal == -Nz::Vector2f::UnitY());
|
||||
}
|
||||
@@ -171,13 +171,13 @@ SCENARIO("PhysWorld2D", "[PHYSICS2D][PHYSWORLD2D]")
|
||||
world.Step(0.1f);
|
||||
CHECK(statusTriggerCollision == 11);
|
||||
|
||||
CHECK(character.GetPosition().x == Approx(3.1f).epsilon(0.01f));
|
||||
CHECK(character.GetPosition().x == Approx(3.1f).margin(0.01f));
|
||||
|
||||
for (int i = 0; i != 9; ++i)
|
||||
world.Step(0.1f);
|
||||
CHECK(character.GetPosition().x == Approx(4.f).epsilon(0.01f));
|
||||
CHECK(character.GetPosition().x == Approx(4.f).margin(0.01f));
|
||||
world.Step(0.1f);
|
||||
CHECK(character.GetPosition().x == Approx(4.f).epsilon(0.01f));
|
||||
CHECK(character.GetPosition().x == Approx(4.f).margin(0.01f));
|
||||
CHECK(statusWallCollision == 1); // It should be close to the wall
|
||||
|
||||
character.SetVelocity(Nz::Vector2f(-2.f, 0.f));
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
Nz::RigidBody2D CreateBody(Nz::PhysWorld2D& world);
|
||||
void EQUALITY(const Nz::RigidBody2D& left, const Nz::RigidBody2D& right);
|
||||
void EQUALITY(const Nz::Rectf& left, const Nz::Rectf& right);
|
||||
|
||||
SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
|
||||
{
|
||||
@@ -65,16 +66,15 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
|
||||
WHEN("We set a new geometry")
|
||||
{
|
||||
float radius = 5.f;
|
||||
Nz::Vector2f positionCircle(0.f, 0.f);
|
||||
Nz::Collider2DRef circle = Nz::CircleCollider2D::New(radius, position);
|
||||
body.SetGeom(circle);
|
||||
body.SetGeom(Nz::CircleCollider2D::New(radius));
|
||||
|
||||
world.Step(1.f);
|
||||
|
||||
THEN("The aabb should be updated")
|
||||
{
|
||||
position = body.GetPosition();
|
||||
Nz::Rectf circleAABB(position.x - radius, position.y - radius, 2.f * radius, 2.f* radius);
|
||||
REQUIRE(body.GetAABB() == circleAABB);
|
||||
EQUALITY(body.GetAABB(), circleAABB);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -316,3 +316,11 @@ void EQUALITY(const Nz::RigidBody2D& left, const Nz::RigidBody2D& right)
|
||||
CHECK(left.GetUserdata() == right.GetUserdata());
|
||||
CHECK(left.GetVelocity() == right.GetVelocity());
|
||||
}
|
||||
|
||||
void EQUALITY(const Nz::Rectf& left, const Nz::Rectf& right)
|
||||
{
|
||||
CHECK(left.x == Approx(right.x));
|
||||
CHECK(left.y == Approx(right.y));
|
||||
CHECK(left.width == Approx(right.width));
|
||||
CHECK(left.height == Approx(right.height));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user