Skip to content
Snippets Groups Projects
Commit 7fdfe720 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Added sections to TinyMatrix tests

parent d6938642
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,12 @@ TEST_CASE("TinyMatrix", "[algebra]") {
REQUIRE(((A(0,0)==1) and (A(0,1)==2) and (A(0,2)==3) and
(A(1,0)==4) and (A(1,1)==5) and (A(1,2)==6) and
(A(2,0)==7) and (A(2,1)==8) and (A(2,2)==9)));
{
TinyMatrix<3,int> B(6,5,3,
8,34,6,
35,6,7);
SECTION("checking for equality and difference tests") {
const TinyMatrix<3, int> copy_A = A;
REQUIRE(((copy_A(0,0)==1) and (copy_A(0,1)==2) and (copy_A(0,2)==3) and
(copy_A(1,0)==4) and (copy_A(1,1)==5) and (copy_A(1,2)==6) and
......@@ -21,9 +26,12 @@ TEST_CASE("TinyMatrix", "[algebra]") {
TinyMatrix<3, int> affected_A; affected_A = A;
REQUIRE(affected_A==A);
REQUIRE_FALSE(affected_A!=A);
REQUIRE(A!=B);
REQUIRE_FALSE(A==B);
}
{
SECTION("checking for scalar left product") {
const int a = 2;
const TinyMatrix<3, int> aA = a*A;
......@@ -31,80 +39,91 @@ TEST_CASE("TinyMatrix", "[algebra]") {
8, 10, 12,
14, 16, 18));
}
SECTION("checking for null matrix management") {
TinyMatrix<3, int> Z = zero;
REQUIRE(Z == TinyMatrix<3, int>(0,0,0,
0,0,0,
0,0,0));
{
TinyMatrix<3, int> affected_Z; affected_Z = zero;
REQUIRE(affected_Z == Z);
}
SECTION("checking for identity management") {
TinyMatrix<3, int> I = identity;
REQUIRE(I == TinyMatrix<3,int>(1,0,0,
0,1,0,
0,0,1));
{
TinyMatrix<3, int> affected_I; affected_I=identity;
REQUIRE(affected_I==I);
}
TinyMatrix<3,int> B(6,5,3,
8,34,6,
35,6,7);
REQUIRE(A!=B);
REQUIRE_FALSE(A==B);
SECTION("checking for matrices sum") {
REQUIRE(A+B == TinyMatrix<3,int>(7,7,6,
12,39,12,
42,14,16));
{
TinyMatrix<3, int> ApB = A;
ApB += B;
REQUIRE(ApB==A+B);
}
SECTION("checking for matrices difference ") {
REQUIRE(A-B == TinyMatrix<3,int>(-5, -3, 0,
-4, -29, 0,
-28, 2, 2));
{
TinyMatrix<3, int> AmB = A;
AmB -= B;
REQUIRE(AmB==A-B);
}
SECTION("checking for matrices product") {
REQUIRE(A*B == TinyMatrix<3,int>(127,91,36,
274,226,84,
421,361,132));
}
SECTION("checking for matrix-vector product") {
REQUIRE(A*TinyVector<3,int>(2,-3,5) == TinyVector<3,int>(11,23,35));
}
TinyVector<3,int> u(1,3,7);
TinyVector<3,int> v(6,2,-3);
SECTION("checking for tensor product") {
const TinyVector<3,int> u(1,3,7);
const TinyVector<3,int> v(6,2,-3);
REQUIRE(tensorProduct(u,v)==TinyMatrix<3,int>(6,2,-3,
18,6,-9,
42,14,-21));
}
SECTION("checking for determinant calculations") {
REQUIRE(det(TinyMatrix<1,int>(6))==6);
REQUIRE(det(TinyMatrix<2,int>(3,1,
-3,6))==21);
REQUIRE(det(B)==-1444);
REQUIRE(det(TinyMatrix<4,double> (1,2.3,7,-6.2,
3,4,9,1,
4.1,5,2,-3,
2,27,3,17.5))== Approx(6661.455).epsilon(1E-14));
}
SECTION("checking for matrices output") {
REQUIRE(Catch::Detail::stringify(A) == "[(1,2,3)(4,5,6)(7,8,9)]");
REQUIRE(Catch::Detail::stringify(TinyMatrix<1,int>(7)) == "7");
}
#ifndef NDEBUG
SECTION("checking for bounds vioation") {
REQUIRE_THROWS_AS(A(3,0), AssertError);
REQUIRE_THROWS_AS(A(0,3), AssertError);
const TinyMatrix<3,int>& constA = A;
REQUIRE_THROWS_AS(constA(3,0), AssertError);
REQUIRE_THROWS_AS(constA(0,3), AssertError);
}
#endif // NDEBUG
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment