Select Git revision
userdoc.org
-
Stéphane Del Pino authoredStéphane Del Pino authored
test_TinyMatrix.cpp 7.60 KiB
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_all.hpp>
#include <Kokkos_Core.hpp>
#include <utils/PugsAssert.hpp>
#include <utils/Types.hpp>
#include <algebra/TinyMatrix.hpp>
// Instantiate to ensure full coverage is performed
template class TinyMatrix<1, int>;
template class TinyMatrix<2, int>;
template class TinyMatrix<3, int>;
template class TinyMatrix<4, double>;
// clazy:excludeall=non-pod-global-static
TEST_CASE("TinyMatrix", "[algebra]")
{
TinyMatrix<3, int> A(1, 2, 3, 4, 5, 6, 7, 8, 9);
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 opposed matrix")
{
const TinyMatrix<3, int> minus_A = -A;
REQUIRE(((minus_A(0, 0) == -1) and (minus_A(0, 1) == -2) and (minus_A(0, 2) == -3) and (minus_A(1, 0) == -4) and
(minus_A(1, 1) == -5) and (minus_A(1, 2) == -6) and (minus_A(2, 0) == -7) and (minus_A(2, 1) == -8) and
(minus_A(2, 2) == -9)));
}
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 (copy_A(2, 0) == 7) and (copy_A(2, 1) == 8) and
(copy_A(2, 2) == 9)));
REQUIRE(copy_A == A);
REQUIRE_FALSE(copy_A != A);
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;
REQUIRE(aA == TinyMatrix<3, int>(2, 4, 6, 8, 10, 12, 14, 16, 18));
}
SECTION("checking for scalar seft product")
{
const int a = 2;
TinyMatrix<3, int> copy_A = A;
REQUIRE((copy_A *= a) == TinyMatrix<3, int>(2, 4, 6, 8, 10, 12, 14, 16, 18));
}
SECTION("checking for null matrix management")
{
TinyMatrix<3, int> Z = zero;