PIMathMatrix new tests version
This commit is contained in:
committed by
Федоренко Дмитрий Витальевич
parent
d255224822
commit
7312fa9a36
@@ -1,33 +1,16 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "pimathmatrix.h"
|
||||
|
||||
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
|
||||
template<typename Type>
|
||||
bool cmpSquareMatrixWithValue(PIMathMatrix<double> matrix, Type val, int num)
|
||||
{
|
||||
bool b = true;
|
||||
for(int i = 0; i < num; i++) {
|
||||
for(int j = 0; j < num; j++) {
|
||||
if(matrix.element(i, j) != val) {
|
||||
b = false;
|
||||
break;
|
||||
}
|
||||
k++;
|
||||
if(k == 3)
|
||||
{
|
||||
j++;
|
||||
k = 0;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
@@ -57,10 +40,8 @@ TEST(PIMathMatrix_Test, matrixRow)
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
auto matrix = PIMathMatrix<double>::matrixRow(vector);
|
||||
for(uint i = 0; i < vector.size(); i++)
|
||||
{
|
||||
if(matrix[0][i] != 3.0)
|
||||
{
|
||||
for(uint i = 0; i < vector.size(); i++) {
|
||||
if(matrix[0][i] != 3.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
@@ -72,10 +53,8 @@ TEST(PIMathMatrix_Test, matrixCol)
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
auto matrix = PIMathMatrix<double>::matrixCol(vector);
|
||||
for(uint i = 0; i < vector.size(); i++)
|
||||
{
|
||||
if(matrix[i][0] != 3.0)
|
||||
{
|
||||
for(uint i = 0; i < vector.size(); i++) {
|
||||
if(matrix[i][0] != 3.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
@@ -89,10 +68,8 @@ TEST(PIMathMatrix_Test, setCol)
|
||||
auto matrix = PIMathMatrix<double>::matrixCol(vector);
|
||||
vector.fill(10.0);
|
||||
matrix.setCol(0, vector);
|
||||
for(uint i = 0; i < vector.size(); i++)
|
||||
{
|
||||
if(matrix[i][0] != 10.0)
|
||||
{
|
||||
for(uint i = 0; i < vector.size(); i++) {
|
||||
if(matrix[i][0] != 10.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
@@ -106,10 +83,8 @@ TEST(PIMathMatrix_Test, setRow)
|
||||
auto matrix = PIMathMatrix<double>::matrixRow(vector);
|
||||
vector.fill(10.0);
|
||||
matrix.setRow(0, vector);
|
||||
for(uint i = 0; i < vector.size(); i++)
|
||||
{
|
||||
if(matrix[0][i] != 10.0)
|
||||
{
|
||||
for(uint i = 0; i < vector.size(); i++) {
|
||||
if(matrix[0][i] != 10.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
@@ -139,25 +114,21 @@ TEST(PIMathMatrix_Test, swapCols)
|
||||
vector.at(1) = 2.0;
|
||||
vector.at(2) = 5.0;
|
||||
matrix1.setCol(2, vector);
|
||||
for(int i = 0; i < 3; i++)
|
||||
{
|
||||
for(int i = 0; i < 3; i++) {
|
||||
a1[i] = matrix1.element(i, 0);
|
||||
a2[i] = matrix1.element(i, 1);
|
||||
a3[i] = matrix1.element(i, 2);
|
||||
}
|
||||
matrix1.swapCols(i1, i2);
|
||||
for(int i = 0; i < 3; i++)
|
||||
{
|
||||
for(int i = 0; i < 3; i++) {
|
||||
b1[i] = matrix1.element(i, 0);
|
||||
b2[i] = matrix1.element(i, 1);
|
||||
b3[i] = matrix1.element(i, 2);
|
||||
}
|
||||
if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0))
|
||||
{
|
||||
if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) {
|
||||
b = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
b = false;
|
||||
}
|
||||
ASSERT_TRUE(b);
|
||||
@@ -186,350 +157,218 @@ TEST(PIMathMatrix_Test, swapRows)
|
||||
vector.at(1) = 2.0;
|
||||
vector.at(2) = 5.0;
|
||||
matrix1.setCol(2, vector);
|
||||
for(int i = 0; i < 3; i++)
|
||||
{
|
||||
for(int i = 0; i < 3; i++) {
|
||||
a1[i] = matrix1.element(0, i);
|
||||
a2[i] = matrix1.element(1, i);
|
||||
a3[i] = matrix1.element(2, i);
|
||||
}
|
||||
matrix1.swapRows(i1, i2);
|
||||
for(int i = 0; i < 3; i++)
|
||||
{
|
||||
for(int i = 0; i < 3; i++) {
|
||||
b1[i] = matrix1.element(0, i);
|
||||
b2[i] = matrix1.element(1, i);
|
||||
b3[i] = matrix1.element(2, i);
|
||||
}
|
||||
if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0))
|
||||
{
|
||||
if((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0)) {
|
||||
b = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
b = false;
|
||||
}
|
||||
ASSERT_TRUE(b);
|
||||
}
|
||||
TEST(PIMathMatrix_Test, fill)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix(3, 3, 5.0);
|
||||
matrix.fill(7.0);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 7.0, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isSquareTrue)
|
||||
{
|
||||
PIMathMatrix<double> matrix(3, 3, 1.0);
|
||||
ASSERT_TRUE(matrix.isSquare());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isSquareFalse)
|
||||
{
|
||||
PIMathMatrix<double> matrix(2, 4, 1.0);
|
||||
ASSERT_FALSE(matrix.isSquare());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isIdentityTrue)
|
||||
{
|
||||
auto matrix = PIMathMatrix<double>::identity(3, 3);
|
||||
ASSERT_TRUE(matrix.isIdentity());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isIdentityFalse)
|
||||
{
|
||||
PIMathMatrix<double> matrix(3, 3, 5.0);
|
||||
ASSERT_FALSE(matrix.isIdentity());
|
||||
}
|
||||
|
||||
|
||||
TEST(PIMathMatrix_Test, isNullTrue)
|
||||
{
|
||||
PIMathMatrix<double> matrix(3, 3, 0.0);
|
||||
ASSERT_TRUE(matrix.isNull());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isNullFalse)
|
||||
{
|
||||
PIMathMatrix<double> matrix(3, 3, 5.0);
|
||||
ASSERT_FALSE(matrix.isNull());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isValidTrue)
|
||||
{
|
||||
PIMathMatrix<double> matrix(3, 3, 1.62);
|
||||
ASSERT_TRUE(matrix.isValid());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isValidFalse)
|
||||
{
|
||||
PIMathMatrix<double> matrix;
|
||||
bool b;
|
||||
matrix = origMatr.identity(3, 3);
|
||||
matrix.fill(5.0);
|
||||
b = cmpMatrixWithValue(matrix, 5.0);
|
||||
ASSERT_TRUE(b);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isSquare)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathMatrix<double> matrix2;
|
||||
bool b;
|
||||
matrix1 = origMatr.identity(3,3);
|
||||
matrix2 = origMatr.identity(4,3);
|
||||
if((matrix1.isSquare() == true) && (matrix2.isSquare() == false))
|
||||
{
|
||||
b = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
b = false;
|
||||
}
|
||||
ASSERT_TRUE(b);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isIdentity)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathMatrix<double> matrix2;
|
||||
bool b;
|
||||
matrix1 = origMatr.identity(3,3);
|
||||
matrix2 = origMatr.identity(3,3);
|
||||
matrix2.fill(3.932);
|
||||
if((matrix1.isIdentity() == true) && (matrix2.isIdentity() == false))
|
||||
{
|
||||
b = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
b = false;
|
||||
}
|
||||
ASSERT_TRUE(b);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isNull)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathMatrix<double> matrix2;
|
||||
bool b;
|
||||
matrix1 = origMatr.identity(3,3);
|
||||
matrix2 = origMatr.identity(3,3);
|
||||
matrix1.fill(0.0);
|
||||
matrix2.fill(3.932);
|
||||
if((matrix1.isNull() == true) && (matrix2.isNull() == false))
|
||||
{
|
||||
b = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
b = false;
|
||||
}
|
||||
ASSERT_TRUE(b);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isValid)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathMatrix<double> matrix2;
|
||||
bool b;
|
||||
matrix1 = origMatr.identity(3,3);
|
||||
if((matrix1.isValid() == true) && (matrix2.isValid() == false))
|
||||
{
|
||||
b = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
b = false;
|
||||
}
|
||||
ASSERT_TRUE(b);
|
||||
ASSERT_FALSE(matrix.isValid());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Assignment)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathMatrix<double> matrix2;
|
||||
bool b;
|
||||
matrix1 = origMatr.identity(3,3);
|
||||
matrix2 = origMatr.identity(3,3);
|
||||
matrix2.fill(6.72);
|
||||
PIMathMatrix<double> matrix1(3, 3, 5.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 7.12);
|
||||
matrix1 = matrix2;
|
||||
b = cmpMatrixWithValue(matrix1, 6.72);
|
||||
ASSERT_TRUE(b);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.12, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Equal)
|
||||
TEST(PIMathMatrix_Test, operator_EqualTrue)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathMatrix<double> matrix2;
|
||||
PIMathMatrix<double> matrix3;
|
||||
PIMathVector<double> vector;
|
||||
bool b;
|
||||
matrix1 = origMatr.identity(3,3);
|
||||
matrix2 = origMatr.identity(3,3);
|
||||
matrix3 = origMatr.identity(3,3);
|
||||
vector.resize(3, 3.0);
|
||||
vector.at(0) = 3.0;
|
||||
vector.at(1) = 6.0;
|
||||
vector.at(2) = 8.0;
|
||||
matrix1.setCol(0, vector);
|
||||
matrix2.setCol(0, vector);
|
||||
matrix3.setCol(0, vector);
|
||||
vector.at(0) = 2.0;
|
||||
vector.at(1) = 1.0;
|
||||
vector.at(2) = 4.0;
|
||||
matrix1.setCol(1, vector);
|
||||
matrix2.setCol(1, vector);
|
||||
matrix3.setCol(1, vector);
|
||||
vector.at(0) = 6.0;
|
||||
vector.at(1) = 2.0;
|
||||
vector.at(2) = 5.0;
|
||||
matrix1.setCol(2, vector);
|
||||
matrix2.setCol(2, vector);
|
||||
vector.at(0) = 566.0;
|
||||
vector.at(1) = 564.0;
|
||||
vector.at(2) = 543.0;
|
||||
matrix3.setCol(2, vector);
|
||||
if(((matrix1 == matrix2) == true) && ((matrix1 == matrix3) == false))
|
||||
{
|
||||
b = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
b = false;
|
||||
}
|
||||
ASSERT_TRUE(b);
|
||||
PIMathMatrix<double> matrix1(2, 2, 2.0);
|
||||
PIMathMatrix<double> matrix2(2, 2, 2.0);
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
matrix1.element(1, 0) = 2.623;
|
||||
matrix2.element(0, 0) = 5.1;
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 0.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_TRUE(matrix1 == matrix2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Not_Equal)
|
||||
TEST(PIMathMatrix_Test, operator_EqualFalse)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathMatrix<double> matrix2;
|
||||
PIMathMatrix<double> matrix3;
|
||||
PIMathVector<double> vector;
|
||||
bool b;
|
||||
matrix1 = origMatr.identity(3,3);
|
||||
matrix2 = origMatr.identity(3,3);
|
||||
matrix3 = origMatr.identity(3,3);
|
||||
vector.resize(3, 3.0);
|
||||
vector.at(0) = 3.0;
|
||||
vector.at(1) = 6.0;
|
||||
vector.at(2) = 8.0;
|
||||
matrix1.setCol(0, vector);
|
||||
matrix2.setCol(0, vector);
|
||||
matrix3.setCol(0, vector);
|
||||
vector.at(0) = 2.0;
|
||||
vector.at(1) = 1.0;
|
||||
vector.at(2) = 4.0;
|
||||
matrix1.setCol(1, vector);
|
||||
matrix2.setCol(1, vector);
|
||||
matrix3.setCol(1, vector);
|
||||
vector.at(0) = 6.0;
|
||||
vector.at(1) = 2.0;
|
||||
vector.at(2) = 5.0;
|
||||
matrix1.setCol(2, vector);
|
||||
matrix2.setCol(2, vector);
|
||||
vector.at(0) = 566.0;
|
||||
vector.at(1) = 564.0;
|
||||
vector.at(2) = 543.0;
|
||||
matrix3.setCol(2, vector);
|
||||
if(((matrix1 != matrix2) == false) && ((matrix1 != matrix3) == true))
|
||||
{
|
||||
b = true;
|
||||
PIMathMatrix<double> matrix1(2, 2, 2.0);
|
||||
PIMathMatrix<double> matrix2(2, 2, 2.0);
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
matrix1.element(1, 0) = 2.623;
|
||||
matrix2.element(0, 0) = 5.1;
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 665.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_FALSE(matrix1 == matrix2);
|
||||
}
|
||||
else
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Not_EqualTrue)
|
||||
{
|
||||
b = false;
|
||||
PIMathMatrix<double> matrix1(2, 2, 2.0);
|
||||
PIMathMatrix<double> matrix2(2, 2, 2.0);
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
matrix1.element(1, 0) = 2.623;
|
||||
matrix2.element(0, 0) = 5.1;
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 665.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_TRUE(matrix1 != matrix2);
|
||||
}
|
||||
ASSERT_TRUE(b);
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Not_EqualFalse)
|
||||
{
|
||||
PIMathMatrix<double> matrix1(2, 2, 2.0);
|
||||
PIMathMatrix<double> matrix2(2, 2, 2.0);
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
matrix1.element(1, 0) = 2.623;
|
||||
matrix2.element(0, 0) = 5.1;
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 0.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_FALSE(matrix1 != matrix2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Addition_Aassignment)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathMatrix<double> matrix2;
|
||||
bool b;
|
||||
matrix1 = origMatr.identity(3,3);
|
||||
matrix2 = origMatr.identity(3,3);
|
||||
matrix2.fill(6.72);
|
||||
matrix1.fill(1.0);
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 1.0);
|
||||
matrix1 += matrix2;
|
||||
b = cmpMatrixWithValue(matrix1, 7.72);
|
||||
ASSERT_TRUE(b);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Subtraction_Assignment)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathMatrix<double> matrix2;
|
||||
bool b;
|
||||
matrix1 = origMatr.identity(3,3);
|
||||
matrix2 = origMatr.identity(3,3);
|
||||
matrix2.fill(6.72);
|
||||
matrix1.fill(1.0);
|
||||
PIMathMatrix<double> matrix1(3, 3, 1.0);
|
||||
PIMathMatrix<double> matrix2(3, 3, 6.72);
|
||||
matrix1 -= matrix2;
|
||||
b = cmpMatrixWithValue(matrix1, -5.72);
|
||||
ASSERT_TRUE(b);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Multiplication_Assignment)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
bool b;
|
||||
matrix1 = origMatr.identity(3,3);
|
||||
matrix1.fill(6.72);
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
matrix1 *= 2.0;
|
||||
b = cmpMatrixWithValue(matrix1, 13.44);
|
||||
ASSERT_TRUE(b);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Division_Assignment)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
bool b;
|
||||
matrix1 = origMatr.identity(3,3);
|
||||
matrix1.fill(6.72);
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
matrix1 /= 2.0;
|
||||
b = cmpMatrixWithValue(matrix1, 3.36);
|
||||
ASSERT_TRUE(b);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Addition)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathMatrix<double> matrix2;
|
||||
bool b;
|
||||
matrix1 = origMatr.identity(3,3);
|
||||
matrix2 = origMatr.identity(3,3);
|
||||
matrix1.fill(6.72);
|
||||
matrix2.fill(8.28);
|
||||
b = cmpMatrixWithValue(matrix1 + matrix2, 15.0);
|
||||
ASSERT_TRUE(b);
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 8.28);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Subtraction)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathMatrix<double> matrix2;
|
||||
bool b;
|
||||
matrix1 = origMatr.identity(3, 3);
|
||||
matrix2 = origMatr.identity(3, 3);
|
||||
origMatr.fill(8.0);
|
||||
matrix1.fill(8.28);
|
||||
origMatr = origMatr - matrix1;
|
||||
matrix2.fill(-0.28);
|
||||
if(origMatr == matrix2)
|
||||
{
|
||||
b = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
b = false;
|
||||
}
|
||||
ASSERT_TRUE(b);
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.0);
|
||||
PIMathMatrix<double> matrix2(3, 3, 5.0);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Multiplication)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathMatrix<double> matrix2;
|
||||
bool b;
|
||||
matrix1 = origMatr.identity(3,3);
|
||||
matrix2 = origMatr.identity(3,3);
|
||||
matrix1.fill(6.72);
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 5.0);
|
||||
matrix2 = matrix1*4.0;
|
||||
b = cmpMatrixWithValue(matrix2, 26.88);
|
||||
ASSERT_TRUE(b);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 26.88, 3));
|
||||
}
|
||||
TEST(PIMathMatrix_Test, operator_Division)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathMatrix<double> matrix2;
|
||||
bool b;
|
||||
matrix1 = origMatr.identity(3,3);
|
||||
matrix2 = origMatr.identity(3,3);
|
||||
matrix1.fill(6.72);
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 5.0);
|
||||
matrix2 = matrix1/4.0;
|
||||
b = cmpMatrixWithValue(matrix2, 1.68);
|
||||
ASSERT_TRUE(b);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 1.68, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, determinant)
|
||||
TEST(PIMathMatrix_Test, determinantIfSquare)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
double d;
|
||||
double i = 59.0;
|
||||
PIMathMatrix<double> matrix;
|
||||
PIMathMatrix<double> matrix(3, 3, 0.0);
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
vector.at(0) = 3.0;
|
||||
vector.at(1) = 6.0;
|
||||
vector.at(2) = 8.0;
|
||||
matrix = origMatr.identity(3, 3);
|
||||
matrix.setCol(0, vector);
|
||||
vector.at(0) = 2.0;
|
||||
vector.at(1) = 1.0;
|
||||
@@ -543,18 +382,23 @@ TEST(PIMathMatrix_Test, determinant)
|
||||
ASSERT_DOUBLE_EQ(d, i);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, determinantIfNotSquare)
|
||||
{
|
||||
PIMathMatrix<double> matrix(3, 5, 1.0);
|
||||
matrix.element(1,1) = 5.0;
|
||||
ASSERT_FALSE(matrix.determinant());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, trace)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix(3, 3, 0.0);
|
||||
double t;
|
||||
double i = 9.0;
|
||||
PIMathMatrix<double> matrix;
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
vector.at(0) = 3.0;
|
||||
vector.at(1) = 6.0;
|
||||
vector.at(2) = 8.0;
|
||||
matrix = origMatr.identity(3, 3);
|
||||
matrix.setCol(0, vector);
|
||||
vector.at(0) = 2.0;
|
||||
vector.at(1) = 1.0;
|
||||
@@ -568,18 +412,23 @@ TEST(PIMathMatrix_Test, trace)
|
||||
ASSERT_DOUBLE_EQ(t, i);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, traceIfNotSquare)
|
||||
{
|
||||
PIMathMatrix<double> matrix(3, 5, 1.0);
|
||||
matrix.element(1,1) = 5.0;
|
||||
ASSERT_FALSE(matrix.trace());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, toUpperTriangular)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix(3, 3, 0.0);
|
||||
double d1, d2 = 1;
|
||||
int i;
|
||||
PIMathMatrix<double> matrix;
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
vector.at(0) = 3.0;
|
||||
vector.at(1) = 6.0;
|
||||
vector.at(2) = 8.0;
|
||||
matrix = origMatr.identity(3, 3);
|
||||
matrix.setCol(0, vector);
|
||||
vector.at(0) = 2.0;
|
||||
vector.at(1) = 1.0;
|
||||
@@ -600,19 +449,17 @@ TEST(PIMathMatrix_Test, toUpperTriangular)
|
||||
|
||||
TEST(PIMathMatrix_Test, invert)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
double d1, d2;
|
||||
bool b;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathMatrix<double> matrix2;
|
||||
PIMathMatrix<double> matrix3;
|
||||
PIMathMatrix<double> matrix4;
|
||||
PIMathMatrix<double> matrix1(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix2(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix3(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix4(3, 3, 0.0);
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
vector.at(0) = 3.0;
|
||||
vector.at(1) = 6.0;
|
||||
vector.at(2) = 8.0;
|
||||
matrix1 = origMatr.identity(3, 3);
|
||||
matrix1.setCol(0, vector);
|
||||
vector.at(0) = 2.0;
|
||||
vector.at(1) = 1.0;
|
||||
@@ -626,8 +473,6 @@ TEST(PIMathMatrix_Test, invert)
|
||||
matrix2 = matrix1;
|
||||
matrix2.invert();
|
||||
d2 = matrix2.determinant();
|
||||
matrix3 = origMatr.identity(3, 3);
|
||||
matrix4 = origMatr.identity(3, 3);
|
||||
matrix4.invert();
|
||||
if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000))
|
||||
{
|
||||
@@ -642,19 +487,17 @@ TEST(PIMathMatrix_Test, invert)
|
||||
|
||||
TEST(PIMathMatrix_Test, inverted)
|
||||
{
|
||||
PIMathMatrix<double> origMatr;
|
||||
double d1, d2;
|
||||
bool b;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathMatrix<double> matrix2;
|
||||
PIMathMatrix<double> matrix3;
|
||||
PIMathMatrix<double> matrix4;
|
||||
PIMathMatrix<double> matrix1(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix2(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix3(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix4(3, 3, 0.0);
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
vector.at(0) = 3.0;
|
||||
vector.at(1) = 6.0;
|
||||
vector.at(2) = 8.0;
|
||||
matrix1 = origMatr.identity(3, 3);
|
||||
matrix1.setCol(0, vector);
|
||||
vector.at(0) = 2.0;
|
||||
vector.at(1) = 1.0;
|
||||
@@ -668,8 +511,6 @@ TEST(PIMathMatrix_Test, inverted)
|
||||
matrix2 = matrix1;
|
||||
matrix1 = matrix2.invert();
|
||||
d2 = matrix1.determinant();
|
||||
matrix3 = origMatr.identity(3, 3);
|
||||
matrix4 = origMatr.identity(3, 3);
|
||||
matrix3 = matrix4.invert();
|
||||
if((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user