LCOV - code coverage report
Current view: top level - problems/tests - test_JacobiPreconditioner.cpp (source / functions) Hit Total Coverage
Test: test_coverage.info.cleaned Lines: 26 26 100.0 %
Date: 2022-02-28 03:37:41 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /**
       2             :  * @file test_JacobiPreconditioner.cpp
       3             :  *
       4             :  * @brief Tests for the JacobiPreconditioner class
       5             :  *
       6             :  * @author Michael Loipführer - initial code
       7             :  */
       8             : 
       9             : #include <doctest/doctest.h>
      10             : 
      11             : #include <VolumeDescriptor.h>
      12             : #include "Logger.h"
      13             : #include "JacobiPreconditioner.h"
      14             : #include "testHelpers.h"
      15             : 
      16             : using namespace elsa;
      17             : using namespace doctest;
      18             : 
      19             : TEST_SUITE_BEGIN("problems");
      20             : 
      21             : template <template <typename> typename T, typename data_t>
      22             : constexpr data_t return_data_t(const T<data_t>&);
      23             : 
      24             : TYPE_TO_STRING(JacobiPreconditioner<float>);
      25             : TYPE_TO_STRING(JacobiPreconditioner<double>);
      26             : 
      27          10 : TEST_CASE_TEMPLATE("JacobiPreconditioner: Testing standard use cases", data_t, float, double)
      28             : {
      29             :     // Set seed for Eigen Matrices!
      30           4 :     srand((unsigned int) 666);
      31             : 
      32             :     // no log spamming in tests
      33           4 :     Logger::setLevel(Logger::LogLevel::OFF);
      34             : 
      35           8 :     GIVEN("a simple linear operator")
      36             :     {
      37           8 :         IndexVector_t numCoeff(2);
      38           4 :         numCoeff << 13, 24;
      39           8 :         VolumeDescriptor dd(numCoeff);
      40             : 
      41           8 :         Eigen::Matrix<data_t, -1, 1> bVec(dd.getNumberOfCoefficients());
      42           4 :         bVec.setRandom();
      43           4 :         bVec = bVec.cwiseAbs();
      44           8 :         Scaling<data_t> scalingOp{dd, DataContainer<data_t>{dd, bVec}};
      45             : 
      46           8 :         WHEN("setting up a Jacobi Preconditioner")
      47             :         {
      48           8 :             JacobiPreconditioner<data_t> preconditioner{scalingOp, false};
      49             : 
      50           6 :             THEN("the clone works correctly")
      51             :             {
      52           4 :                 auto preconditionerClone = preconditioner.clone();
      53             : 
      54           2 :                 REQUIRE_NE(preconditionerClone.get(), &preconditioner);
      55           2 :                 REQUIRE_EQ(*preconditionerClone, preconditioner);
      56             :             }
      57             : 
      58           6 :             THEN("the preconditioner actually represents the diagonal of the operator")
      59             :             {
      60             : 
      61           4 :                 DataContainer<data_t> e(scalingOp.getDomainDescriptor());
      62           2 :                 e = 0;
      63           4 :                 DataContainer<data_t> diag(scalingOp.getDomainDescriptor());
      64         626 :                 for (index_t i = 0; i < e.getSize(); i++) {
      65         624 :                     e[i] = 1;
      66         624 :                     REQUIRE_UNARY(checkApproxEq(preconditioner.apply(e), scalingOp.apply(e)));
      67         624 :                     e[i] = 0;
      68             :                 }
      69             :             }
      70             :         }
      71             :     }
      72           4 : }
      73             : 
      74             : TEST_SUITE_END();

Generated by: LCOV version 1.15