Fix unit tests (WIP)

This commit is contained in:
Lynix 2019-03-26 19:05:41 +01:00
parent e00d0baa00
commit 00ca0248c6
1 changed files with 25 additions and 8 deletions

View File

@ -1,6 +1,7 @@
#include <Nazara/Physics2D/RigidBody2D.hpp>
#include <Nazara/Physics2D/PhysWorld2D.hpp>
#include <Catch/catch.hpp>
#include <iostream>
#include <limits>
Nz::RigidBody2D CreateBody(Nz::PhysWorld2D& world);
@ -93,6 +94,7 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
std::vector<Nz::RigidBody2D> tmp;
tmp.push_back(CreateBody(world));
tmp.push_back(CreateBody(world));
world.Step(1.f);
THEN("They should be valid")
@ -112,11 +114,14 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
Nz::Rectf aabb(positionAABB.x, positionAABB.y, 1.f, 2.f);
Nz::Collider2DRef box = Nz::BoxCollider2D::New(aabb);
float mass = 1.f;
Nz::RigidBody2D body(&world, mass, box);
Nz::RigidBody2D body(&world, mass);
body.SetGeom(box, true, false);
bool userData = false;
body.SetUserdata(&userData);
Nz::Vector2f position = Nz::Vector2f::Zero();
body.SetPosition(position);
world.Step(1.f);
@ -126,7 +131,7 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
{
CHECK(body.GetAABB() == aabb);
CHECK(body.GetAngularVelocity() == 0.f);
CHECK(body.GetMassCenter() == Nz::Vector2f::Zero());
CHECK(body.GetMassCenter(Nz::CoordSys_Global) == position);
CHECK(body.GetGeom() == box);
CHECK(body.GetMass() == Approx(mass));
CHECK(body.GetPosition() == position);
@ -150,7 +155,7 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
{
aabb.Translate(velocity);
CHECK(body.GetAABB() == aabb);
CHECK(body.GetMassCenter() == Nz::Vector2f::Zero());
CHECK(body.GetMassCenter(Nz::CoordSys_Global) == position);
CHECK(body.GetPosition() == position);
CHECK(body.GetVelocity() == velocity);
}
@ -211,7 +216,9 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
float radius = 5.f;
Nz::Collider2DRef circle = Nz::CircleCollider2D::New(radius, position);
float mass = 1.f;
Nz::RigidBody2D body(&world, mass, circle);
Nz::RigidBody2D body(&world, mass);
body.SetGeom(circle, true, false);
world.Step(1.f);
WHEN("We ask for the aabb of the circle")
@ -240,7 +247,9 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
Nz::CompoundCollider2DRef compound = Nz::CompoundCollider2D::New(colliders);
float mass = 1.f;
Nz::RigidBody2D body(&world, mass, compound);
Nz::RigidBody2D body(&world, mass);
body.SetGeom(compound, true, false);
world.Step(1.f);
WHEN("We ask for the aabb of the compound")
@ -267,7 +276,9 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
Nz::SparsePtr<const Nz::Vector2f> sparsePtr(vertices.data());
Nz::ConvexCollider2DRef convex = Nz::ConvexCollider2D::New(sparsePtr, vertices.size());
float mass = 1.f;
Nz::RigidBody2D body(&world, mass, convex);
Nz::RigidBody2D body(&world, mass);
body.SetGeom(convex, true, false);
world.Step(1.f);
WHEN("We ask for the aabb of the convex")
@ -289,7 +300,9 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]")
Nz::Vector2f positionB(1.f, -4.f);
Nz::Collider2DRef segment = Nz::SegmentCollider2D::New(positionA, positionB, 0.f);
float mass = 1.f;
Nz::RigidBody2D body(&world, mass, segment);
Nz::RigidBody2D body(&world, mass);
body.SetGeom(segment, true, false);
world.Step(1.f);
WHEN("We ask for the aabb of the segment")
@ -309,7 +322,11 @@ Nz::RigidBody2D CreateBody(Nz::PhysWorld2D& world)
Nz::Rectf aabb(positionAABB.x, positionAABB.y, 1.f, 2.f);
Nz::Collider2DRef box = Nz::BoxCollider2D::New(aabb);
float mass = 1.f;
return Nz::RigidBody2D(&world, mass, box);
Nz::RigidBody2D body(&world, mass, box);
body.SetPosition(Nz::Vector2f::Zero());
return body;
}
void EQUALITY(const Nz::RigidBody2D& left, const Nz::RigidBody2D& right)