Line data Source code
1 : /** 2 : * @file test_OrthogonalMatchingPursuit.cpp 3 : * 4 : * @brief Tests for the OrthogonalMatchingPursuit class 5 : * 6 : * @author Jonas Buerger 7 : */ 8 : 9 : #include "doctest/doctest.h" 10 : 11 : #include <limits> 12 : #include "Error.h" 13 : #include "OrthogonalMatchingPursuit.h" 14 : #include "Dictionary.h" 15 : #include "Logger.h" 16 : #include "VolumeDescriptor.h" 17 : #include "RepresentationProblem.h" 18 : #include "testHelpers.h" 19 : 20 : using namespace elsa; 21 : using namespace doctest; 22 : 23 : TEST_SUITE_BEGIN("solvers"); 24 : 25 : TEST_CASE("OrthogonalMatchingPursuit: Solving a RepresentationProblem") 26 2 : { 27 : // eliminate the timing info from console for the tests 28 2 : Logger::setLevel(Logger::LogLevel::OFF); 29 : 30 2 : GIVEN("a RepresentationProblem") 31 2 : { 32 2 : VolumeDescriptor dd({2}); 33 2 : const index_t nAtoms = 3; 34 2 : IdenticalBlocksDescriptor ibd(nAtoms, dd); 35 : 36 2 : RealVector_t dictVec(ibd.getNumberOfCoefficients()); 37 2 : dictVec << 0, 1, 1, 0, 1, -1; 38 2 : DataContainer dcDict(ibd, dictVec); 39 : 40 2 : Dictionary dictOp(dcDict); 41 : 42 2 : RealVector_t signalVec(dd.getNumberOfCoefficients()); 43 2 : signalVec << 5, 3; 44 2 : DataContainer dcSignal(dd, signalVec); 45 : 46 2 : RepresentationProblem reprProb(dictOp, dcSignal); 47 : 48 2 : WHEN("setting up a OrthogonalMatchingPursuit solver") 49 2 : { 50 2 : OrthogonalMatchingPursuit solver(reprProb, std::numeric_limits<real_t>::epsilon()); 51 : 52 2 : THEN("cloned OrthogonalMatchingPursuit solver equals original " 53 2 : "OrthogonalMatchingPursuit solver") 54 2 : { 55 1 : auto ompClone = solver.clone(); 56 : 57 1 : REQUIRE_NE(ompClone.get(), &solver); 58 1 : REQUIRE_EQ(*ompClone, solver); 59 1 : } 60 : 61 2 : THEN("the solution is correct") 62 2 : { 63 1 : auto solution = solver.solve(2); 64 : 65 1 : RealVector_t expected(nAtoms); 66 1 : expected << 3, 5, 0; 67 : 68 1 : REQUIRE_UNARY(isApprox(solution, expected)); 69 1 : } 70 2 : } 71 2 : } 72 2 : } 73 : 74 : TEST_SUITE_END();