Select Git revision
ASTNodeUnaryOperatorExpressionBuilder.cpp
-
Stéphane Del Pino authored
One now use OperatorRepository
Stéphane Del Pino authoredOne now use OperatorRepository
test_TinyMatrix.cpp 11.45 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>
#include <sstream>
// Instantiate to ensure full coverage is performed
template class TinyMatrix<1, 1, int>;
template class TinyMatrix<2, 2, int>;
template class TinyMatrix<3, 4, int>;
template class TinyMatrix<4, 4, double>;
// clazy:excludeall=non-pod-global-static
TEST_CASE("TinyMatrix", "[algebra]")
{
REQUIRE(TinyMatrix<1, 1, int>::Dimension == 1);
REQUIRE(TinyMatrix<1, 1, int>::NumberOfRows == 1);
REQUIRE(TinyMatrix<1, 1, int>::NumberOfColumns == 1);
REQUIRE(TinyMatrix<2, 3, int>::Dimension == 6);
REQUIRE(TinyMatrix<2, 3, int>::NumberOfRows == 2);
REQUIRE(TinyMatrix<2, 3, int>::NumberOfColumns == 3);
REQUIRE(TinyMatrix<5, 4, int>::Dimension == 20);
REQUIRE(TinyMatrix<5, 4, int>::NumberOfRows == 5);
REQUIRE(TinyMatrix<5, 4, int>::NumberOfColumns == 4);
TinyMatrix<3, 4, int> A(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
TinyVector<3, int> x1(1, 5, 9);
TinyVector<3, int> x2(2, 6, 10);
TinyVector<3, int> x3(3, 7, 11);
TinyVector<3, int> x4(4, 8, 12);
REQUIRE(((A(0, 0) == 1) and (A(0, 1) == 2) and (A(0, 2) == 3) and (A(0, 3) == 4) and //
(A(1, 0) == 5) and (A(1, 1) == 6) and (A(1, 2) == 7) and (A(1, 3) == 8) and //
(A(2, 0) == 9) and (A(2, 1) == 10) and (A(2, 2) == 11) and (A(2, 3) == 12)));
REQUIRE(A == TinyMatrix<3, 4, int>(x1, x2, x3, x4));
TinyMatrix<3, 4, int> B(6, 5, 3, 8, 34, 6, 35, 6, 7, 1, 3, 6);
SECTION("checking for opposed matrix")
{
const TinyMatrix minus_A = -A;
REQUIRE(
((minus_A(0, 0) == -1) and (minus_A(0, 1) == -2) and (minus_A(0, 2) == -3) and (minus_A(0, 3) == -4) and //
(minus_A(1, 0) == -5) and (minus_A(1, 1) == -6) and (minus_A(1, 2) == -7) and (minus_A(1, 3) == -8) and //
(minus_A(2, 0) == -9) and (minus_A(2, 1) == -10) and (minus_A(2, 2) == -11) and (minus_A(2, 3) == -12)));
}
SECTION("checking for equality and difference tests")
{
const TinyMatrix copy_A = A;
REQUIRE(((copy_A(0, 0) == 1) and (copy_A(0, 1) == 2) and (copy_A(0, 2) == 3) and (copy_A(0, 3) == 4) and //
(copy_A(1, 0) == 5) and (copy_A(1, 1) == 6) and (copy_A(1, 2) == 7) and (copy_A(1, 3) == 8) and //
(copy_A(2, 0) == 9) and (copy_A(2, 1) == 10) and (copy_A(2, 2) == 11) and (copy_A(2, 3) == 12)));
REQUIRE(copy_A == A);
REQUIRE_FALSE(copy_A != A);
TinyMatrix<3, 4, int> affected_A;
affected_A = A;
REQUIRE(affected_A == A);
REQUIRE_FALSE(affected_A != A);
REQUIRE(A != B);
REQUIRE_FALSE(A == B);
}