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 : TEST_CASE_TEMPLATE("SplittingProblem: Simple Test", data_t, float, complex<float>, double, 22 : complex<double>) 23 12 : { 24 12 : GIVEN("some data terms, a regularization term and a constraint") 25 12 : { 26 12 : IndexVector_t numCoeff(2); 27 12 : numCoeff << 91, 32; 28 12 : VolumeDescriptor dd(numCoeff); 29 : 30 12 : Vector_t<data_t> scaling(dd.getNumberOfCoefficients()); 31 12 : scaling.setRandom(); 32 12 : DataContainer<data_t> dcScaling(dd, scaling); 33 12 : Scaling<data_t> scaleOp(dd, dcScaling); 34 : 35 12 : Vector_t<data_t> dataVec(dd.getNumberOfCoefficients()); 36 12 : dataVec.setRandom(); 37 12 : DataContainer<data_t> dcData(dd, dataVec); 38 : 39 12 : WLSProblem<data_t> wlsProblem(scaleOp, dcData); 40 : 41 12 : Identity<data_t> A(dd); 42 12 : Scaling<data_t> B(dd, -1); 43 12 : DataContainer<data_t> c(dd); 44 12 : c = 0; 45 12 : Constraint<data_t> constraint(A, B, c); 46 : 47 12 : WHEN("setting up a SplittingProblem") 48 12 : { 49 12 : L1Norm<data_t> l1NormRegFunc(dd); 50 12 : RegularizationTerm<data_t> l1NormRegTerm(1 / 2, l1NormRegFunc); 51 : 52 12 : SplittingProblem<data_t> splittingProblem(wlsProblem.getDataTerm(), l1NormRegTerm, 53 12 : constraint); 54 : 55 12 : THEN("cloned SplittingProblem equals original SplittingProblem") 56 12 : { 57 : 58 4 : auto splittingProblemClone = splittingProblem.clone(); 59 : 60 4 : REQUIRE_NE(splittingProblemClone.get(), &splittingProblem); 61 4 : REQUIRE_EQ(*splittingProblemClone, splittingProblem); 62 4 : } 63 : 64 12 : THEN("evaluating SplittingProblem throws an exception as it is not yet supported") 65 12 : { 66 4 : REQUIRE_THROWS_AS(splittingProblem.evaluate(), std::runtime_error); 67 4 : } 68 : 69 12 : THEN("calculating the gradient, Hessian and Lipschitz constant from SplittingProblem " 70 12 : "throws an exception as it is not yet supported") 71 12 : { 72 4 : REQUIRE_THROWS_AS(splittingProblem.getGradient(), std::runtime_error); 73 4 : REQUIRE_THROWS_AS(splittingProblem.getHessian(), std::runtime_error); 74 4 : REQUIRE_THROWS_AS(splittingProblem.getLipschitzConstant(), std::runtime_error); 75 4 : } 76 12 : } 77 12 : } 78 12 : } 79 : 80 : TEST_SUITE_END();