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

          Line data    Source code
       1             : /**
       2             :  * @file test_RepresentationProblem.cpp
       3             :  *
       4             :  * @brief Tests for the RepresentationProblem class
       5             :  *
       6             :  * @author Jonas Buerger
       7             :  */
       8             : 
       9             : #include "doctest/doctest.h"
      10             : 
      11             : #include "RepresentationProblem.h"
      12             : #include "VolumeDescriptor.h"
      13             : #include "Dictionary.h"
      14             : #include "testHelpers.h"
      15             : 
      16             : using namespace elsa;
      17             : using namespace doctest;
      18             : 
      19             : TEST_SUITE_BEGIN("problems");
      20             : 
      21          14 : TEST_CASE_TEMPLATE("RepresentationProblem: Setup with a dictionary and a signal vector", data_t,
      22             :                    float, double)
      23             : {
      24          16 :     GIVEN("some dictionary operator and a signal vector")
      25             :     {
      26           8 :         const index_t nAtoms = 10;
      27          16 :         VolumeDescriptor signalDescriptor({5});
      28             : 
      29          16 :         Dictionary<data_t> dictOp(signalDescriptor, nAtoms);
      30             : 
      31          16 :         Vector_t<data_t> signalVec(signalDescriptor.getNumberOfCoefficients());
      32           8 :         signalVec.setRandom();
      33          16 :         DataContainer<data_t> dcSignal(signalDescriptor, signalVec);
      34             : 
      35          16 :         RepresentationProblem<data_t> reprProblem(dictOp, dcSignal);
      36             : 
      37          10 :         WHEN("cloning a RepresentationProblem")
      38             :         {
      39           4 :             auto reprProblemClone = reprProblem.clone();
      40           4 :             THEN("cloned RepresentationProblem equals original RepresentationProblem")
      41             :             {
      42           2 :                 REQUIRE_NE(reprProblemClone.get(), &reprProblem);
      43           2 :                 REQUIRE_EQ(*reprProblemClone, reprProblem);
      44             :             }
      45             :         }
      46             : 
      47          10 :         WHEN("evaluating the problem for a random representation")
      48             :         {
      49           4 :             VolumeDescriptor reprDescriptor({nAtoms});
      50           4 :             Vector_t<data_t> reprVec(reprDescriptor.getNumberOfCoefficients());
      51           2 :             reprVec.setRandom();
      52           4 :             DataContainer<data_t> dcRepresentation(reprDescriptor, reprVec);
      53             : 
      54           2 :             reprProblem.getCurrentSolution() = dcRepresentation;
      55           2 :             auto evaluation = reprProblem.evaluate();
      56             : 
      57           4 :             THEN("the evaluation is as expected")
      58             :             {
      59           2 :                 DataContainer<data_t> residual = (dcSignal - dictOp.apply(dcRepresentation));
      60           2 :                 data_t expected = as<data_t>(0.5) * residual.squaredL2Norm();
      61             : 
      62           2 :                 REQUIRE_UNARY(checkApproxEq(evaluation, expected));
      63             :             }
      64             :         }
      65             : 
      66          10 :         WHEN("getting the dictionary back")
      67             :         {
      68           2 :             const auto& reprProblemDict = reprProblem.getDictionary();
      69             : 
      70           4 :             THEN("it equals the original dictionary") { REQUIRE_EQ(reprProblemDict, dictOp); }
      71             :         }
      72             : 
      73          10 :         WHEN("getting the signal back")
      74             :         {
      75           4 :             auto reprProblemSignal = reprProblem.getSignal();
      76             : 
      77           4 :             THEN("it equals the original signal") { REQUIRE_EQ(reprProblemSignal, dcSignal); }
      78             :         }
      79             :     }
      80           8 : }
      81             : 
      82             : TEST_SUITE_END();

Generated by: LCOV version 1.15