overall PIMathMatrix tests correction

This commit is contained in:
Шишов Максим Денисович
2020-09-10 16:56:04 +03:00
committed by Федоренко Дмитрий Витальевич
parent 7948028022
commit f72d4bcda4
2 changed files with 206 additions and 422 deletions

View File

@@ -470,7 +470,6 @@ TEST(PIMathMatrix_Test, toUpperTriangular)
TEST(PIMathMatrix_Test, invert) TEST(PIMathMatrix_Test, invert)
{ {
double d1, d2; double d1, d2;
bool b;
PIMathMatrix<double> matrix1(3, 3, 0.0); PIMathMatrix<double> matrix1(3, 3, 0.0);
PIMathMatrix<double> matrix2(3, 3, 0.0); PIMathMatrix<double> matrix2(3, 3, 0.0);
PIMathMatrix<double> matrix3(3, 3, 0.0); PIMathMatrix<double> matrix3(3, 3, 0.0);
@@ -494,21 +493,12 @@ TEST(PIMathMatrix_Test, invert)
matrix2.invert(); matrix2.invert();
d2 = matrix2.determinant(); d2 = matrix2.determinant();
matrix4.invert(); matrix4.invert();
if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000));
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrix_Test, inverted) TEST(PIMathMatrix_Test, inverted)
{ {
double d1, d2; double d1, d2;
bool b;
PIMathMatrix<double> matrix1(3, 3, 0.0); PIMathMatrix<double> matrix1(3, 3, 0.0);
PIMathMatrix<double> matrix2(3, 3, 0.0); PIMathMatrix<double> matrix2(3, 3, 0.0);
PIMathMatrix<double> matrix3(3, 3, 0.0); PIMathMatrix<double> matrix3(3, 3, 0.0);
@@ -532,22 +522,13 @@ TEST(PIMathMatrix_Test, inverted)
matrix1 = matrix2.invert(); matrix1 = matrix2.invert();
d2 = matrix1.determinant(); d2 = matrix1.determinant();
matrix3 = matrix4.invert(); matrix3 = matrix4.invert();
if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000));
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrix_Test, transposed) TEST(PIMathMatrix_Test, transposed)
{ {
PIMathMatrix<double> origMatr; PIMathMatrix<double> origMatr;
double d1, d2; double d1, d2;
bool b;
PIMathMatrix<double> matrix1; PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2; PIMathMatrix<double> matrix2;
PIMathMatrix<double> matrix3; PIMathMatrix<double> matrix3;
@@ -570,25 +551,17 @@ TEST(PIMathMatrix_Test, transposed)
matrix2 = matrix1.transposed(); matrix2 = matrix1.transposed();
d2 = matrix2.determinant(); d2 = matrix2.determinant();
matrix3 = matrix2.transposed(); matrix3 = matrix2.transposed();
if((d1 == d2) && (matrix1 == matrix3)) ASSERT_TRUE((d1 == d2) && (matrix1 == matrix3));
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, matrixMultiplication) TEST(PIMathMatrix_Test, matrixMultiplication)
{ {
PIMathMatrix<double> matrix1(2, 2, 1.5); PIMathMatrix<double> matrix1(2, 2, 1.5);
PIMathMatrix<double> matrix2(2, 2, 2.5); PIMathMatrix<double> matrix2(2, 2, 2.5);
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2)); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2));
} }
TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) TEST(PIMathMatrix_Test, matrixAndVectorMultiplication)
{ {
PIMathMatrix<double> matrix1(2, 2, 1.5); PIMathMatrix<double> matrix1(2, 2, 1.5);
PIMathVector<double> vector; PIMathVector<double> vector;
@@ -601,7 +574,7 @@ TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication)
ASSERT_TRUE(true); ASSERT_TRUE(true);
} }
TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication)
{ {
PIMathMatrix<double> matrix1(2, 2, 1.5); PIMathMatrix<double> matrix1(2, 2, 1.5);
PIMathVector<double> vector; PIMathVector<double> vector;
@@ -614,13 +587,13 @@ TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication)
ASSERT_TRUE(true); ASSERT_TRUE(true);
} }
TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) TEST(PIMathMatrix_Test, valAndMatrixMultiplication)
{ {
PIMathMatrix<double> matrix1(3, 3, 1.5); PIMathMatrix<double> matrix1(3, 3, 1.5);
ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3)); ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3));
} }
TEST(PIMathMatrixT_Test, hermitian) TEST(PIMathMatrix_Test, hermitian)
{ {
complex<double> val; complex<double> val;
complex<double> res; complex<double> res;
@@ -639,4 +612,3 @@ TEST(PIMathMatrixT_Test, hermitian)
} }
ASSERT_TRUE(true); ASSERT_TRUE(true);
} }

View File

@@ -50,21 +50,8 @@ TEST(PIMathMatrixT_Test, at)
} }
TEST(PIMathMatrixT_Test, filled) TEST(PIMathMatrixT_Test, filled)
{ {
PIMathMatrixT<rows, cols, double> matrix1; auto matr = PIMathMatrixT<rows, cols, double>::filled(1.0);
PIMathMatrixT<rows, cols, double> matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matr, 1.0, rows));
PIMathMatrixT<rows, cols, double> matr;
PIMathVectorT<rows, double> 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);
} }
TEST(PIMathMatrixT_Test, cols) TEST(PIMathMatrixT_Test, cols)
@@ -83,9 +70,7 @@ TEST(PIMathMatrixT_Test, col)
{ {
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
PIMathVectorT<rows, double> vect; PIMathVectorT<rows, double> vect;
uint i;
uint g = 2; uint g = 2;
bool b;
matr.at(0,0) = 3; matr.at(0,0) = 3;
matr.at(0,1) = 6; matr.at(0,1) = 6;
matr.at(0,2) = 8; matr.at(0,2) = 8;
@@ -96,28 +81,18 @@ TEST(PIMathMatrixT_Test, col)
matr.at(2,1) = 2; matr.at(2,1) = 2;
matr.at(2,2) = 5; matr.at(2,2) = 5;
vect = matr.col(g); vect = matr.col(g);
for(i = 0; i < matr.cols(); i++) for(uint i = 0; i < matr.cols(); i++) {
{ if(matr.at(i, g) != vect.at(i)) {
if(matr.at(i,g) == vect.at(i)) ASSERT_TRUE(false);
{
b = true;
}
else
{
b = false;
break;
} }
} }
ASSERT_TRUE(b); ASSERT_TRUE(true);
} }
TEST(PIMathMatrixT_Test, row) TEST(PIMathMatrixT_Test, row)
{ { PIMathMatrixT<rows, cols, double> matr;
PIMathMatrixT<rows, cols, double> matr;
PIMathVectorT<rows, double> vect; PIMathVectorT<rows, double> vect;
uint i;
uint g = 2; uint g = 2;
bool b;
matr.at(0,0) = 3; matr.at(0,0) = 3;
matr.at(0,1) = 6; matr.at(0,1) = 6;
matr.at(0,2) = 8; matr.at(0,2) = 8;
@@ -128,19 +103,12 @@ TEST(PIMathMatrixT_Test, row)
matr.at(2,1) = 2; matr.at(2,1) = 2;
matr.at(2,2) = 5; matr.at(2,2) = 5;
vect = matr.row(g); vect = matr.row(g);
for(i = 0; i < matr.rows(); i++) for(uint i = 0; i < matr.rows(); i++) {
{ if(matr.at(g, i) != vect.at(i)) {
if(matr.at(g,i) == vect.at(i)) ASSERT_TRUE(false);
{
b = true;
}
else
{
b = false;
break;
} }
} }
ASSERT_TRUE(b); ASSERT_TRUE(true);
} }
TEST(PIMathMatrixT_Test, setCol) TEST(PIMathMatrixT_Test, setCol)
@@ -151,22 +119,13 @@ TEST(PIMathMatrixT_Test, setCol)
vect.at(1) = 3.0; vect.at(1) = 3.0;
vect.at(2) = 5.0; vect.at(2) = 5.0;
uint g = 1; uint g = 1;
uint i = 0;
bool b;
matr.setCol(g, vect); matr.setCol(g, vect);
for(i = 0; i < vect.size(); i++) for(uint i = 0; i < vect.size(); i++) {
{ if(matr.at(i, g) != vect.at(i)) {
if(matr.at(i,g) == vect.at(i)) ASSERT_TRUE(false);
{
b = true;
}
else
{
b = false;
break;
} }
} }
ASSERT_TRUE(b); ASSERT_TRUE(true);
} }
TEST(PIMathMatrixT_Test, setRow) TEST(PIMathMatrixT_Test, setRow)
@@ -177,33 +136,19 @@ TEST(PIMathMatrixT_Test, setRow)
vect.at(1) = 3.0; vect.at(1) = 3.0;
vect.at(2) = 5.0; vect.at(2) = 5.0;
uint g = 1; uint g = 1;
uint i = 0;
bool b;
matr.setRow(g, vect); matr.setRow(g, vect);
for(i = 0; i < vect.size(); i++) for(uint i = 0; i < vect.size(); i++) {
{ if(matr.at(g,i) != vect.at(i)) {
if(matr.at(g,i) == vect.at(i)) ASSERT_TRUE(false);
{
b = true;
}
else
{
b = false;
break;
} }
} }
ASSERT_TRUE(b); ASSERT_TRUE(true);
} }
TEST(PIMathMatrixT_Test, swapCols) TEST(PIMathMatrixT_Test, swapCols)
{ {
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
PIMathVectorT<rows, double> before_Vect1;
PIMathVectorT<rows, double> before_Vect2;
PIMathVectorT<rows, double> after_Vect1;
PIMathVectorT<rows, double> after_Vect2;
int g1 = 1, g2 = 2; int g1 = 1, g2 = 2;
bool b;
matr.at(0,0) = 3; matr.at(0,0) = 3;
matr.at(0,1) = 6; matr.at(0,1) = 6;
matr.at(0,2) = 8; matr.at(0,2) = 8;
@@ -213,31 +158,23 @@ TEST(PIMathMatrixT_Test, swapCols)
matr.at(2,0) = 6; matr.at(2,0) = 6;
matr.at(2,1) = 2; matr.at(2,1) = 2;
matr.at(2,2) = 5; matr.at(2,2) = 5;
before_Vect1 = matr.col(g1); const PIMathVectorT<rows, double> before_Vect1 = matr.col(g1);
before_Vect2 = matr.col(g2); const PIMathVectorT<rows, double> before_Vect2 = matr.col(g2);
matr.swapCols(g1,g2); matr.swapCols(g1, g2);
after_Vect1 = matr.col(g1); const PIMathVectorT<rows, double> after_Vect1 = matr.col(g1);
after_Vect2 = matr.col(g2); const PIMathVectorT<rows, double> after_Vect2 = matr.col(g2);
if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) {
{ ASSERT_TRUE(true);
b = true;
} }
else else {
{ ASSERT_TRUE(false);
b = false;
} }
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, swapRows) TEST(PIMathMatrixT_Test, swapRows)
{ {
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
PIMathVectorT<rows, double> before_Vect1;
PIMathVectorT<rows, double> before_Vect2;
PIMathVectorT<rows, double> after_Vect1;
PIMathVectorT<rows, double> after_Vect2;
int g1 = 1, g2 = 2; int g1 = 1, g2 = 2;
bool b;
matr.at(0,0) = 3; matr.at(0,0) = 3;
matr.at(0,1) = 6; matr.at(0,1) = 6;
matr.at(0,2) = 8; matr.at(0,2) = 8;
@@ -247,20 +184,17 @@ TEST(PIMathMatrixT_Test, swapRows)
matr.at(2,0) = 6; matr.at(2,0) = 6;
matr.at(2,1) = 2; matr.at(2,1) = 2;
matr.at(2,2) = 5; matr.at(2,2) = 5;
before_Vect1 = matr.row(g1); const PIMathVectorT<rows, double> before_Vect1 = matr.row(g1);
before_Vect2 = matr.row(g2); const PIMathVectorT<rows, double> before_Vect2 = matr.row(g2);
matr.swapRows(g1,g2); matr.swapRows(g1, g2);
after_Vect1 = matr.row(g1); const PIMathVectorT<rows, double> after_Vect1 = matr.row(g1);
after_Vect2 = matr.row(g2); const PIMathVectorT<rows, double> after_Vect2 = matr.row(g2);
if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) if((before_Vect1 == after_Vect2) && (before_Vect2 == after_Vect1)) {
{ ASSERT_TRUE(true);
b = true;
} }
else else {
{ ASSERT_TRUE(false);
b = false;
} }
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, fill) TEST(PIMathMatrixT_Test, fill)
@@ -269,231 +203,175 @@ TEST(PIMathMatrixT_Test, fill)
PIMathMatrixT<rows, cols, double> matrix1; PIMathMatrixT<rows, cols, double> matrix1;
double g = 1.0; double g = 1.0;
matr.fill(g); matr.fill(g);
uint j = 0, i = 0; for(uint i = 0; i < cols; i++) {
for(i = 0; i < cols; i++) for(uint j = 0; j < rows; j++) {
{
for(j = 0; j < rows; j++)
{
matrix1.at(j,i) = g; matrix1.at(j,i) = g;
} }
} }
ASSERT_TRUE(matr == matrix1); ASSERT_TRUE(matr == matrix1);
} }
TEST(PIMathMatrixT_Test, isSquare) TEST(PIMathMatrixT_Test, isSquareTrue)
{ {
PIMathMatrixT<rows, cols, double> matr;
PIMathMatrixT<rows, cols, double> matrix1; PIMathMatrixT<rows, cols, double> matrix1;
ASSERT_TRUE(matrix1.isSquare());
}
TEST(PIMathMatrixT_Test, isSquareFalse)
{
const uint new_Cols = 4; const uint new_Cols = 4;
PIMathMatrixT<rows, new_Cols, double> matrix2; PIMathMatrixT<rows, new_Cols, double> matrix2;
bool b; ASSERT_FALSE(matrix2.isSquare());
if((matrix1.isSquare() == true) && (matrix2.isSquare() == false))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, isIdentity) TEST(PIMathMatrixT_Test, isIdentityTrue)
{ {
PIMathMatrixT<rows, cols, double> matr; auto matrix1 = PIMathMatrixT<rows, cols, double>::identity();
PIMathMatrixT<rows, cols, double> matrix1; ASSERT_TRUE(matrix1.isIdentity());
PIMathMatrixT<rows, cols, double> 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);
} }
TEST(PIMathMatrixT_Test, isNull) TEST(PIMathMatrixT_Test, isIdentityFalse)
{
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(2.5);
ASSERT_FALSE(matrix1.isIdentity());
}
TEST(PIMathMatrixT_Test, isNullTrue)
{ {
PIMathMatrixT<rows, cols, double> matrix1; PIMathMatrixT<rows, cols, double> matrix1;
PIMathMatrixT<rows, cols, double> matrix2; ASSERT_TRUE(matrix1.isNull());
PIMathMatrixT<rows, cols, double> matr; }
bool b;
matrix2 = matr.filled(3.67); TEST(PIMathMatrixT_Test, isNullFalse)
if((matrix1.isNull() == true) && (matrix2.isNull() == false)) {
{ auto matrix1 = PIMathMatrixT<rows, cols, double>::identity();
b = true; ASSERT_FALSE(matrix1.isNull());
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Assignment) TEST(PIMathMatrixT_Test, operator_Assignment)
{ {
PIMathMatrixT<rows, cols, double> matrix1; PIMathMatrixT<rows, cols, double> matrix1;
PIMathMatrixT<rows, cols, double> matrix2; auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(6.72);
PIMathMatrixT<rows, cols, double> matr;
bool b;
matrix2.fill(6.72);
matrix1 = matrix2; matrix1 = matrix2;
b = cmpSquareMatrixWithValue(matrix1, 6.72, rows); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 6.72, rows));
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Equal) TEST(PIMathMatrixT_Test, operator_EqualTrue)
{ {
PIMathMatrixT<rows, cols, double> matrix1; PIMathMatrixT<rows, cols, double> matrix1;
PIMathMatrixT<rows, cols, double> matrix2; PIMathMatrixT<rows, cols, double> matrix2;
PIMathMatrixT<rows, cols, double> matr; matrix1.at(0, 0) = 5.1;
bool b; matrix1.at(0, 1) = 1.21;
matr.at(0,0) = 3; matrix1.at(1, 1) = 0.671;
matr.at(0,1) = 6; matrix1.at(1, 0) = 2.623;
matr.at(0,2) = 8; matrix2.at(0, 0) = 5.1;
matr.at(1,0) = 2; matrix2.at(0, 1) = 1.21;
matr.at(1,1) = 1; matrix2.at(1, 1) = 0.671;
matr.at(1,2) = 4; matrix2.at(1, 0) = 2.623;
matr.at(2,0) = 6; ASSERT_TRUE(matrix1 == matrix2);
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);
} }
TEST(PIMathMatrixT_Test, operator_Not_Equal) TEST(PIMathMatrixT_Test, operator_EqualFalse)
{ {
PIMathMatrixT<rows, cols, double> matrix1; PIMathMatrixT<rows, cols, double> matrix1;
PIMathMatrixT<rows, cols, double> matrix2; PIMathMatrixT<rows, cols, double> matrix2;
bool b; matrix1.at(0, 0) = 5.1;
PIMathMatrixT<rows, cols, double> matr; matrix1.at(0, 1) = 1.21;
matr.at(0,0) = 3; matrix1.at(1, 1) = 0.671;
matr.at(0,1) = 6; matrix1.at(1, 0) = 2.623;
matr.at(0,2) = 8; matrix2.at(0, 0) = 5.1;
matr.at(1,0) = 2; matrix2.at(0, 1) = 1.21;
matr.at(1,1) = 1; matrix2.at(1, 1) = 665.671;
matr.at(1,2) = 4; matrix2.at(1, 0) = 2.623;
matr.at(2,0) = 6; ASSERT_FALSE(matrix1 == matrix2);
matr.at(2,1) = 2; }
matr.at(2,2) = 5;
matrix1 = matr; TEST(PIMathMatrixT_Test, operator_Not_EqualTrue)
matrix2 = matr; {
matrix2.at(2, 2) = 232; PIMathMatrixT<rows, cols, double> matrix1;
if(((matr != matrix1) == false) && ((matr != matrix2) == true)) PIMathMatrixT<rows, cols, double> matrix2;
{ matrix1.at(0, 0) = 5.1;
b = true; matrix1.at(0, 1) = 1.21;
} matrix1.at(1, 1) = 0.671;
else matrix1.at(1, 0) = 2.623;
{ matrix2.at(0, 0) = 5.1;
b = false; matrix2.at(0, 1) = 1.21;
} matrix2.at(1, 1) = 665.671;
ASSERT_TRUE(b); matrix2.at(1, 0) = 2.623;
ASSERT_TRUE(matrix1 != matrix2);
}
TEST(PIMathMatrixT_Test, operator_Not_EqualFalse)
{
PIMathMatrixT<rows, cols, double> matrix1;
PIMathMatrixT<rows, cols, double> 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) TEST(PIMathMatrixT_Test, operator_Addition_Aassignment)
{ {
PIMathMatrixT<rows, cols, double> matrix1; auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72) ;
PIMathMatrixT<rows, cols, double> matrix2; auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(1.0) ;
bool b;
matrix2.fill(6.72);
matrix1.fill(1.0);
matrix1 += matrix2; matrix1 += matrix2;
b = cmpSquareMatrixWithValue(matrix1, 7.72, rows); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, rows));
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment)
{ {
PIMathMatrixT<rows, cols, double> matrix1; auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(1.0);
PIMathMatrixT<rows, cols, double> matrix2; auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(6.72);
bool b;
matrix2.fill(6.72);
matrix1.fill(1.0);
matrix1 -= matrix2; matrix1 -= matrix2;
b = cmpSquareMatrixWithValue(matrix1, -5.72, rows); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, rows));
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment)
{ {
PIMathMatrixT<rows, cols, double> matrix1; auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
bool b;
matrix1.fill(6.72);
matrix1 *= 2.0; matrix1 *= 2.0;
b = cmpSquareMatrixWithValue(matrix1, 13.44, rows); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, rows));
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Division_Assignment) TEST(PIMathMatrixT_Test, operator_Division_Assignment)
{ {
PIMathMatrixT<rows, cols, double> matrix1; auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
bool b;
matrix1.fill(6.72);
matrix1 /= 2.0; matrix1 /= 2.0;
b = cmpSquareMatrixWithValue(matrix1, 3.36, rows); ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, rows));
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Addition) TEST(PIMathMatrixT_Test, operator_Addition)
{ {
PIMathMatrixT<rows, cols, double> matrix1; auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
PIMathMatrixT<rows, cols, double> matrix2; auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(8.28);
bool b; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows));
matrix1.fill(6.72);
matrix2.fill(8.28);
b = cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows);
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Subtraction) TEST(PIMathMatrixT_Test, operator_Subtraction)
{ {
PIMathMatrixT<rows, cols, double> matrix1; auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.0);
PIMathMatrixT<rows, cols, double> matrix2; auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(5.0);
bool b; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows));
matrix1.fill(6.0);
matrix2.fill(5.0);
b = cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows);
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Multiplication) TEST(PIMathMatrixT_Test, operator_Multiplication)
{ {
PIMathMatrixT<rows, cols, double> matrix1; auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
PIMathMatrixT<rows, cols, double> matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * 4.0, 26.88, rows));
bool b;
matrix1.fill(6.72);
matrix2 = matrix1*4.0;
b = cmpSquareMatrixWithValue(matrix2, 26.88, rows);
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, operator_Division) TEST(PIMathMatrixT_Test, operator_Division)
{ {
PIMathMatrixT<rows, cols, double> matrix1; auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
PIMathMatrixT<rows, cols, double> matrix2; ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 / 4.0, 1.68, rows));
bool b;
matrix1.fill(6.72);
matrix2 = matrix1/4.0;
b = cmpSquareMatrixWithValue(matrix2, 1.68, rows);
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, determinantIfSquare)
TEST(PIMathMatrixT_Test, determinant)
{ {
double d; double d;
double i = 59.0; double i = 59.0;
@@ -511,6 +389,21 @@ TEST(PIMathMatrixT_Test, determinant)
ASSERT_DOUBLE_EQ(i, d); ASSERT_DOUBLE_EQ(i, d);
} }
TEST(PIMathMatrixT_Test, determinantIfNotSquare)
{
PIMathMatrixT<rows, 5u, double> 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) TEST(PIMathMatrixT_Test, invert)
{ {
PIMathMatrixT<rows, cols, double> matrix1; PIMathMatrixT<rows, cols, double> matrix1;
@@ -518,8 +411,6 @@ TEST(PIMathMatrixT_Test, invert)
PIMathMatrixT<rows, cols, double> matrix3; PIMathMatrixT<rows, cols, double> matrix3;
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
double d1, d2; double d1, d2;
bool b;
matrix1 = matr.identity();
matr.at(0,0) = 3; matr.at(0,0) = 3;
matr.at(0,1) = 6; matr.at(0,1) = 6;
matr.at(0,2) = 8; matr.at(0,2) = 8;
@@ -535,15 +426,7 @@ TEST(PIMathMatrixT_Test, invert)
d2 = matrix2.determinant(); d2 = matrix2.determinant();
matrix3 = matrix1; matrix3 = matrix1;
matrix1.invert(); matrix1.invert();
if((matrix1 == matrix3) && (d1 == 1/d2)) ASSERT_TRUE((matrix1 == matrix3) && (d1 == 1/d2));
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, inverted) TEST(PIMathMatrixT_Test, inverted)
@@ -553,7 +436,6 @@ TEST(PIMathMatrixT_Test, inverted)
PIMathMatrixT<rows, cols, double> matrix3; PIMathMatrixT<rows, cols, double> matrix3;
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
double d1, d2; double d1, d2;
bool b;
matrix1 = matr.identity(); matrix1 = matr.identity();
matr.at(0,0) = 3; matr.at(0,0) = 3;
matr.at(0,1) = 6; matr.at(0,1) = 6;
@@ -568,22 +450,13 @@ TEST(PIMathMatrixT_Test, inverted)
d1 = matr.determinant(); d1 = matr.determinant();
d2 = matrix2.determinant(); d2 = matrix2.determinant();
matrix3 = matrix1.inverted(); matrix3 = matrix1.inverted();
if((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000)) ASSERT_TRUE((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000));
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, toUpperTriangular) TEST(PIMathMatrixT_Test, toUpperTriangular)
{ {
PIMathMatrixT<rows, cols, double> matrix; PIMathMatrixT<rows, cols, double> matrix;
double d1, d2 = 1; double d1, d2 = 1;
uint i;
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
matr.at(0,0) = 3; matr.at(0,0) = 3;
matr.at(0,1) = 6; matr.at(0,1) = 6;
@@ -596,7 +469,7 @@ TEST(PIMathMatrixT_Test, toUpperTriangular)
matr.at(2,2) = 5; matr.at(2,2) = 5;
matrix = matr.toUpperTriangular(); matrix = matr.toUpperTriangular();
d1 = matrix.determinant(); d1 = matrix.determinant();
for(i = 0; i < cols; i++) for(uint i = 0; i < cols; i++)
{ {
d2 = d2*matrix.at(i,i); d2 = d2*matrix.at(i,i);
} }
@@ -609,7 +482,6 @@ TEST(PIMathMatrixT_Test, transposed)
PIMathMatrixT<rows, cols, double> matrix2; PIMathMatrixT<rows, cols, double> matrix2;
PIMathMatrixT<rows, cols, double> matr; PIMathMatrixT<rows, cols, double> matr;
double d1, d2; double d1, d2;
bool b;
matr.at(0,0) = 3; matr.at(0,0) = 3;
matr.at(0,1) = 6; matr.at(0,1) = 6;
matr.at(0,2) = 8; matr.at(0,2) = 8;
@@ -623,67 +495,30 @@ TEST(PIMathMatrixT_Test, transposed)
matrix1 = matr.transposed(); matrix1 = matr.transposed();
d2 = matrix1.determinant(); d2 = matrix1.determinant();
matrix2 = matrix1.transposed(); matrix2 = matrix1.transposed();
if((d1 == d2) && (matr == matrix2)) ASSERT_TRUE((d1 == d2) && (matr == matrix2));
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, scaleX_two) TEST(PIMathMatrixT_Test, scaleX_two)
{ {
double factor = 5.64; double factor = 5.64;
bool b;
PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleX(factor); PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleX(factor);
ASSERT_TRUE((1.0 == matrix.at(1u,1u)) && (factor == matrix.at(0u,0u)));
if((1.0 == matrix.at(1u,1u)) && (factor == matrix.at(0u,0u)))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, scaleY_two) TEST(PIMathMatrixT_Test, scaleY_two)
{ {
double factor = 5.64; double factor = 5.64;
bool b;
PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleY(factor); PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::scaleY(factor);
ASSERT_TRUE((factor == matrix.at(1u,1u)) && (1.0 == matrix.at(0u,0u)));
if((factor == matrix.at(1u,1u)) && (1.0 == matrix.at(0u,0u)))
{
b = true;
}
else
{
b = false;
}
ASSERT_TRUE(b);
} }
TEST(PIMathMatrixT_Test, rotation_2x2) TEST(PIMathMatrixT_Test, rotation_2x2)
{ {
double angle = 1.0; double angle = 1.0;
bool b;
PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle); PIMathMatrixT<2u, 2u, double> matrix = PIMathMatrixT<2u, 2u, double>::rotation(angle);
double c = cos(angle); double c = cos(angle);
double s = sin(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))) ASSERT_TRUE((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);
} }
TEST(PIMathMatrixT_Test, rotation_3x3) TEST(PIMathMatrixT_Test, rotation_3x3)
@@ -696,106 +531,83 @@ TEST(PIMathMatrixT_Test, rotation_3x3)
TEST(PIMathMatrixT_Test, rotationX) TEST(PIMathMatrixT_Test, rotationX)
{ {
double angle = 1.0; double angle = 1.0;
bool b;
double c = cos(angle); double c = cos(angle);
double s = sin(angle); double s = sin(angle);
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationX(angle); PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationX(angle);
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)));
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);
} }
TEST(PIMathMatrixT_Test, rotationY) TEST(PIMathMatrixT_Test, rotationY)
{ {
double angle = 1.0; double angle = 1.0;
bool b;
double c = cos(angle); double c = cos(angle);
double s = sin(angle); double s = sin(angle);
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationY(angle); PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationY(angle);
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)));
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);
} }
TEST(PIMathMatrixT_Test, rotationZ) TEST(PIMathMatrixT_Test, rotationZ)
{ {
double angle = 1.0; double angle = 1.0;
bool b;
double c = cos(angle); double c = cos(angle);
double s = sin(angle); double s = sin(angle);
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationZ(angle); PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotationZ(angle);
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)));
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);
} }
TEST(PIMathMatrixT_Test, scaleX_three) TEST(PIMathMatrixT_Test, scaleX_three)
{ {
double factor = 23.65; double factor = 23.65;
bool b;
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleX(factor); 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))) ASSERT_TRUE((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);
} }
TEST(PIMathMatrixT_Test, scaleY_three) TEST(PIMathMatrixT_Test, scaleY_three)
{ {
double factor = 23.65; double factor = 23.65;
bool b;
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleY(factor); 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))) ASSERT_TRUE((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);
} }
TEST(PIMathMatrixT_Test, scaleZ_three) TEST(PIMathMatrixT_Test, scaleZ_three)
{ {
double factor = 23.65; double factor = 23.65;
bool b;
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::scaleZ(factor); 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))) ASSERT_TRUE((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);
} }
TEST(PIMathMatrixT_Test, matrixMultiplication)
{
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(1.5);
auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(2.5);
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 11.25, 3));
}
TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication)
{
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(1.5);
auto vector = PIMathVectorT<rows, double>::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<rows, cols, double>::filled(1.5);
auto vector = PIMathVectorT<rows, double>::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<rows, cols, double>::filled(1.5);
ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3));
}