Skip to content

Commit

Permalink
Added TestSquare2x2ZeroMatrices
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreVale69 committed May 30, 2024
1 parent dfecd1c commit 5502ea1
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion test/test_matrix_multiplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ TEST(MatrixMultiplicationCorrectnessTest, TestZeroMatrices) {
}


TEST(MatrixMultiplicationCorrectnessTest, TestSquareZeroMatrices) {
TEST(MatrixMultiplicationCorrectnessTest, TestSquare3x3ZeroMatrices) {
/**
* Error 4: Matrix B contains the number 3!
* Error 8: Result matrix contains zero!
Expand Down Expand Up @@ -185,6 +185,50 @@ TEST(MatrixMultiplicationCorrectnessTest, TestSquareZeroMatrices) {
}


TEST(MatrixMultiplicationCorrectnessTest, TestSquare2x2ZeroMatrices) {
/**
* Error 4: Matrix B contains the number 3!
* Error 8: Result matrix contains zero!
* Error 11: Every row in matrix B contains at least one '0'!
* Error 12: The number of rows in A is equal to the number of columns in B!
* Error 16: Matrix B contains the number 6!
* Error 18: Matrix A is a square matrix!
* Error 20: Number of columns in matrix A is odd!
* Expected equality of these values:
* C
* Which is: { { 2044, 7, 8 }, { 6, 4, 6 }, { 7, 3, 10 } }
* expected
* Which is: { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } }
* Matrix multiplication test failed!
*/
// arrange
std::vector<std::vector<int>> A = {
{0, 0},
{0, 0}
};
std::vector<std::vector<int>> B = {
{1, 2},
{3, 4}
};
std::vector<std::vector<int>> C(2, std::vector<int>(2, 0));
std::vector<std::vector<int>> D(2, std::vector<int>(2, 0));

// act
multiplyMatrices(A, B, C, 2, 2, 2);
multiplyMatricesWithoutErrors(A, B, D, 2, 2, 2);
std::vector<std::vector<int>> expected = {
{0, 0},
{0, 0}
};

// assert
ASSERT_EQ(D, expected) << "Matrix multiplication test failed! "
"It's the algorithm given by the professor, "
"maybe the test contains an error...";
ASSERT_EQ(C, expected) << "Matrix multiplication test failed!";
}


int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down

0 comments on commit 5502ea1

Please sign in to comment.