Line data Source code
1 : /** 2 : * @file test_SplittingProblem.cpp 3 : * 4 : * @brief Tests for the SplittingProblem class 5 : * 6 : * @author Andi Braimllari 7 : */ 8 : 9 : #include "doctest/doctest.h" 10 : 11 : #include "SplittingProblem.h" 12 : #include "L1Norm.h" 13 : #include "VolumeDescriptor.h" 14 : #include "Identity.h" 15 : 16 : using namespace elsa; 17 : using namespace doctest; 18 : 19 : TEST_SUITE_BEGIN("problems"); 20 : 21 38 : TEST_CASE_TEMPLATE("SplittingProblem: Simple Test", data_t, float, complex<float>, double, 22 : complex<double>) 23 : { 24 36 : GIVEN("some data terms, a regularization term and a constraint") 25 : { 26 36 : IndexVector_t numCoeff(2); 27 18 : numCoeff << 91, 32; 28 36 : VolumeDescriptor dd(numCoeff); 29 : 30 36 : Vector_t<data_t> scaling(dd.getNumberOfCoefficients()); 31 18 : scaling.setRandom(); 32 36 : DataContainer<data_t> dcScaling(dd, scaling); 33 36 : Scaling<data_t> scaleOp(dd, dcScaling); 34 : 35 36 : Vector_t<data_t> dataVec(dd.getNumberOfCoefficients()); 36 18 : dataVec.setRandom(); 37 36 : DataContainer<data_t> dcData(dd, dataVec); 38 : 39 36 : WLSProblem<data_t> wlsProblem(scaleOp, dcData); 40 : 41 36 : Identity<data_t> A(dd); 42 36 : Scaling<data_t> B(dd, -1); 43 36 : DataContainer<data_t> c(dd); 44 18 : c = 0; 45 36 : Constraint<data_t> constraint(A, B, c); 46 : 47 36 : WHEN("setting up a SplittingProblem") 48 : { 49 36 : L1Norm<data_t> l1NormRegFunc(dd); 50 36 : RegularizationTerm<data_t> l1NormRegTerm(1 / 2, l1NormRegFunc); 51 : 52 36 : SplittingProblem<data_t> splittingProblem(wlsProblem.getDataTerm(), l1NormRegTerm, 53 : constraint); 54 : 55 24 : THEN("cloned SplittingProblem equals original SplittingProblem") 56 : { 57 : 58 12 : auto splittingProblemClone = splittingProblem.clone(); 59 : 60 6 : REQUIRE_NE(splittingProblemClone.get(), &splittingProblem); 61 6 : REQUIRE_EQ(*splittingProblemClone, splittingProblem); 62 : } 63 : 64 24 : THEN("evaluating SplittingProblem throws an exception as it is not yet supported") 65 : { 66 12 : REQUIRE_THROWS_AS(splittingProblem.evaluate(), std::runtime_error); 67 : } 68 : 69 24 : THEN("calculating the gradient, Hessian and Lipschitz constant from SplittingProblem " 70 : "throws an exception as it is not yet supported") 71 : { 72 12 : REQUIRE_THROWS_AS(splittingProblem.getGradient(), std::runtime_error); 73 12 : REQUIRE_THROWS_AS(splittingProblem.getHessian(), std::runtime_error); 74 12 : REQUIRE_THROWS_AS(splittingProblem.getLipschitzConstant(), std::runtime_error); 75 : } 76 : } 77 : } 78 18 : } 79 : 80 : TEST_SUITE_END();