code format
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "pimathmatrix.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
template<typename Type>
|
||||
bool cmpSquareMatrixWithValue(PIMathMatrix<Type> matrix, Type val, int num) {
|
||||
for(int i = 0; i < num; i++) {
|
||||
for(int j = 0; j < num; j++) {
|
||||
if(matrix.element(i, j) != val) {
|
||||
for (int i = 0; i < num; i++) {
|
||||
for (int j = 0; j < num; j++) {
|
||||
if (matrix.element(i, j) != val) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -32,15 +33,14 @@ TEST(PIMathMatrix_Test, constructor3) {
|
||||
|
||||
TEST(PIMathMatrix_Test, identity1) {
|
||||
auto matrix = PIMathMatrix<double>::identity(3, 3);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 3; j++) {
|
||||
if(i != j) {
|
||||
if(matrix[i][j] != 0.0){
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
if (i != j) {
|
||||
if (matrix[i][j] != 0.0) {
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(matrix[i][i] != 1.0){
|
||||
} else {
|
||||
if (matrix[i][i] != 1.0) {
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
@@ -51,20 +51,18 @@ TEST(PIMathMatrix_Test, identity1) {
|
||||
|
||||
TEST(PIMathMatrix_Test, identity2) {
|
||||
auto matrix = PIMathMatrix<double>::identity(4, 3);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 4; j++) {
|
||||
if(matrix.element(i,j) != (i == j ? 1. : 0.))
|
||||
FAIL();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if (matrix.element(i, j) != (i == j ? 1. : 0.)) FAIL();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, element) {
|
||||
auto matrix = PIMathMatrix<double>::identity(3, 3);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 3; j++) {
|
||||
if(matrix.element(i,j) != (i == j ? 1. : 0.))
|
||||
FAIL();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
if (matrix.element(i, j) != (i == j ? 1. : 0.)) FAIL();
|
||||
}
|
||||
}
|
||||
SUCCEED();
|
||||
@@ -74,8 +72,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) {
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
@@ -86,8 +84,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) {
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
@@ -100,8 +98,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) {
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
@@ -114,8 +112,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) {
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
@@ -126,14 +124,15 @@ TEST(PIMathMatrix_Test, swapCols) {
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathVector<double> vector;
|
||||
uint i1 = 0; uint i2 = 1;
|
||||
uint i1 = 0;
|
||||
uint i2 = 1;
|
||||
double a1[3], a2[3], a3[3];
|
||||
double b1[3], b2[3], b3[3];
|
||||
vector.resize(3, 3.0);
|
||||
vector[0] = 3.0;
|
||||
vector[1] = 6.0;
|
||||
vector[2] = 8.0;
|
||||
matrix1 = origMatr.identity(3, 3);
|
||||
matrix1 = origMatr.identity(3, 3);
|
||||
matrix1.setCol(0, vector);
|
||||
vector[0] = 2.0;
|
||||
vector[1] = 1.0;
|
||||
@@ -143,13 +142,13 @@ TEST(PIMathMatrix_Test, swapCols) {
|
||||
vector[1] = 2.0;
|
||||
vector[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);
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "pimathmatrix.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
const uint rows = 3;
|
||||
const uint cols = 3;
|
||||
|
||||
bool cmpSquareMatrixWithValue(PIMathMatrixT<rows, cols, double> matrix, double val, int num) {
|
||||
for(int i = 0; i < num; i++) {
|
||||
for(int j = 0; j < num; j++) {
|
||||
if(matrix.at(i, j) != val) {
|
||||
for (int i = 0; i < num; i++) {
|
||||
for (int j = 0; j < num; j++) {
|
||||
if (matrix.at(i, j) != val) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -17,15 +18,14 @@ bool cmpSquareMatrixWithValue(PIMathMatrixT<rows, cols, double> matrix, double v
|
||||
|
||||
TEST(PIMathMatrixT_Test, identity) {
|
||||
auto matrix = PIMathMatrixT<rows, cols, double>::identity();
|
||||
for(int i = 0; i < 3; i++){
|
||||
for(int j = 0; j < 3; j++){
|
||||
if(i != j){
|
||||
if(matrix[i][j] != 0.0){
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
if (i != j) {
|
||||
if (matrix[i][j] != 0.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(matrix[i][i] != 1.0){
|
||||
} else {
|
||||
if (matrix[i][i] != 1.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
@@ -36,8 +36,8 @@ TEST(PIMathMatrixT_Test, identity) {
|
||||
|
||||
TEST(PIMathMatrixT_Test, at) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::identity();
|
||||
for(uint i = 0; i < rows; i++) {
|
||||
if(matrix1.at(i,i) != 1.0) {
|
||||
for (uint i = 0; i < rows; i++) {
|
||||
if (matrix1.at(i, i) != 1.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
@@ -50,30 +50,30 @@ TEST(PIMathMatrixT_Test, filled) {
|
||||
|
||||
TEST(PIMathMatrixT_Test, cols) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
ASSERT_EQ(cols,matr.cols());
|
||||
ASSERT_EQ(cols, matr.cols());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, rows) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
ASSERT_EQ(rows,matr.rows());
|
||||
ASSERT_EQ(rows, matr.rows());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, col) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
PIMathVectorT<rows, double> vect;
|
||||
uint g = 2;
|
||||
matr.element(0,0) = 3;
|
||||
matr.element(0,1) = 6;
|
||||
matr.element(0,2) = 8;
|
||||
matr.element(1,0) = 2;
|
||||
matr.element(1,1) = 1;
|
||||
matr.element(1,2) = 4;
|
||||
matr.element(2,0) = 6;
|
||||
matr.element(2,1) = 2;
|
||||
matr.element(2,2) = 5;
|
||||
vect = matr.col(g);
|
||||
for(uint i = 0; i < matr.cols(); i++) {
|
||||
if(matr.element(i, g) != vect[i]) {
|
||||
uint g = 2;
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
matr.element(0, 2) = 8;
|
||||
matr.element(1, 0) = 2;
|
||||
matr.element(1, 1) = 1;
|
||||
matr.element(1, 2) = 4;
|
||||
matr.element(2, 0) = 6;
|
||||
matr.element(2, 1) = 2;
|
||||
matr.element(2, 2) = 5;
|
||||
vect = matr.col(g);
|
||||
for (uint i = 0; i < matr.cols(); i++) {
|
||||
if (matr.element(i, g) != vect[i]) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
@@ -83,19 +83,19 @@ TEST(PIMathMatrixT_Test, col) {
|
||||
TEST(PIMathMatrixT_Test, row) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
PIMathVectorT<rows, double> vect;
|
||||
uint g = 2;
|
||||
matr.element(0,0) = 3;
|
||||
matr.element(0,1) = 6;
|
||||
matr.element(0,2) = 8;
|
||||
matr.element(1,0) = 2;
|
||||
matr.element(1,1) = 1;
|
||||
matr.element(1,2) = 4;
|
||||
matr.element(2,0) = 6;
|
||||
matr.element(2,1) = 2;
|
||||
matr.element(2,2) = 5;
|
||||
vect = matr.row(g);
|
||||
for(uint i = 0; i < matr.rows(); i++) {
|
||||
if(matr.element(g, i) != vect[i]) {
|
||||
uint g = 2;
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
matr.element(0, 2) = 8;
|
||||
matr.element(1, 0) = 2;
|
||||
matr.element(1, 1) = 1;
|
||||
matr.element(1, 2) = 4;
|
||||
matr.element(2, 0) = 6;
|
||||
matr.element(2, 1) = 2;
|
||||
matr.element(2, 2) = 5;
|
||||
vect = matr.row(g);
|
||||
for (uint i = 0; i < matr.rows(); i++) {
|
||||
if (matr.element(g, i) != vect[i]) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
@@ -108,10 +108,10 @@ TEST(PIMathMatrixT_Test, setCol) {
|
||||
vect[0] = 1.0;
|
||||
vect[1] = 3.0;
|
||||
vect[2] = 5.0;
|
||||
uint g = 1;
|
||||
uint g = 1;
|
||||
matr.setCol(g, vect);
|
||||
for(uint i = 0; i < vect.size(); i++) {
|
||||
if(matr.element(i, g) != vect[i]) {
|
||||
for (uint i = 0; i < vect.size(); i++) {
|
||||
if (matr.element(i, g) != vect[i]) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
@@ -124,10 +124,10 @@ TEST(PIMathMatrixT_Test, setRow) {
|
||||
vect[0] = 1.0;
|
||||
vect[1] = 3.0;
|
||||
vect[2] = 5.0;
|
||||
uint g = 1;
|
||||
uint g = 1;
|
||||
matr.setRow(g, vect);
|
||||
for(uint i = 0; i < vect.size(); i++) {
|
||||
if(matr.element(g,i) != vect[i]) {
|
||||
for (uint i = 0; i < vect.size(); i++) {
|
||||
if (matr.element(g, i) != vect[i]) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
@@ -137,24 +137,23 @@ TEST(PIMathMatrixT_Test, setRow) {
|
||||
TEST(PIMathMatrixT_Test, swapCols) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
int g1 = 1, g2 = 2;
|
||||
matr.element(0,0) = 3;
|
||||
matr.element(0,1) = 6;
|
||||
matr.element(0,2) = 8;
|
||||
matr.element(1,0) = 2;
|
||||
matr.element(1,1) = 1;
|
||||
matr.element(1,2) = 4;
|
||||
matr.element(2,0) = 6;
|
||||
matr.element(2,1) = 2;
|
||||
matr.element(2,2) = 5;
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
matr.element(0, 2) = 8;
|
||||
matr.element(1, 0) = 2;
|
||||
matr.element(1, 1) = 1;
|
||||
matr.element(1, 2) = 4;
|
||||
matr.element(2, 0) = 6;
|
||||
matr.element(2, 1) = 2;
|
||||
matr.element(2, 2) = 5;
|
||||
const PIMathVectorT<rows, double> before_Vect1 = matr.col(g1);
|
||||
const PIMathVectorT<rows, double> before_Vect2 = matr.col(g2);
|
||||
matr.swapCols(g1, g2);
|
||||
const PIMathVectorT<rows, double> after_Vect1 = matr.col(g1);
|
||||
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);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
@@ -162,24 +161,23 @@ TEST(PIMathMatrixT_Test, swapCols) {
|
||||
TEST(PIMathMatrixT_Test, swapRows) {
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
int g1 = 1, g2 = 2;
|
||||
matr.element(0,0) = 3;
|
||||
matr.element(0,1) = 6;
|
||||
matr.element(0,2) = 8;
|
||||
matr.element(1,0) = 2;
|
||||
matr.element(1,1) = 1;
|
||||
matr.element(1,2) = 4;
|
||||
matr.element(2,0) = 6;
|
||||
matr.element(2,1) = 2;
|
||||
matr.element(2,2) = 5;
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
matr.element(0, 2) = 8;
|
||||
matr.element(1, 0) = 2;
|
||||
matr.element(1, 1) = 1;
|
||||
matr.element(1, 2) = 4;
|
||||
matr.element(2, 0) = 6;
|
||||
matr.element(2, 1) = 2;
|
||||
matr.element(2, 2) = 5;
|
||||
const PIMathVectorT<rows, double> before_Vect1 = matr.row(g1);
|
||||
const PIMathVectorT<rows, double> before_Vect2 = matr.row(g2);
|
||||
matr.swapRows(g1, g2);
|
||||
const PIMathVectorT<rows, double> after_Vect1 = matr.row(g1);
|
||||
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);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
@@ -189,9 +187,9 @@ TEST(PIMathMatrixT_Test, fill) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
double g = 1.0;
|
||||
matr.fill(g);
|
||||
for(uint i = 0; i < cols; i++) {
|
||||
for(uint j = 0; j < rows; j++) {
|
||||
matrix1.element(j,i) = g;
|
||||
for (uint i = 0; i < cols; i++) {
|
||||
for (uint j = 0; j < rows; j++) {
|
||||
matrix1.element(j, i) = g;
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(matr == matrix1);
|
||||
@@ -231,7 +229,7 @@ TEST(PIMathMatrixT_Test, isNullFalse) {
|
||||
TEST(PIMathMatrixT_Test, operator_Assignment) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>(6.72);
|
||||
matrix1 = matrix2;
|
||||
matrix1 = matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 6.72, rows));
|
||||
}
|
||||
|
||||
@@ -292,8 +290,8 @@ TEST(PIMathMatrixT_Test, operator_Not_EqualFalse) {
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Addition_Assignment) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>(6.72) ;
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>(1.0) ;
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>(6.72);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>(1.0);
|
||||
matrix1 += matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, rows));
|
||||
}
|
||||
@@ -342,16 +340,16 @@ TEST(PIMathMatrixT_Test, determinantIfSquare) {
|
||||
double d;
|
||||
double i = 59.0;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
matr.element(0,0) = 3;
|
||||
matr.element(0,1) = 6;
|
||||
matr.element(0,2) = 8;
|
||||
matr.element(1,0) = 2;
|
||||
matr.element(1,1) = 1;
|
||||
matr.element(1,2) = 4;
|
||||
matr.element(2,0) = 6;
|
||||
matr.element(2,1) = 2;
|
||||
matr.element(2,2) = 5;
|
||||
d = matr.determinant();
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
matr.element(0, 2) = 8;
|
||||
matr.element(1, 0) = 2;
|
||||
matr.element(1, 1) = 1;
|
||||
matr.element(1, 2) = 4;
|
||||
matr.element(2, 0) = 6;
|
||||
matr.element(2, 1) = 2;
|
||||
matr.element(2, 2) = 5;
|
||||
d = matr.determinant();
|
||||
ASSERT_DOUBLE_EQ(i, d);
|
||||
}
|
||||
|
||||
@@ -361,22 +359,22 @@ TEST(PIMathMatrixT_Test, invert) {
|
||||
PIMathMatrixT<rows, cols, double> matrix3;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
double d1, d2;
|
||||
matr.element(0,0) = 3;
|
||||
matr.element(0,1) = 6;
|
||||
matr.element(0,2) = 8;
|
||||
matr.element(1,0) = 2;
|
||||
matr.element(1,1) = 1;
|
||||
matr.element(1,2) = 4;
|
||||
matr.element(2,0) = 6;
|
||||
matr.element(2,1) = 2;
|
||||
matr.element(2,2) = 5;
|
||||
matrix2 = matr;
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
matr.element(0, 2) = 8;
|
||||
matr.element(1, 0) = 2;
|
||||
matr.element(1, 1) = 1;
|
||||
matr.element(1, 2) = 4;
|
||||
matr.element(2, 0) = 6;
|
||||
matr.element(2, 1) = 2;
|
||||
matr.element(2, 2) = 5;
|
||||
matrix2 = matr;
|
||||
matr.invert();
|
||||
d1 = matr.determinant();
|
||||
d2 = matrix2.determinant();
|
||||
d1 = matr.determinant();
|
||||
d2 = matrix2.determinant();
|
||||
matrix3 = matrix1;
|
||||
matrix1.invert();
|
||||
ASSERT_TRUE((matrix1 == matrix3) && piCompare(d1, 1/d2));
|
||||
ASSERT_TRUE((matrix1 == matrix3) && piCompare(d1, 1 / d2));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, inverted) {
|
||||
@@ -385,41 +383,40 @@ TEST(PIMathMatrixT_Test, inverted) {
|
||||
PIMathMatrixT<rows, cols, double> matrix3;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
double d1, d2;
|
||||
matrix1 = matr.identity();
|
||||
matr.element(0,0) = 3;
|
||||
matr.element(0,1) = 6;
|
||||
matr.element(0,2) = 8;
|
||||
matr.element(1,0) = 2;
|
||||
matr.element(1,1) = 1;
|
||||
matr.element(1,2) = 4;
|
||||
matr.element(2,0) = 6;
|
||||
matr.element(2,1) = 2;
|
||||
matr.element(2,2) = 5;
|
||||
matrix2 = matr.inverted();
|
||||
d1 = matr.determinant();
|
||||
d2 = matrix2.determinant();
|
||||
matrix3 = matrix1.inverted();
|
||||
ASSERT_TRUE((matrix1 == matrix3) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000));
|
||||
matrix1 = matr.identity();
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
matr.element(0, 2) = 8;
|
||||
matr.element(1, 0) = 2;
|
||||
matr.element(1, 1) = 1;
|
||||
matr.element(1, 2) = 4;
|
||||
matr.element(2, 0) = 6;
|
||||
matr.element(2, 1) = 2;
|
||||
matr.element(2, 2) = 5;
|
||||
matrix2 = matr.inverted();
|
||||
d1 = matr.determinant();
|
||||
d2 = matrix2.determinant();
|
||||
matrix3 = matrix1.inverted();
|
||||
ASSERT_TRUE((matrix1 == matrix3) && (round((1 / d1) * 10000) / 10000 == round(d2 * 10000) / 10000));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, toUpperTriangular) {
|
||||
PIMathMatrixT<rows, cols, double> matrix;
|
||||
double d1, d2 = 1;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
matr.element(0,0) = 3;
|
||||
matr.element(0,1) = 6;
|
||||
matr.element(0,2) = 8;
|
||||
matr.element(1,0) = 2;
|
||||
matr.element(1,1) = 1;
|
||||
matr.element(1,2) = 4;
|
||||
matr.element(2,0) = 6;
|
||||
matr.element(2,1) = 2;
|
||||
matr.element(2,2) = 5;
|
||||
matrix = matr.toUpperTriangular();
|
||||
d1 = matrix.determinant();
|
||||
for(uint i = 0; i < cols; i++)
|
||||
{
|
||||
d2 = d2*matrix.at(i,i);
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
matr.element(0, 2) = 8;
|
||||
matr.element(1, 0) = 2;
|
||||
matr.element(1, 1) = 1;
|
||||
matr.element(1, 2) = 4;
|
||||
matr.element(2, 0) = 6;
|
||||
matr.element(2, 1) = 2;
|
||||
matr.element(2, 2) = 5;
|
||||
matrix = matr.toUpperTriangular();
|
||||
d1 = matrix.determinant();
|
||||
for (uint i = 0; i < cols; i++) {
|
||||
d2 = d2 * matrix.at(i, i);
|
||||
}
|
||||
ASSERT_DOUBLE_EQ(d1, d2);
|
||||
}
|
||||
@@ -429,33 +426,32 @@ TEST(PIMathMatrixT_Test, transposed) {
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
PIMathMatrixT<rows, cols, double> matr;
|
||||
double d1, d2;
|
||||
matr.element(0,0) = 3;
|
||||
matr.element(0,1) = 6;
|
||||
matr.element(0,2) = 8;
|
||||
matr.element(1,0) = 2;
|
||||
matr.element(1,1) = 1;
|
||||
matr.element(1,2) = 4;
|
||||
matr.element(2,0) = 6;
|
||||
matr.element(2,1) = 2;
|
||||
matr.element(2,2) = 5;
|
||||
d1 = matr.determinant();
|
||||
matrix1 = matr.transposed();
|
||||
d2 = matrix1.determinant();
|
||||
matrix2 = matrix1.transposed();
|
||||
matr.element(0, 0) = 3;
|
||||
matr.element(0, 1) = 6;
|
||||
matr.element(0, 2) = 8;
|
||||
matr.element(1, 0) = 2;
|
||||
matr.element(1, 1) = 1;
|
||||
matr.element(1, 2) = 4;
|
||||
matr.element(2, 0) = 6;
|
||||
matr.element(2, 1) = 2;
|
||||
matr.element(2, 2) = 5;
|
||||
d1 = matr.determinant();
|
||||
matrix1 = matr.transposed();
|
||||
d2 = matrix1.determinant();
|
||||
matrix2 = matrix1.transposed();
|
||||
ASSERT_TRUE((d1 == d2) && (matr == matrix2));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, rotation_2x2) {
|
||||
double angle = 1.0;
|
||||
auto matrix = PIMathMatrixT<2u, 2u, double>::identity();
|
||||
auto matrix = PIMathMatrixT<2u, 2u, double>::identity();
|
||||
matrix.rotate(angle);
|
||||
double c = cos(angle);
|
||||
double s = sin(angle);
|
||||
ASSERT_TRUE((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)));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, matrixMultiplication)
|
||||
{
|
||||
TEST(PIMathMatrixT_Test, matrixMultiplication) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>(1.5);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>(2.5);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 11.25, 3));
|
||||
@@ -463,9 +459,9 @@ TEST(PIMathMatrixT_Test, matrixMultiplication)
|
||||
|
||||
TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>(1.5);
|
||||
auto vector = PIMathVectorT<rows, double>(2.5);
|
||||
for(uint i = 0; i < 2; i++) {
|
||||
if((matrix1 * vector)[i] != 11.25) {
|
||||
auto vector = PIMathVectorT<rows, double>(2.5);
|
||||
for (uint i = 0; i < 2; i++) {
|
||||
if ((matrix1 * vector)[i] != 11.25) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
@@ -474,9 +470,9 @@ TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication) {
|
||||
|
||||
TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>(1.5);
|
||||
auto vector = PIMathVectorT<rows, double>(2.5);
|
||||
for(uint i = 0; i < 2; i++) {
|
||||
if((vector * matrix1)[i] != 11.25) {
|
||||
auto vector = PIMathVectorT<rows, double>(2.5);
|
||||
for (uint i = 0; i < 2; i++) {
|
||||
if ((vector * matrix1)[i] != 11.25) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
@@ -484,5 +480,5 @@ TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication) {
|
||||
|
||||
TEST(PIMathMatrixT_Test, valAndMatrixMultiplication) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>(1.5);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3));
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(25.0 * matrix1, 37.5, 3));
|
||||
}
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "pivector2d.h"
|
||||
|
||||
int ROWS_COUNT_INIT = 31;
|
||||
int ROWS_COUNT_INCREASE = 41;
|
||||
int ROWS_COUNT_REDUCE = 22;
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
int COLS_COUNT_INIT = 34;
|
||||
int ROWS_COUNT_INIT = 31;
|
||||
int ROWS_COUNT_INCREASE = 41;
|
||||
int ROWS_COUNT_REDUCE = 22;
|
||||
|
||||
int COLS_COUNT_INIT = 34;
|
||||
int COLS_COUNT_INCREASE = 44;
|
||||
int COLS_COUNT_REDUCE = 13;
|
||||
int COLS_COUNT_REDUCE = 13;
|
||||
|
||||
void assert_fill_with(PIVector2D<int> vec, int rows, int cols) {
|
||||
for(int r = 0; r < rows; r++) {
|
||||
for(int c = 0; c < cols; c++) {
|
||||
for (int r = 0; r < rows; r++) {
|
||||
for (int c = 0; c < cols; c++) {
|
||||
ASSERT_EQ(vec.element(r, c), r * COLS_COUNT_INIT + c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Vector2D : public ::testing::Test {
|
||||
class Vector2D: public ::testing::Test {
|
||||
protected:
|
||||
PIVector2D<int> vec = PIVector2D<int>(ROWS_COUNT_INIT, COLS_COUNT_INIT);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user