From 8f37d4ac98e94302c57c7db21499a99a3b40f2f5 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Thu, 16 May 2013 21:42:13 +0200 Subject: [PATCH] Fix issues in the unit tests for Vector2 and Matrix2x2 --- src/mathematics/Matrix2x2.h | 2 +- test/main.cpp | 4 ++++ test/tests/mathematics/TestMatrix2x2.h | 26 +++++++++++++------------- test/tests/mathematics/TestVector2.h | 8 ++++---- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/mathematics/Matrix2x2.h b/src/mathematics/Matrix2x2.h index ec9c28f1..53a313af 100644 --- a/src/mathematics/Matrix2x2.h +++ b/src/mathematics/Matrix2x2.h @@ -60,7 +60,7 @@ class Matrix2x2 { Matrix2x2(decimal a1, decimal a2, decimal b1, decimal b2); /// Destructor - virtual ~Matrix2x2(); + ~Matrix2x2(); /// Copy-constructor Matrix2x2(const Matrix2x2& matrix); diff --git a/test/main.cpp b/test/main.cpp index 11139b6f..76c2048c 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -25,9 +25,11 @@ // Libraries #include "TestSuite.h" +#include "tests/mathematics/TestVector2.h" #include "tests/mathematics/TestVector3.h" #include "tests/mathematics/TestTransform.h" #include "tests/mathematics/TestQuaternion.h" +#include "tests/mathematics/TestMatrix2x2.h" #include "tests/mathematics/TestMatrix3x3.h" using namespace reactphysics3d; @@ -38,10 +40,12 @@ 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); // ----------------------------- --------- // diff --git a/test/tests/mathematics/TestMatrix2x2.h b/test/tests/mathematics/TestMatrix2x2.h index b4251ec6..f9144cc9 100644 --- a/test/tests/mathematics/TestMatrix2x2.h +++ b/test/tests/mathematics/TestMatrix2x2.h @@ -107,10 +107,10 @@ class TestMatrix2x2 : public Test { test(column2 == Vector2(24, 5)); // Test method that returns a row - Vector3 row1 = mMatrix1.getRow(0); - Vector3 row2 = mMatrix1.getRow(1); - test(row1 == Vector3(2, 24)); - test(row2 == Vector3(-4, 5)); + Vector2 row1 = mMatrix1.getRow(0); + Vector2 row2 = mMatrix1.getRow(1); + test(row1 == Vector2(2, 24)); + test(row2 == Vector2(-4, 5)); } /// Test the identity methods @@ -136,7 +136,7 @@ class TestMatrix2x2 : public Test { test(transpose == Matrix2x2(2, -4, 24, 5)); // Test trace - test(mMatrix1.getTrace() == 10); + test(mMatrix1.getTrace() ==7); test(Matrix2x2::identity().getTrace() == 2); // Test determinant @@ -150,13 +150,13 @@ class TestMatrix2x2 : public Test { Matrix2x2 inverseMatrix = matrix2.getInverse(); test(approxEqual(inverseMatrix[0][0], decimal(-2), decimal(10e-6))); test(approxEqual(inverseMatrix[0][1], decimal(1), decimal(10e-6))); - test(approxEqual(inverseMatrix[1][0], decimal(-0.75), decimal(10e-6))); - test(approxEqual(inverseMatrix[1][1], decimal(0.25), decimal(10e-6))); + test(approxEqual(inverseMatrix[1][0], decimal(1.5), decimal(10e-6))); + test(approxEqual(inverseMatrix[1][1], decimal(-0.5), decimal(10e-6))); Matrix2x2 inverseMatrix1 = mMatrix1.getInverse(); - test(approxEqual(inverseMatrix1[0][0], decimal(0.04716981), decimal(10e-6))); - test(approxEqual(inverseMatrix1[0][1], decimal(-0.2264150), decimal(10e-6))); - test(approxEqual(inverseMatrix1[1][0], decimal(0.0377358), decimal(10e-6))); - test(approxEqual(inverseMatrix1[1][1], decimal(0.0188679), decimal(10e-6))); + test(approxEqual(inverseMatrix1[0][0], decimal(0.047169811), decimal(10e-6))); + test(approxEqual(inverseMatrix1[0][1], decimal(-0.226415094), decimal(10e-6))); + test(approxEqual(inverseMatrix1[1][0], decimal(0.037735849), decimal(10e-6))); + test(approxEqual(inverseMatrix1[1][1], decimal(0.018867925), decimal(10e-6))); // Test absolute matrix Matrix2x2 matrix3(-2, -3, -4, -5); @@ -208,8 +208,8 @@ class TestMatrix2x2 : public Test { Vector2 vector2(-31, -422); Vector2 test1 = matrix1 * vector1; Vector2 test2 = matrix2 * vector2; - test(test1 == Vector2(-762, -182)); - test(test2 == Vector2(-10190, -1986)); + test(test1 == Vector2(-90, -148)); + test(test2 == Vector2(-1204, -4065)); // Test equality operators test(Matrix2x2(34, 38, 43, 64) == diff --git a/test/tests/mathematics/TestVector2.h b/test/tests/mathematics/TestVector2.h index 0cb1f812..f001fa0a 100644 --- a/test/tests/mathematics/TestVector2.h +++ b/test/tests/mathematics/TestVector2.h @@ -54,7 +54,7 @@ class TestVector2 : public Test { // ---------- Methods ---------- // /// Constructor - TestVector1() : mVectorZero(0, 0), mVector34(3, 4) {} + TestVector2() : mVectorZero(0, 0), mVector34(3, 4) {} /// Run the tests void run() { @@ -98,14 +98,14 @@ class TestVector2 : public Test { test(mVectorZero.lengthSquare() == 0.0); test(Vector2(1, 0).length() == 1.0); test(Vector2(0, 1).length() == 1.0); - test(mVector345.lengthSquare() == 50.0); + test(mVector34.lengthSquare() == 25.0); // Test unit vector methods test(Vector2(1, 0).isUnit()); test(Vector2(0, 1).isUnit()); test(!mVector34.isUnit()); - test(Vector2(5, 0).getUnit() == Vector3(1, 0)); - test(Vector2(0, 5).getUnit() == Vector3(0, 1)); + test(Vector2(5, 0).getUnit() == Vector2(1, 0)); + test(Vector2(0, 5).getUnit() == Vector2(0, 1)); test(!mVector34.isZero()); test(mVectorZero.isZero());