[FEAT] Matrix Add invertible method

This commit is contained in:
NADAL Jean-Baptiste
2024-02-05 10:05:31 +01:00
parent ef0bb1a6e2
commit 8461c3da6b
3 changed files with 57 additions and 4 deletions

View File

@@ -332,9 +332,10 @@ TEST_CASE("[Matrix] Calculating the determinant of a 3x3 matrix", "[Matrix]")
TEST_CASE("[Matrix] Calculating the determinant of a 4x4 matrix", "[Matrix]")
{
Matrix a = {
{-2, -8, 3, 5},
{-3, 1, 7, 3},
{-6, 7, 7, -9}
{-2, -8, 3, 5},
{-3, 1, 7, 3},
{ 1, 2, -9, 6},
{-6, 7, 7, -9}
};
REQUIRE(a.cofactor(0, 0) == 690);
@@ -343,3 +344,33 @@ TEST_CASE("[Matrix] Calculating the determinant of a 4x4 matrix", "[Matrix]")
REQUIRE(a.cofactor(0, 3) == 51);
REQUIRE(a.determinant() == -4071);
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[Matrix] Testing an invertible matrix for invertibility", "[Matrix]")
{
Matrix a = {
{6, 4, 4, 4},
{5, 5, 7, 6},
{4, -9, 3, -7},
{9, 1, 7, -6}
};
REQUIRE(a.determinant() == -2120);
REQUIRE(a.invertible() == true);
}
/* ------------------------------------------------------------------------- */
TEST_CASE("[Matrix] Testing an noninvertible matrix for invertibility", "[Matrix]")
{
Matrix a = {
{-4, 2, -2, -3},
{ 9, 6, 2, 6},
{ 0, -5, 1, -5},
{ 0, 0, 0, 0}
};
REQUIRE(a.determinant() == 0);
REQUIRE(a.invertible() == false);
}