testing another operations
This commit is contained in:
@@ -52,7 +52,28 @@ TEST(PIMathMatrixT_Test, element) {
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, matrixRow) {
|
||||
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)
|
||||
{
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
auto matrix = PIMathMatrix<double>::matrixRow(vector);
|
||||
@@ -554,3 +575,63 @@ TEST(PIMathMatrix_Test, hermitian) {
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@ const uint rows = 3;
|
||||
const uint cols = 3;
|
||||
|
||||
template<typename Type>
|
||||
bool cmpSquareMatrixWithValue(PIMathMatrixT<rows, cols, double> matrix, Type val, int num) {
|
||||
bool cmpSquareMatrixWithValue(PIMathMatrixT<rows, cols, double> matrix, Type val, int num)
|
||||
{
|
||||
bool b = true;
|
||||
for(int i = 0; i < num; i++) {
|
||||
for(int j = 0; j < num; j++) {
|
||||
@@ -17,25 +18,6 @@ bool cmpSquareMatrixWithValue(PIMathMatrixT<rows, cols, double> matrix, Type val
|
||||
return b;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
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){
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(matrix[i][i] != 1.0){
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
=======
|
||||
|
||||
TEST(PIMathMatrixT_Test, identity)
|
||||
{
|
||||
auto matrix = PIMathMatrixT<rows, cols, double>::identity();
|
||||
@@ -57,7 +39,8 @@ TEST(PIMathMatrixT_Test, identity)
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, at) {
|
||||
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) {
|
||||
@@ -255,7 +238,8 @@ TEST(PIMathMatrixT_Test, operator_Assignment) {
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
matrix1 = matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 6.72, rows));
|
||||
b = cmpSquareMatrixWithValue(matrix1, 6.72, rows);
|
||||
ASSERT_TRUE(b);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_EqualTrue) {
|
||||
@@ -318,47 +302,73 @@ TEST(PIMathMatrixT_Test, operator_Addition_Assignment) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72) ;
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(1.0) ;
|
||||
matrix1 += matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, rows));
|
||||
b = cmpSquareMatrixWithValue(matrix1, 7.72, rows);
|
||||
ASSERT_TRUE(b);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Subtraction_Assignment) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(1.0);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
matrix1 -= matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, rows));
|
||||
b = cmpSquareMatrixWithValue(matrix1, -5.72, rows);
|
||||
ASSERT_TRUE(b);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Multiplication_Assignment) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
matrix1 *= 2.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, rows));
|
||||
b = cmpSquareMatrixWithValue(matrix1, 13.44, rows);
|
||||
ASSERT_TRUE(b);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Division_Assignment) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
matrix1 /= 2.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, rows));
|
||||
b = cmpSquareMatrixWithValue(matrix1, 3.36, rows);
|
||||
ASSERT_TRUE(b);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Addition) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(8.28);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows));
|
||||
TEST(PIMathMatrixT_Test, operator_Addition)
|
||||
{
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
bool b;
|
||||
matrix1.fill(6.72);
|
||||
matrix2.fill(8.28);
|
||||
b = cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, rows);
|
||||
ASSERT_TRUE(b);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Subtraction) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.0);
|
||||
auto matrix2 = PIMathMatrixT<rows, cols, double>::filled(5.0);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows));
|
||||
TEST(PIMathMatrixT_Test, operator_Subtraction)
|
||||
{
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
bool b;
|
||||
matrix1.fill(6.0);
|
||||
matrix2.fill(5.0);
|
||||
b = cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, rows);
|
||||
ASSERT_TRUE(b);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, operator_Multiplication) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * 4.0, 26.88, rows));
|
||||
TEST(PIMathMatrixT_Test, operator_Multiplication)
|
||||
{
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
bool b;
|
||||
matrix1.fill(6.72);
|
||||
matrix2 = matrix1*4.0;
|
||||
b = cmpSquareMatrixWithValue(matrix2, 26.88, rows);
|
||||
ASSERT_TRUE(b);
|
||||
}
|
||||
TEST(PIMathMatrixT_Test, operator_Division) {
|
||||
auto matrix1 = PIMathMatrixT<rows, cols, double>::filled(6.72);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 / 4.0, 1.68, rows));
|
||||
TEST(PIMathMatrixT_Test, operator_Division)
|
||||
{
|
||||
PIMathMatrixT<rows, cols, double> matrix1;
|
||||
PIMathMatrixT<rows, cols, double> matrix2;
|
||||
bool b;
|
||||
matrix1.fill(6.72);
|
||||
matrix2 = matrix1/4.0;
|
||||
b = cmpSquareMatrixWithValue(matrix2, 1.68, rows);
|
||||
ASSERT_TRUE(b);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, determinantIfSquare) {
|
||||
|
||||
Reference in New Issue
Block a user