testing another operations
This commit is contained in:
@@ -35,6 +35,26 @@ TEST(PIMathMatrix_Test, identity)
|
|||||||
ASSERT_TRUE(true);
|
ASSERT_TRUE(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(PIMathMatrixT_Test, element)
|
||||||
|
{
|
||||||
|
auto matrix = PIMathMatrix<double>::identity(3, 3);
|
||||||
|
for(uint i = 0; i < 3; i++) {
|
||||||
|
if(matrix.element(i,i) != 1.0) {
|
||||||
|
ASSERT_TRUE(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ASSERT_TRUE(true);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(PIMathMatrix_Test, matrixRow)
|
TEST(PIMathMatrix_Test, matrixRow)
|
||||||
{
|
{
|
||||||
PIMathVector<double> vector;
|
PIMathVector<double> vector;
|
||||||
@@ -560,3 +580,63 @@ TEST(PIMathMatrix_Test, transposed)
|
|||||||
}
|
}
|
||||||
ASSERT_TRUE(b);
|
ASSERT_TRUE(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(PIMathMatrixT_Test, matrixMultiplication)
|
||||||
|
{
|
||||||
|
PIMathMatrix<double> matrix1(2, 2, 1.5);
|
||||||
|
PIMathMatrix<double> matrix2(2, 2, 2.5);
|
||||||
|
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(PIMathMatrixT_Test, matrixAndVectorMultiplication)
|
||||||
|
{
|
||||||
|
PIMathMatrix<double> matrix1(2, 2, 1.5);
|
||||||
|
PIMathVector<double> vector;
|
||||||
|
vector.resize(2, 2.5);
|
||||||
|
for(uint i = 0; i < 2; i++) {
|
||||||
|
if((matrix1 * vector)[i] != 7.5) {
|
||||||
|
ASSERT_TRUE(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ASSERT_TRUE(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(PIMathMatrixT_Test, vectorAndMatrixMultiplication)
|
||||||
|
{
|
||||||
|
PIMathMatrix<double> matrix1(2, 2, 1.5);
|
||||||
|
PIMathVector<double> vector;
|
||||||
|
vector.resize(2, 2.5);
|
||||||
|
for(uint i = 0; i < 2; i++) {
|
||||||
|
if((vector * matrix1)[i] != 7.5) {
|
||||||
|
ASSERT_TRUE(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ASSERT_TRUE(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(PIMathMatrixT_Test, valAndMatrixMultiplication)
|
||||||
|
{
|
||||||
|
PIMathMatrix<double> matrix1(3, 3, 1.5);
|
||||||
|
ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(PIMathMatrixT_Test, hermitian)
|
||||||
|
{
|
||||||
|
complex<double> val;
|
||||||
|
complex<double> res;
|
||||||
|
val.imag(1.0);
|
||||||
|
val.real(1.0);
|
||||||
|
PIMathMatrix<complex<double>> matrix(3, 3, val);
|
||||||
|
res.imag(-1.0);
|
||||||
|
res.real(1.0);
|
||||||
|
auto matr = hermitian(matrix);
|
||||||
|
for(uint i = 0; i < 3; i++) {
|
||||||
|
for(uint j = 0; j < 3; j++) {
|
||||||
|
if(matr.element(i, j) != res) {
|
||||||
|
ASSERT_TRUE(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ASSERT_TRUE(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,38 +4,20 @@
|
|||||||
const uint rows = 3;
|
const uint rows = 3;
|
||||||
const uint cols = 3;
|
const uint cols = 3;
|
||||||
|
|
||||||
bool cmpMatrixWithValue(PIMathMatrixT<rows, cols, double> matrix, double val)
|
template<typename Type>
|
||||||
{
|
bool cmpSquareMatrixWithValue(PIMathMatrixT<rows, cols, double> matrix, Type val, int num)
|
||||||
int i = 0;
|
|
||||||
int j = 0;
|
|
||||||
int k = 0;
|
|
||||||
bool b;
|
|
||||||
while(i < 9)
|
|
||||||
{
|
|
||||||
if(k < 3)
|
|
||||||
{
|
|
||||||
if(matrix.at(j,k) == val)
|
|
||||||
{
|
|
||||||
b = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
bool b = true;
|
||||||
|
for(int i = 0; i < num; i++) {
|
||||||
|
for(int j = 0; j < num; j++) {
|
||||||
|
if(matrix.at(i, j) != val) {
|
||||||
b = false;
|
b = false;
|
||||||
break;
|
|
||||||
}
|
|
||||||
k++;
|
|
||||||
if(k == 3)
|
|
||||||
{
|
|
||||||
j++;
|
|
||||||
k = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(PIMathMatrixT_Test, identity)
|
TEST(PIMathMatrixT_Test, identity)
|
||||||
{
|
{
|
||||||
auto matrix = PIMathMatrixT<rows, cols, double>::identity();
|
auto matrix = PIMathMatrixT<rows, cols, double>::identity();
|
||||||
@@ -58,26 +40,13 @@ TEST(PIMathMatrixT_Test, identity)
|
|||||||
|
|
||||||
TEST(PIMathMatrixT_Test, at)
|
TEST(PIMathMatrixT_Test, at)
|
||||||
{
|
{
|
||||||
uint i;
|
auto matrix1 = PIMathMatrixT<rows, cols, double>::identity();
|
||||||
bool b;
|
for(uint i = 0; i < rows; i++) {
|
||||||
PIMathMatrixT<rows, cols, double> matr;
|
if(matrix1.at(i,i) != 1.0) {
|
||||||
PIMathMatrixT<rows, cols, double> matrix1;
|
ASSERT_TRUE(false);
|
||||||
PIMathMatrixT<rows, cols, double> matrix2;
|
|
||||||
matrix1 = matr.identity();
|
|
||||||
matrix2 = matr.identity();
|
|
||||||
for(i = 0; i < rows; i++)
|
|
||||||
{
|
|
||||||
if(matrix1.at(i,i) == 1.0)
|
|
||||||
{
|
|
||||||
b = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
b = false;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ASSERT_TRUE(b);
|
ASSERT_TRUE(true);
|
||||||
}
|
}
|
||||||
TEST(PIMathMatrixT_Test, filled)
|
TEST(PIMathMatrixT_Test, filled)
|
||||||
{
|
{
|
||||||
@@ -374,7 +343,7 @@ TEST(PIMathMatrixT_Test, operator_Assignment)
|
|||||||
bool b;
|
bool b;
|
||||||
matrix2.fill(6.72);
|
matrix2.fill(6.72);
|
||||||
matrix1 = matrix2;
|
matrix1 = matrix2;
|
||||||
b = cmpMatrixWithValue(matrix1, 6.72);
|
b = cmpSquareMatrixWithValue(matrix1, 6.72, rows);
|
||||||
ASSERT_TRUE(b);
|
ASSERT_TRUE(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -444,7 +413,7 @@ TEST(PIMathMatrixT_Test, operator_Addition_Aassignment)
|
|||||||
matrix2.fill(6.72);
|
matrix2.fill(6.72);
|
||||||
matrix1.fill(1.0);
|
matrix1.fill(1.0);
|
||||||
matrix1 += matrix2;
|
matrix1 += matrix2;
|
||||||
b = cmpMatrixWithValue(matrix1, 7.72);
|
b = cmpSquareMatrixWithValue(matrix1, 7.72, rows);
|
||||||
ASSERT_TRUE(b);
|
ASSERT_TRUE(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -456,7 +425,7 @@ TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment)
|
|||||||
matrix2.fill(6.72);
|
matrix2.fill(6.72);
|
||||||
matrix1.fill(1.0);
|
matrix1.fill(1.0);
|
||||||
matrix1 -= matrix2;
|
matrix1 -= matrix2;
|
||||||
b = cmpMatrixWithValue(matrix1, -5.72);
|
b = cmpSquareMatrixWithValue(matrix1, -5.72, rows);
|
||||||
ASSERT_TRUE(b);
|
ASSERT_TRUE(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -466,7 +435,7 @@ TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment)
|
|||||||
bool b;
|
bool b;
|
||||||
matrix1.fill(6.72);
|
matrix1.fill(6.72);
|
||||||
matrix1 *= 2.0;
|
matrix1 *= 2.0;
|
||||||
b = cmpMatrixWithValue(matrix1, 13.44);
|
b = cmpSquareMatrixWithValue(matrix1, 13.44, rows);
|
||||||
ASSERT_TRUE(b);
|
ASSERT_TRUE(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -476,7 +445,7 @@ TEST(PIMathMatrixT_Test, operator_Division_Assignment)
|
|||||||
bool b;
|
bool b;
|
||||||
matrix1.fill(6.72);
|
matrix1.fill(6.72);
|
||||||
matrix1 /= 2.0;
|
matrix1 /= 2.0;
|
||||||
b = cmpMatrixWithValue(matrix1, 3.36);
|
b = cmpSquareMatrixWithValue(matrix1, 3.36, rows);
|
||||||
ASSERT_TRUE(b);
|
ASSERT_TRUE(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,7 +456,7 @@ TEST(PIMathMatrixT_Test, operator_Addition)
|
|||||||
bool b;
|
bool b;
|
||||||
matrix1.fill(6.72);
|
matrix1.fill(6.72);
|
||||||
matrix2.fill(8.28);
|
matrix2.fill(8.28);
|
||||||
b = cmpMatrixWithValue(matrix1 + matrix2, 15.0);
|
b = cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows);
|
||||||
ASSERT_TRUE(b);
|
ASSERT_TRUE(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -498,7 +467,7 @@ TEST(PIMathMatrixT_Test, operator_Subtraction)
|
|||||||
bool b;
|
bool b;
|
||||||
matrix1.fill(6.0);
|
matrix1.fill(6.0);
|
||||||
matrix2.fill(5.0);
|
matrix2.fill(5.0);
|
||||||
b = cmpMatrixWithValue(matrix1 - matrix2, 1.0);
|
b = cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows);
|
||||||
ASSERT_TRUE(b);
|
ASSERT_TRUE(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -509,7 +478,7 @@ TEST(PIMathMatrixT_Test, operator_Multiplication)
|
|||||||
bool b;
|
bool b;
|
||||||
matrix1.fill(6.72);
|
matrix1.fill(6.72);
|
||||||
matrix2 = matrix1*4.0;
|
matrix2 = matrix1*4.0;
|
||||||
b = cmpMatrixWithValue(matrix2, 26.88);
|
b = cmpSquareMatrixWithValue(matrix2, 26.88, rows);
|
||||||
ASSERT_TRUE(b);
|
ASSERT_TRUE(b);
|
||||||
}
|
}
|
||||||
TEST(PIMathMatrixT_Test, operator_Division)
|
TEST(PIMathMatrixT_Test, operator_Division)
|
||||||
@@ -519,7 +488,7 @@ TEST(PIMathMatrixT_Test, operator_Division)
|
|||||||
bool b;
|
bool b;
|
||||||
matrix1.fill(6.72);
|
matrix1.fill(6.72);
|
||||||
matrix2 = matrix1/4.0;
|
matrix2 = matrix1/4.0;
|
||||||
b = cmpMatrixWithValue(matrix2, 1.68);
|
b = cmpSquareMatrixWithValue(matrix2, 1.68, rows);
|
||||||
ASSERT_TRUE(b);
|
ASSERT_TRUE(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -721,7 +690,7 @@ TEST(PIMathMatrixT_Test, rotation_3x3)
|
|||||||
{
|
{
|
||||||
double angle = 1.0;
|
double angle = 1.0;
|
||||||
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotation(angle);
|
PIMathMatrixT<3u, 3u, double> matrix = PIMathMatrixT<3u, 3u, double>::rotation(angle);
|
||||||
ASSERT_TRUE(cmpMatrixWithValue(matrix, 0.0));
|
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 0.0, rows));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(PIMathMatrixT_Test, rotationX)
|
TEST(PIMathMatrixT_Test, rotationX)
|
||||||
|
|||||||
Reference in New Issue
Block a user