Fix issues in the unit tests for Vector2 and Matrix2x2
This commit is contained in:
parent
74070ae400
commit
8f37d4ac98
|
@ -60,7 +60,7 @@ class Matrix2x2 {
|
||||||
Matrix2x2(decimal a1, decimal a2, decimal b1, decimal b2);
|
Matrix2x2(decimal a1, decimal a2, decimal b1, decimal b2);
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
virtual ~Matrix2x2();
|
~Matrix2x2();
|
||||||
|
|
||||||
/// Copy-constructor
|
/// Copy-constructor
|
||||||
Matrix2x2(const Matrix2x2& matrix);
|
Matrix2x2(const Matrix2x2& matrix);
|
||||||
|
|
|
@ -25,9 +25,11 @@
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
#include "TestSuite.h"
|
#include "TestSuite.h"
|
||||||
|
#include "tests/mathematics/TestVector2.h"
|
||||||
#include "tests/mathematics/TestVector3.h"
|
#include "tests/mathematics/TestVector3.h"
|
||||||
#include "tests/mathematics/TestTransform.h"
|
#include "tests/mathematics/TestTransform.h"
|
||||||
#include "tests/mathematics/TestQuaternion.h"
|
#include "tests/mathematics/TestQuaternion.h"
|
||||||
|
#include "tests/mathematics/TestMatrix2x2.h"
|
||||||
#include "tests/mathematics/TestMatrix3x3.h"
|
#include "tests/mathematics/TestMatrix3x3.h"
|
||||||
|
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
@ -38,10 +40,12 @@ int main() {
|
||||||
|
|
||||||
// ---------- Mathematics tests ---------- //
|
// ---------- Mathematics tests ---------- //
|
||||||
|
|
||||||
|
testSuite.addTest(new TestVector2);
|
||||||
testSuite.addTest(new TestVector3);
|
testSuite.addTest(new TestVector3);
|
||||||
testSuite.addTest(new TestTransform);
|
testSuite.addTest(new TestTransform);
|
||||||
testSuite.addTest(new TestQuaternion);
|
testSuite.addTest(new TestQuaternion);
|
||||||
testSuite.addTest(new TestMatrix3x3);
|
testSuite.addTest(new TestMatrix3x3);
|
||||||
|
testSuite.addTest(new TestMatrix2x2);
|
||||||
|
|
||||||
// ----------------------------- --------- //
|
// ----------------------------- --------- //
|
||||||
|
|
||||||
|
|
|
@ -107,10 +107,10 @@ class TestMatrix2x2 : public Test {
|
||||||
test(column2 == Vector2(24, 5));
|
test(column2 == Vector2(24, 5));
|
||||||
|
|
||||||
// Test method that returns a row
|
// Test method that returns a row
|
||||||
Vector3 row1 = mMatrix1.getRow(0);
|
Vector2 row1 = mMatrix1.getRow(0);
|
||||||
Vector3 row2 = mMatrix1.getRow(1);
|
Vector2 row2 = mMatrix1.getRow(1);
|
||||||
test(row1 == Vector3(2, 24));
|
test(row1 == Vector2(2, 24));
|
||||||
test(row2 == Vector3(-4, 5));
|
test(row2 == Vector2(-4, 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test the identity methods
|
/// Test the identity methods
|
||||||
|
@ -136,7 +136,7 @@ class TestMatrix2x2 : public Test {
|
||||||
test(transpose == Matrix2x2(2, -4, 24, 5));
|
test(transpose == Matrix2x2(2, -4, 24, 5));
|
||||||
|
|
||||||
// Test trace
|
// Test trace
|
||||||
test(mMatrix1.getTrace() == 10);
|
test(mMatrix1.getTrace() ==7);
|
||||||
test(Matrix2x2::identity().getTrace() == 2);
|
test(Matrix2x2::identity().getTrace() == 2);
|
||||||
|
|
||||||
// Test determinant
|
// Test determinant
|
||||||
|
@ -150,13 +150,13 @@ class TestMatrix2x2 : public Test {
|
||||||
Matrix2x2 inverseMatrix = matrix2.getInverse();
|
Matrix2x2 inverseMatrix = matrix2.getInverse();
|
||||||
test(approxEqual(inverseMatrix[0][0], decimal(-2), decimal(10e-6)));
|
test(approxEqual(inverseMatrix[0][0], decimal(-2), decimal(10e-6)));
|
||||||
test(approxEqual(inverseMatrix[0][1], decimal(1), 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][0], decimal(1.5), decimal(10e-6)));
|
||||||
test(approxEqual(inverseMatrix[1][1], decimal(0.25), decimal(10e-6)));
|
test(approxEqual(inverseMatrix[1][1], decimal(-0.5), decimal(10e-6)));
|
||||||
Matrix2x2 inverseMatrix1 = mMatrix1.getInverse();
|
Matrix2x2 inverseMatrix1 = mMatrix1.getInverse();
|
||||||
test(approxEqual(inverseMatrix1[0][0], decimal(0.04716981), decimal(10e-6)));
|
test(approxEqual(inverseMatrix1[0][0], decimal(0.047169811), decimal(10e-6)));
|
||||||
test(approxEqual(inverseMatrix1[0][1], decimal(-0.2264150), decimal(10e-6)));
|
test(approxEqual(inverseMatrix1[0][1], decimal(-0.226415094), decimal(10e-6)));
|
||||||
test(approxEqual(inverseMatrix1[1][0], decimal(0.0377358), decimal(10e-6)));
|
test(approxEqual(inverseMatrix1[1][0], decimal(0.037735849), decimal(10e-6)));
|
||||||
test(approxEqual(inverseMatrix1[1][1], decimal(0.0188679), decimal(10e-6)));
|
test(approxEqual(inverseMatrix1[1][1], decimal(0.018867925), decimal(10e-6)));
|
||||||
|
|
||||||
// Test absolute matrix
|
// Test absolute matrix
|
||||||
Matrix2x2 matrix3(-2, -3, -4, -5);
|
Matrix2x2 matrix3(-2, -3, -4, -5);
|
||||||
|
@ -208,8 +208,8 @@ class TestMatrix2x2 : public Test {
|
||||||
Vector2 vector2(-31, -422);
|
Vector2 vector2(-31, -422);
|
||||||
Vector2 test1 = matrix1 * vector1;
|
Vector2 test1 = matrix1 * vector1;
|
||||||
Vector2 test2 = matrix2 * vector2;
|
Vector2 test2 = matrix2 * vector2;
|
||||||
test(test1 == Vector2(-762, -182));
|
test(test1 == Vector2(-90, -148));
|
||||||
test(test2 == Vector2(-10190, -1986));
|
test(test2 == Vector2(-1204, -4065));
|
||||||
|
|
||||||
// Test equality operators
|
// Test equality operators
|
||||||
test(Matrix2x2(34, 38, 43, 64) ==
|
test(Matrix2x2(34, 38, 43, 64) ==
|
||||||
|
|
|
@ -54,7 +54,7 @@ class TestVector2 : public Test {
|
||||||
// ---------- Methods ---------- //
|
// ---------- Methods ---------- //
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
TestVector1() : mVectorZero(0, 0), mVector34(3, 4) {}
|
TestVector2() : mVectorZero(0, 0), mVector34(3, 4) {}
|
||||||
|
|
||||||
/// Run the tests
|
/// Run the tests
|
||||||
void run() {
|
void run() {
|
||||||
|
@ -98,14 +98,14 @@ class TestVector2 : public Test {
|
||||||
test(mVectorZero.lengthSquare() == 0.0);
|
test(mVectorZero.lengthSquare() == 0.0);
|
||||||
test(Vector2(1, 0).length() == 1.0);
|
test(Vector2(1, 0).length() == 1.0);
|
||||||
test(Vector2(0, 1).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 unit vector methods
|
||||||
test(Vector2(1, 0).isUnit());
|
test(Vector2(1, 0).isUnit());
|
||||||
test(Vector2(0, 1).isUnit());
|
test(Vector2(0, 1).isUnit());
|
||||||
test(!mVector34.isUnit());
|
test(!mVector34.isUnit());
|
||||||
test(Vector2(5, 0).getUnit() == Vector3(1, 0));
|
test(Vector2(5, 0).getUnit() == Vector2(1, 0));
|
||||||
test(Vector2(0, 5).getUnit() == Vector3(0, 1));
|
test(Vector2(0, 5).getUnit() == Vector2(0, 1));
|
||||||
|
|
||||||
test(!mVector34.isZero());
|
test(!mVector34.isZero());
|
||||||
test(mVectorZero.isZero());
|
test(mVectorZero.isZero());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user