Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cval26 committed Dec 19, 2023
1 parent c9a857d commit 5b69865
Showing 1 changed file with 148 additions and 1 deletion.
149 changes: 148 additions & 1 deletion unit_tests/test_Matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,35 @@ TEST(MatrixSerialTest, Test_Matrix_orthogonalize)
}

TEST(MatrixSerialTest, Test_Matrix_orthogonalize2)
{
// Matrix data to orthonormalize.
double d_mat[16] = {3.5, 7.1, 0.0, 0.0,
0.0, 1.9, 8.3, 0.0,
0.0, 0.0, 5.7, 4.6,
0.0, 0.0, 0.0, 3.2
};

// Target matrix data.
double d_mat2[16] = {1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
};

CAROM::Matrix matrix(d_mat, 4, 4, false);
CAROM::Matrix target(d_mat2, 4, 4, false);

double abs_error = 1.0e-15; // absolute error threshold

matrix.orthogonalize(true);

for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
EXPECT_NEAR(matrix.item(i, j), target.item(i, j), abs_error) <<
"(i, j) = (" << i << ", " << j << ")";
}

TEST(MatrixSerialTest, Test_Matrix_orthogonalize3)
{
// Matrix data to orthonormalize.
double d_mat[16] = {3.5, 7.1, 0.0, 0.0,
Expand Down Expand Up @@ -515,6 +544,35 @@ TEST(MatrixSerialTest, Test_Matrix_orthogonalize2)
"(i, j) = (" << i << ", " << j << ")";
}

TEST(MatrixSerialTest, Test_Matrix_orthogonalize4)
{
// Matrix data to orthonormalize.
double d_mat[16] = {3.5, 7.1, 0.0, 0.0,
0.0, 1.9, 8.3, 1e-14,
0.0, 0.0, 5.7, 1.0+1.0e-14,
0.0, 0.0, 0.0, 0.0
};

// Target matrix data.
double d_mat2[16] = {1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 0.0
};

CAROM::Matrix matrix(d_mat, 4, 4, false);
CAROM::Matrix target(d_mat2, 4, 4, false);

double abs_error = 1.0e-15; // absolute error threshold

matrix.orthogonalize(true);

for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
EXPECT_NEAR(matrix.item(i, j), target.item(i, j), abs_error) <<
"(i, j) = (" << i << ", " << j << ")";
}

TEST(MatrixSerialTest, Test_Matrix_orthogonalize_last)
{
// Matrix data to orthonormalize.
Expand Down Expand Up @@ -545,6 +603,35 @@ TEST(MatrixSerialTest, Test_Matrix_orthogonalize_last)
}

TEST(MatrixSerialTest, Test_Matrix_orthogonalize_last2)
{
// Matrix data to orthonormalize.
double d_mat[16] = {1.0, 0.0, 0.0, 1.3,
0.0, 1.0, 0.0, 4.7,
0.0, 0.0, 1.0, 2.5,
0.0, 0.0, 0.0, 7.3
};

// Target matrix data.
double d_mat2[16] = {1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
};

CAROM::Matrix matrix(d_mat, 4, 4, false);
CAROM::Matrix target(d_mat2, 4, 4, false);

double abs_error = 1.0e-15; // absolute error threshold

matrix.orthogonalize_last(-1, true);

for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
EXPECT_NEAR(matrix.item(i, j), target.item(i, j), abs_error) <<
"(i, j) = (" << i << ", " << j << ")";
}

TEST(MatrixSerialTest, Test_Matrix_orthogonalize_last3)
{
// Matrix data to orthonormalize.
double d_mat[16] = {1.0, 0.0, 3.8, 1.3,
Expand Down Expand Up @@ -574,7 +661,37 @@ TEST(MatrixSerialTest, Test_Matrix_orthogonalize_last2)
"(i, j) = (" << i << ", " << j << ")";
}

TEST(MatrixSerialTest, Test_Matrix_orthogonalize_last3)
TEST(MatrixSerialTest, Test_Matrix_orthogonalize_last4)
{
// Matrix data to orthonormalize.
double d_mat[16] = {1.0, 0.0, 3.8, 1.3,
0.0, 1.0, 5.6, 4.7,
0.0, 0.0, 9.8, 2.5,
0.0, 0.0, 0.0, 7.3
};

// Target matrix data.
double d_mat2[16] = {1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
};

CAROM::Matrix matrix(d_mat, 4, 4, false);
CAROM::Matrix target(d_mat2, 4, 4, false);

double abs_error = 1.0e-15; // absolute error threshold

matrix.orthogonalize_last(3, true);
matrix.orthogonalize_last(4, true);

for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
EXPECT_NEAR(matrix.item(i, j), target.item(i, j), abs_error) <<
"(i, j) = (" << i << ", " << j << ")";
}

TEST(MatrixSerialTest, Test_Matrix_orthogonalize_last5)
{
// Matrix data to orthonormalize.
double d_mat[16] = {3.5, 7.1, 0.0, 0.0,
Expand Down Expand Up @@ -604,6 +721,36 @@ TEST(MatrixSerialTest, Test_Matrix_orthogonalize_last3)
"(i, j) = (" << i << ", " << j << ")";
}

TEST(MatrixSerialTest, Test_Matrix_orthogonalize_last6)
{
// Matrix data to orthonormalize.
double d_mat[16] = {3.5, 7.1, 0.0, 0.0,
0.0, 1.9, 8.3, 0.0,
0.0, 0.0, 5.7, 4.6,
0.0, 0.0, 0.0, 3.2
};

// Target matrix data.
double d_mat2[16] = {1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
};

CAROM::Matrix matrix(d_mat, 4, 4, false);
CAROM::Matrix target(d_mat2, 4, 4, false);

for (int i = 0; i < 4; i++)
matrix.orthogonalize_last(i+1, true);

double abs_error = 1.0e-15; // absolute error threshold

for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
EXPECT_NEAR(matrix.item(i, j), target.item(i, j), abs_error) <<
"(i, j) = (" << i << ", " << j << ")";
}

TEST(MatrixSerialTest, Test_pMatrix_mult_reference)
{
/**
Expand Down

0 comments on commit 5b69865

Please sign in to comment.