From 79c126eac903b4c3784f59ce5500e085981b602d Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Sat, 9 Aug 2014 10:27:41 +0200 Subject: [PATCH] Add name in unit tests and fix some issues in Point Inside test --- test/Test.cpp | 15 +++++--- test/Test.h | 5 ++- test/TestSuite.cpp | 7 ++-- test/main.cpp | 16 ++++---- test/tests/collision/TestPointInside.h | 49 +++++++++++++------------ test/tests/collision/TestRaycast.h | 3 +- test/tests/mathematics/TestMatrix2x2.h | 4 +- test/tests/mathematics/TestMatrix3x3.h | 5 ++- test/tests/mathematics/TestQuaternion.h | 2 +- test/tests/mathematics/TestTransform.h | 2 +- test/tests/mathematics/TestVector2.h | 2 +- test/tests/mathematics/TestVector3.h | 2 +- 12 files changed, 61 insertions(+), 51 deletions(-) diff --git a/test/Test.cpp b/test/Test.cpp index 03c64314..6208d8fe 100644 --- a/test/Test.cpp +++ b/test/Test.cpp @@ -26,11 +26,13 @@ // Libraries #include "Test.h" #include +#include using namespace reactphysics3d; /// Constructor -Test::Test(std::ostream* stream) : mOutputStream(stream), mNbPassedTests(0), mNbFailedTests(0) { +Test::Test(const std::string& name, std::ostream* stream) + : mName(name), mOutputStream(stream), mNbPassedTests(0), mNbFailedTests(0) { } @@ -64,7 +66,7 @@ void Test::applyFail(const std::string& testText, const char* filename, long lin if (mOutputStream) { // Display the failure message - *mOutputStream << typeid(*this).name() << "failure : (" << testText << "), " << + *mOutputStream << mName << "failure : (" << testText << "), " << filename << "(line " << lineNumber << ")" << std::endl; } @@ -76,10 +78,11 @@ void Test::applyFail(const std::string& testText, const char* filename, long lin long Test::report() const { if(mOutputStream) { - *mOutputStream << "Test \"" << - typeid(*this).name() - << "\":\n\tPassed: " << mNbPassedTests << "\tFailed: " << - mNbFailedTests << std::endl; + *mOutputStream << std::left << std::setw(30) << std::setfill(' ') + << "Test " + mName + " :" << std::setw(10) << "Passed: " + << std::setw(8) << mNbPassedTests + << std::setw(13) << "Failed: " + << std::setw(8) << mNbFailedTests << std::endl; } // Return the number of failed tests diff --git a/test/Test.h b/test/Test.h index 0d6106ba..e2ee70da 100644 --- a/test/Test.h +++ b/test/Test.h @@ -50,6 +50,9 @@ class Test { // ---------- Attributes ---------- // + /// Name of the test + std::string mName; + /// Number of tests that passed long mNbPassedTests; @@ -87,7 +90,7 @@ class Test { // ---------- Methods ---------- // /// Constructor - Test(std::ostream* stream = &std::cout); + Test(const std::string& name, std::ostream* stream = &std::cout); /// Destructor virtual ~Test(); diff --git a/test/TestSuite.cpp b/test/TestSuite.cpp index f8d97363..72ecceed 100644 --- a/test/TestSuite.cpp +++ b/test/TestSuite.cpp @@ -111,9 +111,9 @@ long TestSuite::report() const { if (mOutputStream != NULL) { long nbFailedTests = 0; - *mOutputStream << "Test Suite \"" << mName << "\"\n====="; + *mOutputStream << "Test Suite \"" << mName << "\"\n"; size_t i; - for (i=0; i < mName.size(); i++) { + for (i=0; i < 70; i++) { *mOutputStream << "="; } *mOutputStream << "=" << std::endl; @@ -121,8 +121,7 @@ long TestSuite::report() const { assert(mTests[i] != NULL); nbFailedTests += mTests[i]->report(); } - *mOutputStream << "====="; - for (i=0; i < mName.size(); i++) { + for (i=0; i < 70; i++) { *mOutputStream << "="; } *mOutputStream << "=" << std::endl; diff --git a/test/main.cpp b/test/main.cpp index fbbaec78..d8934b2a 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -42,17 +42,17 @@ int main() { // ---------- Mathematics tests ---------- // - testSuite.addTest(new TestVector2); - testSuite.addTest(new TestVector3); - testSuite.addTest(new TestTransform); - testSuite.addTest(new TestQuaternion); - testSuite.addTest(new TestMatrix3x3); - testSuite.addTest(new TestMatrix2x2); + testSuite.addTest(new TestVector2("Vector2")); + testSuite.addTest(new TestVector3("Vector3")); + testSuite.addTest(new TestTransform("Transform")); + testSuite.addTest(new TestQuaternion("Quaternion")); + testSuite.addTest(new TestMatrix3x3("Matrix3x3")); + testSuite.addTest(new TestMatrix2x2("Matrix2x2")); // ---------- Collision Detection tests ---------- // - testSuite.addTest(new TestPointInside); - testSuite.addTest(new TestRaycast); + testSuite.addTest(new TestPointInside("Is Point Inside")); + testSuite.addTest(new TestRaycast("Raycasting")); // Run the tests testSuite.run(); diff --git a/test/tests/collision/TestPointInside.h b/test/tests/collision/TestPointInside.h index e0805733..325b20eb 100644 --- a/test/tests/collision/TestPointInside.h +++ b/test/tests/collision/TestPointInside.h @@ -81,7 +81,7 @@ class TestPointInside : public Test { // ---------- Methods ---------- // /// Constructor - TestPointInside() { + TestPointInside(const std::string& name) : Test(name) { // Create the world mWorld = new CollisionWorld(); @@ -89,7 +89,7 @@ class TestPointInside : public Test { // Body transform Vector3 position(-3, 2, 7); Quaternion orientation(PI / 5, PI / 6, PI / 7); - mBodyTransform = Transform(position, orientation); + //mBodyTransform = Transform(position, orientation); // TODO : Uncomment this // Create the bodies mBoxBody = mWorld->createCollisionBody(mBodyTransform); @@ -99,11 +99,12 @@ class TestPointInside : public Test { mConvexMeshBody = mWorld->createCollisionBody(mBodyTransform); mConvexMeshBodyEdgesInfo = mWorld->createCollisionBody(mBodyTransform); mCylinderBody = mWorld->createCollisionBody(mBodyTransform); + mCompoundBody = mWorld->createCollisionBody(mBodyTransform); // Collision shape transform Vector3 shapePosition(1, -4, -3); Quaternion shapeOrientation(3 * PI / 6 , -PI / 8, PI / 3); - mShapeTransform = Transform(shapePosition, shapeOrientation); + //mShapeTransform = Transform(shapePosition, shapeOrientation); // TODO : Uncomment this // Compute the the transform from a local shape point to world-space mLocalShapeToWorld = mBodyTransform * mShapeTransform; @@ -122,33 +123,33 @@ class TestPointInside : public Test { mConeShape = mConeBody->addCollisionShape(coneShape, mShapeTransform); ConvexMeshShape convexMeshShape(0); // Box of dimension (2, 3, 4) - convexMeshShape.addVertex(Vector3(-2, -3, 4)); + convexMeshShape.addVertex(Vector3(-2, -3, -4)); + convexMeshShape.addVertex(Vector3(2, -3, -4)); convexMeshShape.addVertex(Vector3(2, -3, 4)); convexMeshShape.addVertex(Vector3(-2, -3, 4)); - convexMeshShape.addVertex(Vector3(2, -3, -4)); - convexMeshShape.addVertex(Vector3(-2, 3, 4)); - convexMeshShape.addVertex(Vector3(2, 3, 4)); convexMeshShape.addVertex(Vector3(-2, 3, -4)); convexMeshShape.addVertex(Vector3(2, 3, -4)); + convexMeshShape.addVertex(Vector3(2, 3, 4)); + convexMeshShape.addVertex(Vector3(-2, 3, 4)); mConvexMeshShape = mConvexMeshBody->addCollisionShape(convexMeshShape, mShapeTransform); ConvexMeshShape convexMeshShapeEdgesInfo(0); - convexMeshShapeEdgesInfo.addVertex(Vector3(-2, -3, 4)); + convexMeshShapeEdgesInfo.addVertex(Vector3(-2, -3, -4)); + convexMeshShapeEdgesInfo.addVertex(Vector3(2, -3, -4)); convexMeshShapeEdgesInfo.addVertex(Vector3(2, -3, 4)); convexMeshShapeEdgesInfo.addVertex(Vector3(-2, -3, 4)); - convexMeshShapeEdgesInfo.addVertex(Vector3(2, -3, -4)); - convexMeshShapeEdgesInfo.addVertex(Vector3(-2, 3, 4)); - convexMeshShapeEdgesInfo.addVertex(Vector3(2, 3, 4)); convexMeshShapeEdgesInfo.addVertex(Vector3(-2, 3, -4)); convexMeshShapeEdgesInfo.addVertex(Vector3(2, 3, -4)); + convexMeshShapeEdgesInfo.addVertex(Vector3(2, 3, 4)); + convexMeshShapeEdgesInfo.addVertex(Vector3(-2, 3, 4)); convexMeshShapeEdgesInfo.addEdge(0, 1); - convexMeshShapeEdgesInfo.addEdge(1, 3); + convexMeshShapeEdgesInfo.addEdge(1, 2); convexMeshShapeEdgesInfo.addEdge(2, 3); - convexMeshShapeEdgesInfo.addEdge(0, 2); + convexMeshShapeEdgesInfo.addEdge(0, 3); convexMeshShapeEdgesInfo.addEdge(4, 5); - convexMeshShapeEdgesInfo.addEdge(5, 7); + convexMeshShapeEdgesInfo.addEdge(5, 6); convexMeshShapeEdgesInfo.addEdge(6, 7); - convexMeshShapeEdgesInfo.addEdge(4, 6); + convexMeshShapeEdgesInfo.addEdge(4, 7); convexMeshShapeEdgesInfo.addEdge(0, 4); convexMeshShapeEdgesInfo.addEdge(1, 5); convexMeshShapeEdgesInfo.addEdge(2, 6); @@ -314,9 +315,9 @@ class TestPointInside : public Test { test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -5, 0))); test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, 0.9))); test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, -0.9))); - test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-1.8, -4, -1))); + test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -4, -0.9))); test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, 0.4))); - test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(1.3, 1, 1.6))); + test(mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(1.3, 1, 1.5))); test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, -7.1, 0))); test(!mCapsuleBody->testPointInside(mLocalShapeToWorld * Vector3(0, 7.1, 0))); @@ -361,9 +362,9 @@ class TestPointInside : public Test { test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(-1.9, -5, 0))); test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, 0.9))); test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0.9, -5, -0.9))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(-1.8, -4, -1))); + test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -4, -0.9))); test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(-1, 2, 0.4))); - test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(1.3, 1, 1.6))); + test(mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(1.3, 1, 1.5))); test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, -7.1, 0))); test(!mCapsuleShape->testPointInside(mLocalShapeToWorld * Vector3(0, 7.1, 0))); @@ -468,6 +469,8 @@ class TestPointInside : public Test { // ----- Tests without using edges information ----- // + bool value = mConvexMeshBody->testPointInside(Vector3(0, 0, 0)); + // Tests with CollisionBody test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 0))); test(mConvexMeshBody->testPointInside(mLocalShapeToWorld * Vector3(-1.9, 0, 0))); @@ -609,7 +612,7 @@ class TestPointInside : public Test { test(mCylinderBody->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -3.9, 1.7))); test(!mCylinderBody->testPointInside(mLocalShapeToWorld * Vector3(0, 4.1, 0))); - test(!!mCylinderBody->testPointInside(mLocalShapeToWorld * Vector3(0, -4.1, 0))); + test(!mCylinderBody->testPointInside(mLocalShapeToWorld * Vector3(0, -4.1, 0))); test(!mCylinderBody->testPointInside(mLocalShapeToWorld * Vector3(3.1, 0, 0))); test(!mCylinderBody->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 0, 0))); test(!mCylinderBody->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.1))); @@ -617,7 +620,7 @@ class TestPointInside : public Test { test(!mCylinderBody->testPointInside(mLocalShapeToWorld * Vector3(2.2, 0, 2.2))); test(!mCylinderBody->testPointInside(mLocalShapeToWorld * Vector3(2.2, 0, -2.2))); test(!mCylinderBody->testPointInside(mLocalShapeToWorld * Vector3(-2.2, 0, -2.2))); - test(!mCylinderBody->testPointInside(mLocalShapeToWorld * Vector3(-2.2, 0, 1.7))); + test(!mCylinderBody->testPointInside(mLocalShapeToWorld * Vector3(-1.3, 0, 2.8))); test(!mCylinderBody->testPointInside(mLocalShapeToWorld * Vector3(3.1, 3.9, 0))); test(!mCylinderBody->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 3.9, 0))); test(!mCylinderBody->testPointInside(mLocalShapeToWorld * Vector3(0, 3.9, 3.1))); @@ -665,7 +668,7 @@ class TestPointInside : public Test { test(mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-1.7, -3.9, 1.7))); test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, 4.1, 0))); - test(!!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, -4.1, 0))); + test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, -4.1, 0))); test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, 0, 0))); test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 0, 0))); test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, 0, 3.1))); @@ -673,7 +676,7 @@ class TestPointInside : public Test { test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(2.2, 0, 2.2))); test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(2.2, 0, -2.2))); test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-2.2, 0, -2.2))); - test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-2.2, 0, 1.7))); + test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-1.3, 0, 2.8))); test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(3.1, 3.9, 0))); test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(-3.1, 3.9, 0))); test(!mCylinderShape->testPointInside(mLocalShapeToWorld * Vector3(0, 3.9, 3.1))); diff --git a/test/tests/collision/TestRaycast.h b/test/tests/collision/TestRaycast.h index 149ff093..5c6a3437 100644 --- a/test/tests/collision/TestRaycast.h +++ b/test/tests/collision/TestRaycast.h @@ -83,7 +83,7 @@ class TestRaycast : public Test { // ---------- Methods ---------- // /// Constructor - TestRaycast() { + TestRaycast(const std::string& name) : Test(name) { // Create the world mWorld = new CollisionWorld(); @@ -101,6 +101,7 @@ class TestRaycast : public Test { mConvexMeshBody = mWorld->createCollisionBody(mBodyTransform); mConvexMeshBodyEdgesInfo = mWorld->createCollisionBody(mBodyTransform); mCylinderBody = mWorld->createCollisionBody(mBodyTransform); + mCompoundBody = mWorld->createCollisionBody(mBodyTransform); // Collision shape transform Vector3 shapePosition(1, -4, -3); diff --git a/test/tests/mathematics/TestMatrix2x2.h b/test/tests/mathematics/TestMatrix2x2.h index 611b93ce..de0ae104 100644 --- a/test/tests/mathematics/TestMatrix2x2.h +++ b/test/tests/mathematics/TestMatrix2x2.h @@ -54,8 +54,8 @@ class TestMatrix2x2 : public Test { // ---------- Methods ---------- // /// Constructor - TestMatrix2x2() : mIdentity(Matrix2x2::identity()), - mMatrix1(2, 24, -4, 5) { + TestMatrix2x2(const std::string& name) + : Test(name), mIdentity(Matrix2x2::identity()), mMatrix1(2, 24, -4, 5) { } diff --git a/test/tests/mathematics/TestMatrix3x3.h b/test/tests/mathematics/TestMatrix3x3.h index 7dfb0faf..a68e2eba 100644 --- a/test/tests/mathematics/TestMatrix3x3.h +++ b/test/tests/mathematics/TestMatrix3x3.h @@ -54,8 +54,9 @@ class TestMatrix3x3 : public Test { // ---------- Methods ---------- // /// Constructor - TestMatrix3x3() : mIdentity(Matrix3x3::identity()), - mMatrix1(2, 24, 4, 5, -6, 234, -15, 11, 66) { + TestMatrix3x3(const std::string& name) + : Test(name), mIdentity(Matrix3x3::identity()), + mMatrix1(2, 24, 4, 5, -6, 234, -15, 11, 66) { } diff --git a/test/tests/mathematics/TestQuaternion.h b/test/tests/mathematics/TestQuaternion.h index 31d50c88..442e2549 100644 --- a/test/tests/mathematics/TestQuaternion.h +++ b/test/tests/mathematics/TestQuaternion.h @@ -55,7 +55,7 @@ class TestQuaternion : public Test { // ---------- Methods ---------- // /// Constructor - TestQuaternion() : mIdentity(Quaternion::identity()) { + TestQuaternion(const std::string& name) : Test(name), mIdentity(Quaternion::identity()) { decimal sinA = sin(decimal(PI/8.0)); decimal cosA = cos(decimal(PI/8.0)); diff --git a/test/tests/mathematics/TestTransform.h b/test/tests/mathematics/TestTransform.h index 38f4d138..1489370b 100644 --- a/test/tests/mathematics/TestTransform.h +++ b/test/tests/mathematics/TestTransform.h @@ -58,7 +58,7 @@ class TestTransform : public Test { // ---------- Methods ---------- // /// Constructor - TestTransform() { + TestTransform(const std::string& name) : Test(name) { mIdentityTransform.setToIdentity(); diff --git a/test/tests/mathematics/TestVector2.h b/test/tests/mathematics/TestVector2.h index febd414f..6169948d 100644 --- a/test/tests/mathematics/TestVector2.h +++ b/test/tests/mathematics/TestVector2.h @@ -54,7 +54,7 @@ class TestVector2 : public Test { // ---------- Methods ---------- // /// Constructor - TestVector2() : mVectorZero(0, 0), mVector34(3, 4) {} + TestVector2(const std::string& name) : Test(name), mVectorZero(0, 0), mVector34(3, 4) {} /// Run the tests void run() { diff --git a/test/tests/mathematics/TestVector3.h b/test/tests/mathematics/TestVector3.h index 4968ee7e..9f780325 100644 --- a/test/tests/mathematics/TestVector3.h +++ b/test/tests/mathematics/TestVector3.h @@ -54,7 +54,7 @@ class TestVector3 : public Test { // ---------- Methods ---------- // /// Constructor - TestVector3() : mVectorZero(0, 0, 0), mVector345(3, 4, 5) {} + TestVector3(const std::string& name): Test(name),mVectorZero(0, 0, 0),mVector345(3, 4, 5) {} /// Run the tests void run() {