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 : TEST_CASE("RegularizationTerm: Test a simple term") 13 5 : { 14 5 : GIVEN("some term") 15 5 : { 16 1 : IndexVector_t numCoeff(2); 17 1 : numCoeff << 7, 16; 18 1 : VolumeDescriptor dd(numCoeff); 19 : 20 1 : real_t weight = 2.5; 21 1 : L2NormPow2 functional(dd); 22 : 23 1 : WHEN("instantiating") 24 1 : { 25 1 : RegularizationTerm regTerm(weight, functional); 26 : 27 1 : THEN("everything is as expected") 28 1 : { 29 1 : REQUIRE_EQ(regTerm.getWeight(), Approx(weight)); 30 1 : REQUIRE_EQ(regTerm.getFunctional(), functional); 31 1 : } 32 1 : } 33 1 : } 34 : 35 5 : GIVEN("another regularization term") 36 5 : { 37 4 : IndexVector_t numCoeff(3); 38 4 : numCoeff << 11, 17, 23; 39 4 : VolumeDescriptor dd(numCoeff); 40 : 41 4 : auto weight = real_t{3.1f}; 42 4 : L2NormPow2 functional(dd); 43 : 44 4 : RegularizationTerm regTerm(weight, functional); 45 : 46 4 : WHEN("copy constructing") 47 4 : { 48 1 : RegularizationTerm rt(regTerm); 49 : 50 1 : THEN("it copied correctly") 51 1 : { 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 1 : } 57 1 : } 58 : 59 4 : WHEN("copy assigning") 60 4 : { 61 1 : RegularizationTerm rt(0.0f, functional); 62 1 : rt = regTerm; 63 : 64 1 : THEN("it copied correctly") 65 1 : { 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 1 : } 71 1 : } 72 : 73 4 : WHEN("move constructing") 74 4 : { 75 1 : RegularizationTerm oldOtherRt(regTerm); 76 : 77 1 : RegularizationTerm rt(std::move(regTerm)); 78 : 79 1 : THEN("it moved correctly") 80 1 : { 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 1 : } 86 1 : } 87 : 88 4 : WHEN("move assigning") 89 4 : { 90 1 : RegularizationTerm oldOtherRt(regTerm); 91 : 92 1 : RegularizationTerm rt(0.0f, functional); 93 1 : rt = std::move(regTerm); 94 : 95 1 : THEN("it moved correctly") 96 1 : { 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 1 : } 102 1 : } 103 4 : } 104 5 : } 105 : 106 : TEST_SUITE_END();