From 411b1191b30c7d432007fc08bbda469f2957108c Mon Sep 17 00:00:00 2001 From: NADAL Jean-Baptiste Date: Fri, 2 Feb 2024 18:29:08 +0100 Subject: [PATCH] [WIP] add tests for 3x3 and 4x4 --- tests/03_matrix.cpp | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/tests/03_matrix.cpp b/tests/03_matrix.cpp index 1e3c32e..60096f1 100644 --- a/tests/03_matrix.cpp +++ b/tests/03_matrix.cpp @@ -305,8 +305,41 @@ TEST_CASE("[Matrix] Calculating a cofactor of a 3x3 matrix", "[Matrix]") {6, -1, 5} }; - REQUIRE(a.minor(0, 0) == -12.0); - REQUIRE(a.cofactor(0, 0) == -12.0); - REQUIRE(a.minor(1, 0) == 25.0); - REQUIRE(a.cofactor(1, 0) == -25.0); + REQUIRE(a.minor(0, 0) == -12); + REQUIRE(a.cofactor(0, 0) == -12); + REQUIRE(a.minor(1, 0) == 25); + REQUIRE(a.cofactor(1, 0) == -25); +} + +/* ------------------------------------------------------------------------- */ + +TEST_CASE("[Matrix] Calculating the determinant of a 3x3 matrix", "[Matrix]") +{ + Matrix a = { + { 1, 2, 6}, + {-5, 8, -4}, + { 2, 6, 4} + }; + + REQUIRE(a.cofactor(0, 0) == 56); + REQUIRE(a.cofactor(0, 1) == 12); + REQUIRE(a.cofactor(0, 2) == -46); + REQUIRE(a.determinant() == -196); +} + +/* ------------------------------------------------------------------------- */ + +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} + }; + + REQUIRE(a.cofactor(0, 0) == 690); + REQUIRE(a.cofactor(0, 1) == 447); + REQUIRE(a.cofactor(0, 2) == 210); + REQUIRE(a.cofactor(0, 3) == 51); + REQUIRE(a.determinant() == -4071); }