Add name in unit tests and fix some issues in Point Inside test
This commit is contained in:
parent
6c505377c5
commit
79c126eac9
|
@ -26,11 +26,13 @@
|
|||
// Libraries
|
||||
#include "Test.h"
|
||||
#include <typeinfo>
|
||||
#include <iomanip>
|
||||
|
||||
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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)));
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -58,7 +58,7 @@ class TestTransform : public Test {
|
|||
// ---------- Methods ---------- //
|
||||
|
||||
/// Constructor
|
||||
TestTransform() {
|
||||
TestTransform(const std::string& name) : Test(name) {
|
||||
|
||||
mIdentityTransform.setToIdentity();
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user