From 2b2ad436f02e4c43ee89c8022e5f263959a3efe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A8=D0=B8=D1=88=D0=BE=D0=B2=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=94=D0=B5=D0=BD=D0=B8=D1=81=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=87?= Date: Thu, 10 Sep 2020 16:56:04 +0300 Subject: [PATCH] overall PIMathMatrix tests correction --- tests/math/testpimathmatrix.cpp | 44 +-- tests/math/testpimathmatrixt.cpp | 584 +++++++++++-------------------- 2 files changed, 206 insertions(+), 422 deletions(-) diff --git a/tests/math/testpimathmatrix.cpp b/tests/math/testpimathmatrix.cpp index ae3b46f3..2b045000 100644 --- a/tests/math/testpimathmatrix.cpp +++ b/tests/math/testpimathmatrix.cpp @@ -470,7 +470,6 @@ TEST(PIMathMatrix_Test, toUpperTriangular) TEST(PIMathMatrix_Test, invert) { double d1, d2; - bool b; PIMathMatrix matrix1(3, 3, 0.0); PIMathMatrix matrix2(3, 3, 0.0); PIMathMatrix matrix3(3, 3, 0.0); @@ -494,21 +493,12 @@ TEST(PIMathMatrix_Test, invert) matrix2.invert(); d2 = matrix2.determinant(); matrix4.invert(); - if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } TEST(PIMathMatrix_Test, inverted) { double d1, d2; - bool b; PIMathMatrix matrix1(3, 3, 0.0); PIMathMatrix matrix2(3, 3, 0.0); PIMathMatrix matrix3(3, 3, 0.0); @@ -532,22 +522,13 @@ TEST(PIMathMatrix_Test, inverted) matrix1 = matrix2.invert(); d2 = matrix1.determinant(); matrix3 = matrix4.invert(); - if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } TEST(PIMathMatrix_Test, transposed) { PIMathMatrix origMatr; double d1, d2; - bool b; PIMathMatrix matrix1; PIMathMatrix matrix2; PIMathMatrix matrix3; @@ -570,25 +551,17 @@ TEST(PIMathMatrix_Test, transposed) matrix2 = matrix1.transposed(); d2 = matrix2.determinant(); matrix3 = matrix2.transposed(); - if((d1 == d2) && (matrix1 == matrix3)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((d1 == d2) && (matrix1 == matrix3)); } -TEST(PIMathMatrixT_Test, matrixMultiplication) +TEST(PIMathMatrix_Test, matrixMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathMatrix matrix2(2, 2, 2.5); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2)); } -TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) +TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathVector vector; @@ -601,7 +574,7 @@ TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) +TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) { PIMathMatrix matrix1(2, 2, 1.5); PIMathVector vector; @@ -614,13 +587,13 @@ TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) ASSERT_TRUE(true); } -TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) +TEST(PIMathMatrix_Test, valAndMatrixMultiplication) { PIMathMatrix matrix1(3, 3, 1.5); ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); } -TEST(PIMathMatrixT_Test, hermitian) +TEST(PIMathMatrix_Test, hermitian) { complex val; complex res; @@ -639,4 +612,3 @@ TEST(PIMathMatrixT_Test, hermitian) } ASSERT_TRUE(true); } - diff --git a/tests/math/testpimathmatrixt.cpp b/tests/math/testpimathmatrixt.cpp index 6e4e0a45..a006b3cd 100644 --- a/tests/math/testpimathmatrixt.cpp +++ b/tests/math/testpimathmatrixt.cpp @@ -50,21 +50,8 @@ TEST(PIMathMatrixT_Test, at) } TEST(PIMathMatrixT_Test, filled) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - PIMathMatrixT matr; - PIMathVectorT vect; - double g = 1.0; - matrix2 = matr.fill(g); - uint j = 0, i = 0; - for(i = 0; i < cols; i++) - { - for(j = 0; j < rows; j++) - { - matrix1.at(j,i) = g; - } - } - ASSERT_TRUE(matrix2 == matrix1); + auto matr = PIMathMatrixT::filled(1.0); + ASSERT_TRUE(cmpSquareMatrixWithValue(matr, 1.0, rows)); } TEST(PIMathMatrixT_Test, cols) @@ -83,9 +70,7 @@ TEST(PIMathMatrixT_Test, col) { PIMathMatrixT matr; PIMathVectorT vect; - uint i; uint g = 2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -96,28 +81,18 @@ TEST(PIMathMatrixT_Test, col) matr.at(2,1) = 2; matr.at(2,2) = 5; vect = matr.col(g); - for(i = 0; i < matr.cols(); i++) - { - if(matr.at(i,g) == vect.at(i)) - { - b = true; - } - else - { - b = false; - break; + for(uint i = 0; i < matr.cols(); i++) { + if(matr.at(i, g) != vect.at(i)) { + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, row) -{ - PIMathMatrixT matr; +{ PIMathMatrixT matr; PIMathVectorT vect; - uint i; uint g = 2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -128,19 +103,12 @@ TEST(PIMathMatrixT_Test, row) matr.at(2,1) = 2; matr.at(2,2) = 5; vect = matr.row(g); - for(i = 0; i < matr.rows(); i++) - { - if(matr.at(g,i) == vect.at(i)) - { - b = true; - } - else - { - b = false; - break; + for(uint i = 0; i < matr.rows(); i++) { + if(matr.at(g, i) != vect.at(i)) { + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, setCol) @@ -151,22 +119,13 @@ TEST(PIMathMatrixT_Test, setCol) vect.at(1) = 3.0; vect.at(2) = 5.0; uint g = 1; - uint i = 0; - bool b; matr.setCol(g, vect); - for(i = 0; i < vect.size(); i++) - { - if(matr.at(i,g) == vect.at(i)) - { - b = true; - } - else - { - b = false; - break; + for(uint i = 0; i < vect.size(); i++) { + if(matr.at(i, g) != vect.at(i)) { + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, setRow) @@ -177,33 +136,19 @@ TEST(PIMathMatrixT_Test, setRow) vect.at(1) = 3.0; vect.at(2) = 5.0; uint g = 1; - uint i = 0; - bool b; matr.setRow(g, vect); - for(i = 0; i < vect.size(); i++) - { - if(matr.at(g,i) == vect.at(i)) - { - b = true; - } - else - { - b = false; - break; + for(uint i = 0; i < vect.size(); i++) { + if(matr.at(g,i) != vect.at(i)) { + ASSERT_TRUE(false); } } - ASSERT_TRUE(b); + ASSERT_TRUE(true); } TEST(PIMathMatrixT_Test, swapCols) { PIMathMatrixT matr; - PIMathVectorT before_Vect1; - PIMathVectorT before_Vect2; - PIMathVectorT after_Vect1; - PIMathVectorT after_Vect2; int g1 = 1, g2 = 2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -213,31 +158,23 @@ TEST(PIMathMatrixT_Test, swapCols) matr.at(2,0) = 6; matr.at(2,1) = 2; matr.at(2,2) = 5; - before_Vect1 = matr.col(g1); - before_Vect2 = matr.col(g2); - matr.swapCols(g1,g2); - after_Vect1 = matr.col(g1); - after_Vect2 = matr.col(g2); - if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) - { - b = true; + const PIMathVectorT before_Vect1 = matr.col(g1); + const PIMathVectorT before_Vect2 = matr.col(g2); + matr.swapCols(g1, g2); + const PIMathVectorT after_Vect1 = matr.col(g1); + const PIMathVectorT after_Vect2 = matr.col(g2); + if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) { + ASSERT_TRUE(true); } - else - { - b = false; + else { + ASSERT_TRUE(false); } - ASSERT_TRUE(b); } TEST(PIMathMatrixT_Test, swapRows) { PIMathMatrixT matr; - PIMathVectorT before_Vect1; - PIMathVectorT before_Vect2; - PIMathVectorT after_Vect1; - PIMathVectorT after_Vect2; int g1 = 1, g2 = 2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -247,20 +184,17 @@ TEST(PIMathMatrixT_Test, swapRows) matr.at(2,0) = 6; matr.at(2,1) = 2; matr.at(2,2) = 5; - before_Vect1 = matr.row(g1); - before_Vect2 = matr.row(g2); - matr.swapRows(g1,g2); - after_Vect1 = matr.row(g1); - after_Vect2 = matr.row(g2); - if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) - { - b = true; + const PIMathVectorT before_Vect1 = matr.row(g1); + const PIMathVectorT before_Vect2 = matr.row(g2); + matr.swapRows(g1, g2); + const PIMathVectorT after_Vect1 = matr.row(g1); + const PIMathVectorT after_Vect2 = matr.row(g2); + if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) { + ASSERT_TRUE(true); } - else - { - b = false; + else { + ASSERT_TRUE(false); } - ASSERT_TRUE(b); } TEST(PIMathMatrixT_Test, fill) @@ -269,231 +203,175 @@ TEST(PIMathMatrixT_Test, fill) PIMathMatrixT matrix1; double g = 1.0; matr.fill(g); - uint j = 0, i = 0; - for(i = 0; i < cols; i++) - { - for(j = 0; j < rows; j++) - { + for(uint i = 0; i < cols; i++) { + for(uint j = 0; j < rows; j++) { matrix1.at(j,i) = g; } } ASSERT_TRUE(matr == matrix1); } -TEST(PIMathMatrixT_Test, isSquare) +TEST(PIMathMatrixT_Test, isSquareTrue) { - PIMathMatrixT matr; PIMathMatrixT matrix1; + ASSERT_TRUE(matrix1.isSquare()); +} + +TEST(PIMathMatrixT_Test, isSquareFalse) +{ const uint new_Cols = 4; PIMathMatrixT matrix2; - bool b; - if((matrix1.isSquare() == true) && (matrix2.isSquare() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_FALSE(matrix2.isSquare()); } -TEST(PIMathMatrixT_Test, isIdentity) +TEST(PIMathMatrixT_Test, isIdentityTrue) { - PIMathMatrixT matr; - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1 = matr.identity(); - matrix2 = matr.filled(3.67); - if((matrix1.isIdentity() == true) && (matrix2.isIdentity() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::identity(); + ASSERT_TRUE(matrix1.isIdentity()); } -TEST(PIMathMatrixT_Test, isNull) +TEST(PIMathMatrixT_Test, isIdentityFalse) +{ + auto matrix1 = PIMathMatrixT::filled(2.5); + ASSERT_FALSE(matrix1.isIdentity()); +} + +TEST(PIMathMatrixT_Test, isNullTrue) { PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - PIMathMatrixT matr; - bool b; - matrix2 = matr.filled(3.67); - if((matrix1.isNull() == true) && (matrix2.isNull() == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE(matrix1.isNull()); +} + +TEST(PIMathMatrixT_Test, isNullFalse) +{ + auto matrix1 = PIMathMatrixT::identity(); + ASSERT_FALSE(matrix1.isNull()); } TEST(PIMathMatrixT_Test, operator_Assignment) { PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - PIMathMatrixT matr; - bool b; - matrix2.fill(6.72); + auto matrix2 = PIMathMatrixT::filled(6.72); matrix1 = matrix2; - b = cmpSquareMatrixWithValue(matrix1, 6.72, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 6.72, rows)); } -TEST(PIMathMatrixT_Test, operator_Equal) +TEST(PIMathMatrixT_Test, operator_EqualTrue) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; - PIMathMatrixT matr; - bool b; - matr.at(0,0) = 3; - matr.at(0,1) = 6; - matr.at(0,2) = 8; - matr.at(1,0) = 2; - matr.at(1,1) = 1; - matr.at(1,2) = 4; - matr.at(2,0) = 6; - matr.at(2,1) = 2; - matr.at(2,2) = 5; - matrix1 = matr; - matrix2 = matr; - matrix2.at(2, 2) = 232; - if(((matr == matrix1) == true) && ((matr == matrix2) == false)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + matrix1.at(0, 0) = 5.1; + matrix1.at(0, 1) = 1.21; + matrix1.at(1, 1) = 0.671; + matrix1.at(1, 0) = 2.623; + matrix2.at(0, 0) = 5.1; + matrix2.at(0, 1) = 1.21; + matrix2.at(1, 1) = 0.671; + matrix2.at(1, 0) = 2.623; + ASSERT_TRUE(matrix1 == matrix2); } -TEST(PIMathMatrixT_Test, operator_Not_Equal) +TEST(PIMathMatrixT_Test, operator_EqualFalse) { PIMathMatrixT matrix1; PIMathMatrixT matrix2; - bool b; - PIMathMatrixT matr; - matr.at(0,0) = 3; - matr.at(0,1) = 6; - matr.at(0,2) = 8; - matr.at(1,0) = 2; - matr.at(1,1) = 1; - matr.at(1,2) = 4; - matr.at(2,0) = 6; - matr.at(2,1) = 2; - matr.at(2,2) = 5; - matrix1 = matr; - matrix2 = matr; - matrix2.at(2, 2) = 232; - if(((matr != matrix1) == false) && ((matr != matrix2) == true)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + matrix1.at(0, 0) = 5.1; + matrix1.at(0, 1) = 1.21; + matrix1.at(1, 1) = 0.671; + matrix1.at(1, 0) = 2.623; + matrix2.at(0, 0) = 5.1; + matrix2.at(0, 1) = 1.21; + matrix2.at(1, 1) = 665.671; + matrix2.at(1, 0) = 2.623; + ASSERT_FALSE(matrix1 == matrix2); +} + +TEST(PIMathMatrixT_Test, operator_Not_EqualTrue) +{ + PIMathMatrixT matrix1; + PIMathMatrixT matrix2; + matrix1.at(0, 0) = 5.1; + matrix1.at(0, 1) = 1.21; + matrix1.at(1, 1) = 0.671; + matrix1.at(1, 0) = 2.623; + matrix2.at(0, 0) = 5.1; + matrix2.at(0, 1) = 1.21; + matrix2.at(1, 1) = 665.671; + matrix2.at(1, 0) = 2.623; + ASSERT_TRUE(matrix1 != matrix2); +} + +TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) +{ + PIMathMatrixT matrix1; + PIMathMatrixT matrix2; + matrix1.at(0, 0) = 5.1; + matrix1.at(0, 1) = 1.21; + matrix1.at(1, 1) = 0.671; + matrix1.at(1, 0) = 2.623; + matrix2.at(0, 0) = 5.1; + matrix2.at(0, 1) = 1.21; + matrix2.at(1, 1) = 0.671; + matrix2.at(1, 0) = 2.623; + ASSERT_FALSE(matrix1 != matrix2); } TEST(PIMathMatrixT_Test, operator_Addition_Aassignment) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix2.fill(6.72); - matrix1.fill(1.0); + auto matrix1 = PIMathMatrixT::filled(6.72) ; + auto matrix2 = PIMathMatrixT::filled(1.0) ; matrix1 += matrix2; - b = cmpSquareMatrixWithValue(matrix1, 7.72, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, rows)); } TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix2.fill(6.72); - matrix1.fill(1.0); + auto matrix1 = PIMathMatrixT::filled(1.0); + auto matrix2 = PIMathMatrixT::filled(6.72); matrix1 -= matrix2; - b = cmpSquareMatrixWithValue(matrix1, -5.72, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, rows)); } TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) { - PIMathMatrixT matrix1; - bool b; - matrix1.fill(6.72); + auto matrix1 = PIMathMatrixT::filled(6.72); matrix1 *= 2.0; - b = cmpSquareMatrixWithValue(matrix1, 13.44, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, rows)); } TEST(PIMathMatrixT_Test, operator_Division_Assignment) { - PIMathMatrixT matrix1; - bool b; - matrix1.fill(6.72); + auto matrix1 = PIMathMatrixT::filled(6.72); matrix1 /= 2.0; - b = cmpSquareMatrixWithValue(matrix1, 3.36, rows); - ASSERT_TRUE(b); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, rows)); } TEST(PIMathMatrixT_Test, operator_Addition) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.72); - matrix2.fill(8.28); - b = cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.72); + auto matrix2 = PIMathMatrixT::filled(8.28); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows)); } TEST(PIMathMatrixT_Test, operator_Subtraction) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.0); - matrix2.fill(5.0); - b = cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.0); + auto matrix2 = PIMathMatrixT::filled(5.0); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows)); } TEST(PIMathMatrixT_Test, operator_Multiplication) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.72); - matrix2 = matrix1*4.0; - b = cmpSquareMatrixWithValue(matrix2, 26.88, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.72); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * 4.0, 26.88, rows)); } TEST(PIMathMatrixT_Test, operator_Division) { - PIMathMatrixT matrix1; - PIMathMatrixT matrix2; - bool b; - matrix1.fill(6.72); - matrix2 = matrix1/4.0; - b = cmpSquareMatrixWithValue(matrix2, 1.68, rows); - ASSERT_TRUE(b); + auto matrix1 = PIMathMatrixT::filled(6.72); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 / 4.0, 1.68, rows)); } - -TEST(PIMathMatrixT_Test, determinant) +TEST(PIMathMatrixT_Test, determinantIfSquare) { double d; double i = 59.0; @@ -511,6 +389,21 @@ TEST(PIMathMatrixT_Test, determinant) ASSERT_DOUBLE_EQ(i, d); } +TEST(PIMathMatrixT_Test, determinantIfNotSquare) +{ + PIMathMatrixT matr; + matr.at(0,0) = 3; + matr.at(0,1) = 6; + matr.at(0,2) = 8; + matr.at(1,0) = 2; + matr.at(1,1) = 1; + matr.at(1,2) = 4; + matr.at(2,0) = 6; + matr.at(2,1) = 2; + matr.at(2,2) = 5; + ASSERT_FALSE(matr.determinant()); +} + TEST(PIMathMatrixT_Test, invert) { PIMathMatrixT matrix1; @@ -518,8 +411,6 @@ TEST(PIMathMatrixT_Test, invert) PIMathMatrixT matrix3; PIMathMatrixT matr; double d1, d2; - bool b; - matrix1 = matr.identity(); matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -535,15 +426,7 @@ TEST(PIMathMatrixT_Test, invert) d2 = matrix2.determinant(); matrix3 = matrix1; matrix1.invert(); - if((matrix1 == matrix3) && (d1 == 1/d2)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((matrix1 == matrix3) && (d1 == 1/d2)); } TEST(PIMathMatrixT_Test, inverted) @@ -553,7 +436,6 @@ TEST(PIMathMatrixT_Test, inverted) PIMathMatrixT matrix3; PIMathMatrixT matr; double d1, d2; - bool b; matrix1 = matr.identity(); matr.at(0,0) = 3; matr.at(0,1) = 6; @@ -568,22 +450,13 @@ TEST(PIMathMatrixT_Test, inverted) d1 = matr.determinant(); d2 = matrix2.determinant(); matrix3 = matrix1.inverted(); - if((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)); } TEST(PIMathMatrixT_Test, toUpperTriangular) { PIMathMatrixT matrix; double d1, d2 = 1; - uint i; PIMathMatrixT matr; matr.at(0,0) = 3; matr.at(0,1) = 6; @@ -596,7 +469,7 @@ TEST(PIMathMatrixT_Test, toUpperTriangular) matr.at(2,2) = 5; matrix = matr.toUpperTriangular(); d1 = matrix.determinant(); - for(i = 0; i < cols; i++) + for(uint i = 0; i < cols; i++) { d2 = d2*matrix.at(i,i); } @@ -609,7 +482,6 @@ TEST(PIMathMatrixT_Test, transposed) PIMathMatrixT matrix2; PIMathMatrixT matr; double d1, d2; - bool b; matr.at(0,0) = 3; matr.at(0,1) = 6; matr.at(0,2) = 8; @@ -623,67 +495,30 @@ TEST(PIMathMatrixT_Test, transposed) matrix1 = matr.transposed(); d2 = matrix1.determinant(); matrix2 = matrix1.transposed(); - if((d1 == d2) && (matr == matrix2)) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((d1 == d2) && (matr == matrix2)); } TEST(PIMathMatrixT_Test, scaleX_two) { double factor = 5.64; - bool b; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleX(factor); - - if((1.0 == matrix.at(1u,1u)) && (factor == matrix.at(0u,0u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (factor == matrix.at(0u,0u))); } TEST(PIMathMatrixT_Test, scaleY_two) { double factor = 5.64; - bool b; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleY(factor); - - if((factor == matrix.at(1u,1u)) && (1.0 == matrix.at(0u,0u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((factor == matrix.at(1u,1u)) && (1.0 == matrix.at(0u,0u))); } TEST(PIMathMatrixT_Test, rotation_2x2) { double angle = 1.0; - bool b; PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle); double c = cos(angle); double s = sin(angle); - if((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((c == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (-s == matrix.at(0u,1u)) && (s == matrix.at(1u,0u))); } TEST(PIMathMatrixT_Test, rotation_3x3) @@ -696,106 +531,83 @@ TEST(PIMathMatrixT_Test, rotation_3x3) TEST(PIMathMatrixT_Test, rotationX) { double angle = 1.0; - bool b; double c = cos(angle); double s = sin(angle); PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationX(angle); - - if((1.0 == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(2u,1u)) && (-s == matrix.at(1u,2u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(2u,1u)) && (-s == matrix.at(1u,2u))); } TEST(PIMathMatrixT_Test, rotationY) { double angle = 1.0; - bool b; double c = cos(angle); double s = sin(angle); PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationY(angle); - - if((1.0 == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(0u,2u)) && (-s == matrix.at(2u,0u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(2u,2u)) && (s == matrix.at(0u,2u)) && (-s == matrix.at(2u,0u))); } TEST(PIMathMatrixT_Test, rotationZ) { double angle = 1.0; - bool b; double c = cos(angle); double s = sin(angle); PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationZ(angle); - - if((1.0 == matrix.at(2u,2u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (s == matrix.at(1u,0u)) && (-s == matrix.at(0u,1u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (c == matrix.at(0u,0u)) && (c == matrix.at(1u,1u)) && (s == matrix.at(1u,0u)) && (-s == matrix.at(0u,1u))); } TEST(PIMathMatrixT_Test, scaleX_three) { double factor = 23.65; - bool b; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleX(factor); - if((1.0 == matrix.at(2u,2u)) && (factor == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (factor == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))); } TEST(PIMathMatrixT_Test, scaleY_three) { double factor = 23.65; - bool b; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleY(factor); - if((1.0 == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (factor == matrix.at(1u,1u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((1.0 == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (factor == matrix.at(1u,1u))); } TEST(PIMathMatrixT_Test, scaleZ_three) { double factor = 23.65; - bool b; PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleZ(factor); - if((factor == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))) - { - b = true; - } - else - { - b = false; - } - ASSERT_TRUE(b); + ASSERT_TRUE((factor == matrix.at(2u,2u)) && (1.0 == matrix.at(0u,0u)) && (1.0 == matrix.at(1u,1u))); } +TEST(PIMathMatrixT_Test, matrixMultiplication) +{ + auto matrix1 = PIMathMatrixT::filled(1.5); + auto matrix2 = PIMathMatrixT::filled(2.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 11.25, 3)); +} +TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) +{ + auto matrix1 = PIMathMatrixT::filled(1.5); + auto vector = PIMathVectorT::filled(2.5); + for(uint i = 0; i < 2; i++) { + if((matrix1 * vector)[i] != 11.25) { + ASSERT_TRUE(false); + } + } + ASSERT_TRUE(true); +} + +TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) +{ + auto matrix1 = PIMathMatrixT::filled(1.5); + auto vector = PIMathVectorT::filled(2.5); + for(uint i = 0; i < 2; i++) { + if((vector * matrix1)[i] != 11.25) { + ASSERT_TRUE(false); + } + } +} + +TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) +{ + auto matrix1 = PIMathMatrixT::filled(1.5); + ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); +}