Tests update

This commit is contained in:
Шишов Максим Денисович
2020-09-01 12:10:56 +03:00
parent 8405b564a4
commit fcf91a26b6
2 changed files with 141 additions and 472 deletions

View File

@@ -1,18 +1,44 @@
#include "gtest/gtest.h"
#include "pimathmatrix.h"
using namespace std;
PIMathMatrix<double> origMatr;
bool cmpMatrixWithValue(PIMathMatrix<double> matrix, double val)
{
int i = 0;
int j = 0;
int k = 0;
bool b;
while(i < 9)
{
if(k < 3)
{
if(matrix.element(j,k) == val)
{
b = true;
}
else
{
b = false;
break;
}
k++;
if(k == 3)
{
j++;
k = 0;
}
}
i++;
}
return b;
}
TEST(PIMathMatrix_Test, identity)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix;
int i;
double d;
bool a, b;
bool b;
matrix = origMatr.identity(3, 3);
d = matrix.determinant();
for(i = 0; i < 3; i++)
{
if(matrix[i][i] == 1.0)
@@ -25,19 +51,12 @@ TEST(PIMathMatrix_Test, identity)
break;
}
}
if(d == 1.0)
{
a = true;
}
else
{
a = false;
}
ASSERT_TRUE(a && b);
ASSERT_TRUE(b);
}
TEST(PIMathMatrix_Test, matrixRow)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix;
PIMathVector<double> vector;
uint i;
@@ -62,6 +81,7 @@ TEST(PIMathMatrix_Test, matrixRow)
TEST(PIMathMatrix_Test, matrixCol)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix;
PIMathVector<double> vector;
uint i;
@@ -86,6 +106,7 @@ TEST(PIMathMatrix_Test, matrixCol)
TEST(PIMathMatrix_Test, setCol)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix;
PIMathVector<double> vector;
uint i;
@@ -112,6 +133,7 @@ TEST(PIMathMatrix_Test, setCol)
TEST(PIMathMatrix_Test, setRow)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix;
PIMathVector<double> vector;
uint i;
@@ -138,6 +160,7 @@ TEST(PIMathMatrix_Test, setRow)
TEST(PIMathMatrix_Test, swapCols)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
PIMathVector<double> vector;
uint i1 = 0; uint i2 = 1;
@@ -184,6 +207,7 @@ TEST(PIMathMatrix_Test, swapCols)
TEST(PIMathMatrix_Test, swapRows)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
PIMathVector<double> vector;
uint i1 = 0; uint i2 = 1;
@@ -229,41 +253,18 @@ TEST(PIMathMatrix_Test, swapRows)
}
TEST(PIMathMatrix_Test, fill)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix;
int i = 0;
int j = 0;
int k = 0;
bool b;
matrix = origMatr.identity(3, 3);
matrix.fill(5.0);
while(i < 9)
{
if(k < 3)
{
if(matrix.element(j,k) == 5.0)
{
b = true;
}
else
{
b = false;
break;
}
k++;
if(k == 3)
{
j++;
k = 0;
}
}
i++;
}
b = cmpMatrixWithValue(matrix, 5.0);
ASSERT_TRUE(b);
}
TEST(PIMathMatrix_Test, isSquare)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
bool b;
@@ -282,6 +283,7 @@ TEST(PIMathMatrix_Test, isSquare)
TEST(PIMathMatrix_Test, isIdentity)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
bool b;
@@ -301,6 +303,7 @@ TEST(PIMathMatrix_Test, isIdentity)
TEST(PIMathMatrix_Test, isNull)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
bool b;
@@ -321,6 +324,7 @@ TEST(PIMathMatrix_Test, isNull)
TEST(PIMathMatrix_Test, isValid)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
bool b;
@@ -338,43 +342,21 @@ TEST(PIMathMatrix_Test, isValid)
TEST(PIMathMatrix_Test, operator_Assignment)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
int i = 0;
int j = 0;
int k = 0;
bool b;
matrix1 = origMatr.identity(3,3);
matrix2 = origMatr.identity(3,3);
matrix2.fill(6.72);
matrix1 = matrix2;
while(i < 9)
{
if(k < 3)
{
if(matrix1.element(j,k) == 6.72)
{
b = true;
}
else
{
b = false;
break;
}
k++;
if(k == 3)
{
j++;
k = 0;
}
}
i++;
}
b = cmpMatrixWithValue(matrix1, 6.72);
ASSERT_TRUE(b);
}
TEST(PIMathMatrix_Test, operator_Equal)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
PIMathMatrix<double> matrix3;
@@ -418,6 +400,7 @@ TEST(PIMathMatrix_Test, operator_Equal)
TEST(PIMathMatrix_Test, operator_Not_Equal)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
PIMathMatrix<double> matrix3;
@@ -461,189 +444,75 @@ TEST(PIMathMatrix_Test, operator_Not_Equal)
TEST(PIMathMatrix_Test, operator_Addition_Aassignment)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
bool b;
int i = 0;
int j = 0;
int k = 0;
matrix1 = origMatr.identity(3,3);
matrix2 = origMatr.identity(3,3);
matrix2.fill(6.72);
matrix1.fill(1.0);
matrix1 += matrix2;
while(i < 9)
{
if(k < 3)
{
if(matrix1.element(j,k) == 7.72)
{
b = true;
}
else
{
b = false;
break;
}
k++;
if(k == 3)
{
j++;
k = 0;
}
}
i++;
}
b = cmpMatrixWithValue(matrix1, 7.72);
ASSERT_TRUE(b);
}
TEST(PIMathMatrix_Test, operator_Subtraction_Assignment)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
bool b;
int i = 0;
int j = 0;
int k = 0;
matrix1 = origMatr.identity(3,3);
matrix2 = origMatr.identity(3,3);
matrix2.fill(6.72);
matrix1.fill(1.0);
matrix1 -= matrix2;
while(i < 9)
{
if(k < 3)
{
if(matrix1.element(j,k) == -5.72)
{
b = true;
}
else
{
b = false;
break;
}
k++;
if(k == 3)
{
j++;
k = 0;
}
}
i++;
}
b = cmpMatrixWithValue(matrix1, -5.72);
ASSERT_TRUE(b);
}
TEST(PIMathMatrix_Test, operator_Multiplication_Assignment)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
bool b;
int i = 0;
int j = 0;
int k = 0;
matrix1 = origMatr.identity(3,3);
matrix1.fill(6.72);
matrix1 *= 2.0;
while(i < 9)
{
if(k < 3)
{
if(matrix1.element(j,k) == 13.44)
{
b = true;
}
else
{
b = false;
break;
}
k++;
if(k == 3)
{
j++;
k = 0;
}
}
i++;
}
b = cmpMatrixWithValue(matrix1, 13.44);
ASSERT_TRUE(b);
}
TEST(PIMathMatrix_Test, operator_Division_Assignment)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
bool b;
int i = 0;
int j = 0;
int k = 0;
matrix1 = origMatr.identity(3,3);
matrix1.fill(6.72);
matrix1 /= 2.0;
while(i < 9)
{
if(k < 3)
{
if(matrix1.element(j,k) == 3.36)
{
b = true;
}
else
{
b = false;
break;
}
k++;
if(k == 3)
{
j++;
k = 0;
}
}
i++;
}
b = cmpMatrixWithValue(matrix1, 3.36);
ASSERT_TRUE(b);
}
TEST(PIMathMatrix_Test, operator_Addition)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
bool b;
int i = 0;
int j = 0;
int k = 0;
matrix1 = origMatr.identity(3,3);
matrix2 = origMatr.identity(3,3);
matrix1.fill(6.72);
matrix2.fill(8.28);
while(i < 9)
{
if(k < 3)
{
if((matrix1+matrix2).element(j,k) == 15.0)
{
b = true;
}
else
{
b = false;
break;
}
k++;
if(k == 3)
{
j++;
k = 0;
}
}
i++;
}
b = cmpMatrixWithValue(matrix1 + matrix2, 15.0);
ASSERT_TRUE(b);
}
TEST(PIMathMatrix_Test, operator_Subtraction)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
bool b;
@@ -666,79 +535,34 @@ TEST(PIMathMatrix_Test, operator_Subtraction)
TEST(PIMathMatrix_Test, operator_Multiplication)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
bool b;
int i = 0;
int j = 0;
int k = 0;
matrix1 = origMatr.identity(3,3);
matrix2 = origMatr.identity(3,3);
matrix1.fill(6.72);
matrix2 = matrix1*4.0;
while(i < 9)
{
if(k < 3)
{
if(matrix2.element(j,k) == 26.88)
{
b = true;
}
else
{
b = false;
break;
}
k++;
if(k == 3)
{
j++;
k = 0;
}
}
i++;
}
b = cmpMatrixWithValue(matrix2, 26.88);
ASSERT_TRUE(b);
}
TEST(PIMathMatrix_Test, operator_Division)
{
PIMathMatrix<double> origMatr;
PIMathMatrix<double> matrix1;
PIMathMatrix<double> matrix2;
bool b;
int i = 0;
int j = 0;
int k = 0;
matrix1 = origMatr.identity(3,3);
matrix2 = origMatr.identity(3,3);
matrix1.fill(6.72);
matrix2 = matrix1/4.0;
while(i < 9)
{
if(k < 3)
{
if(matrix2.element(j,k) == 1.68)
{
b = true;
}
else
{
b = false;
break;
}
k++;
if(k == 3)
{
j++;
k = 0;
}
}
i++;
}
b = cmpMatrixWithValue(matrix2, 1.68);
ASSERT_TRUE(b);
}
TEST(PIMathMatrix_Test, determinant)
{
PIMathMatrix<double> origMatr;
double d;
double i = 59.0;
PIMathMatrix<double> matrix;
@@ -763,6 +587,7 @@ TEST(PIMathMatrix_Test, determinant)
TEST(PIMathMatrix_Test, trace)
{
PIMathMatrix<double> origMatr;
double t;
double i = 9.0;
PIMathMatrix<double> matrix;
@@ -787,6 +612,7 @@ TEST(PIMathMatrix_Test, trace)
TEST(PIMathMatrix_Test, toUpperTriangular)
{
PIMathMatrix<double> origMatr;
double d1, d2 = 1;
int i;
PIMathMatrix<double> matrix;
@@ -816,6 +642,7 @@ TEST(PIMathMatrix_Test, toUpperTriangular)
TEST(PIMathMatrix_Test, invert)
{
PIMathMatrix<double> origMatr;
double d1, d2;
bool b;
PIMathMatrix<double> matrix1;
@@ -857,6 +684,7 @@ TEST(PIMathMatrix_Test, invert)
TEST(PIMathMatrix_Test, inverted)
{
PIMathMatrix<double> origMatr;
double d1, d2;
bool b;
PIMathMatrix<double> matrix1;
@@ -898,6 +726,7 @@ TEST(PIMathMatrix_Test, inverted)
TEST(PIMathMatrix_Test, transposed)
{
PIMathMatrix<double> origMatr;
double d1, d2;
bool b;
PIMathMatrix<double> matrix1;
@@ -932,5 +761,3 @@ TEST(PIMathMatrix_Test, transposed)
}
ASSERT_TRUE(b);
}