Skip to content

Commit 2e7d868

Browse files
authored
[Type] Add determinant tests for 2x2 and 3x3 matrices (#5796)
[Type] Add determinant tests
1 parent c70d43e commit 2e7d868

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Sofa/framework/Type/test/MatTypes_test.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,21 @@ TEST(MatTypesTest, assignFromPtr)
418418
EXPECT_TRUE(comp);
419419
}
420420

421+
TEST(MatTypesTest, determinant2x2)
422+
{
423+
EXPECT_DOUBLE_EQ(sofa::type::determinant(Matrix2::Identity()), 1_sreal);
424+
EXPECT_DOUBLE_EQ(sofa::type::determinant(sofa::type::Mat<2,2,SReal>{{1, 2}, {3, 4}}), -2_sreal);
425+
EXPECT_DOUBLE_EQ(sofa::type::determinant(sofa::type::Mat<2,2,SReal>{{2, 0}, {0, 2}}), 4_sreal);
426+
EXPECT_DOUBLE_EQ(sofa::type::determinant(sofa::type::Mat<2,2,SReal>{{0, 1}, {1, 0}}), -1_sreal);
427+
EXPECT_DOUBLE_EQ(sofa::type::determinant(sofa::type::Mat<2,2,SReal>{{-1, 2}, {3, 4}}), -10_sreal);
428+
}
429+
430+
TEST(MatTypesTest, determinant3x3)
431+
{
432+
EXPECT_DOUBLE_EQ(sofa::type::determinant(Matrix3::Identity()), 1_sreal);
433+
EXPECT_DOUBLE_EQ(sofa::type::determinant(sofa::type::Mat<3,3,SReal>{{2, 0, 0}, {0, 3, 0}, {0, 0, 4}}), 24_sreal);
434+
EXPECT_DOUBLE_EQ(sofa::type::determinant(sofa::type::Mat<3,3,SReal>{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}), 0_sreal);
435+
EXPECT_DOUBLE_EQ(sofa::type::determinant(sofa::type::Mat<3,3,SReal>{{0, 1, 0}, {0, 0, 1}, {1, 0, 0}}), 1_sreal);
436+
EXPECT_DOUBLE_EQ(sofa::type::determinant(sofa::type::Mat<3,3,SReal>{{1, 1, 0}, {1, 0, 1}, {0, 1, 1}}), -2_sreal);
437+
}
438+

0 commit comments

Comments
 (0)