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

          Line data    Source code
       1             : #include "doctest/doctest.h"
       2             : 
       3             : #include "RegularizationTerm.h"
       4             : #include "L2NormPow2.h"
       5             : #include "VolumeDescriptor.h"
       6             : 
       7             : using namespace elsa;
       8             : using namespace doctest;
       9             : 
      10             : TEST_SUITE_BEGIN("problems");
      11             : 
      12           5 : TEST_CASE("RegularizationTerm: Test a simple term")
      13             : {
      14           6 :     GIVEN("some term")
      15             :     {
      16           2 :         IndexVector_t numCoeff(2);
      17           1 :         numCoeff << 7, 16;
      18           2 :         VolumeDescriptor dd(numCoeff);
      19             : 
      20           1 :         real_t weight = 2.5;
      21           2 :         L2NormPow2 functional(dd);
      22             : 
      23           2 :         WHEN("instantiating")
      24             :         {
      25           2 :             RegularizationTerm regTerm(weight, functional);
      26             : 
      27           2 :             THEN("everything is as expected")
      28             :             {
      29           1 :                 REQUIRE_EQ(regTerm.getWeight(), Approx(weight));
      30           1 :                 REQUIRE_EQ(regTerm.getFunctional(), functional);
      31             :             }
      32             :         }
      33             :     }
      34             : 
      35           9 :     GIVEN("another regularization term")
      36             :     {
      37           8 :         IndexVector_t numCoeff(3);
      38           4 :         numCoeff << 11, 17, 23;
      39           8 :         VolumeDescriptor dd(numCoeff);
      40             : 
      41           4 :         auto weight = real_t{3.1f};
      42           8 :         L2NormPow2 functional(dd);
      43             : 
      44           8 :         RegularizationTerm regTerm(weight, functional);
      45             : 
      46           5 :         WHEN("copy constructing")
      47             :         {
      48           2 :             RegularizationTerm rt(regTerm);
      49             : 
      50           2 :             THEN("it copied correctly")
      51             :             {
      52           1 :                 REQUIRE_EQ(rt.getWeight(), Approx(regTerm.getWeight()));
      53           1 :                 REQUIRE_EQ(rt.getFunctional(), regTerm.getFunctional());
      54             : 
      55           1 :                 REQUIRE_EQ(rt, regTerm);
      56             :             }
      57             :         }
      58             : 
      59           5 :         WHEN("copy assigning")
      60             :         {
      61           2 :             RegularizationTerm rt(0.0f, functional);
      62           1 :             rt = regTerm;
      63             : 
      64           2 :             THEN("it copied correctly")
      65             :             {
      66           1 :                 REQUIRE_EQ(rt.getWeight(), Approx(regTerm.getWeight()));
      67           1 :                 REQUIRE_EQ(rt.getFunctional(), regTerm.getFunctional());
      68             : 
      69           1 :                 REQUIRE_EQ(rt, regTerm);
      70             :             }
      71             :         }
      72             : 
      73           5 :         WHEN("move constructing")
      74             :         {
      75           2 :             RegularizationTerm oldOtherRt(regTerm);
      76             : 
      77           2 :             RegularizationTerm rt(std::move(regTerm));
      78             : 
      79           2 :             THEN("it moved correctly")
      80             :             {
      81           1 :                 REQUIRE_EQ(rt.getWeight(), Approx(oldOtherRt.getWeight()));
      82           1 :                 REQUIRE_EQ(rt.getFunctional(), oldOtherRt.getFunctional());
      83             : 
      84           1 :                 REQUIRE_EQ(rt, oldOtherRt);
      85             :             }
      86             :         }
      87             : 
      88           5 :         WHEN("move assigning")
      89             :         {
      90           2 :             RegularizationTerm oldOtherRt(regTerm);
      91             : 
      92           2 :             RegularizationTerm rt(0.0f, functional);
      93           1 :             rt = std::move(regTerm);
      94             : 
      95           2 :             THEN("it moved correctly")
      96             :             {
      97           1 :                 REQUIRE_EQ(rt.getWeight(), Approx(oldOtherRt.getWeight()));
      98           1 :                 REQUIRE_EQ(rt.getFunctional(), oldOtherRt.getFunctional());
      99             : 
     100           1 :                 REQUIRE_EQ(rt, oldOtherRt);
     101             :             }
     102             :         }
     103             :     }
     104           5 : }
     105             : 
     106             : TEST_SUITE_END();

Generated by: LCOV version 1.15