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 2 : TEST_CASE("OrthogonalMatchingPursuit: Solving a RepresentationProblem") 26 : { 27 : // eliminate the timing info from console for the tests 28 2 : Logger::setLevel(Logger::LogLevel::OFF); 29 : 30 4 : GIVEN("a RepresentationProblem") 31 : { 32 4 : VolumeDescriptor dd({2}); 33 2 : const index_t nAtoms = 3; 34 4 : IdenticalBlocksDescriptor ibd(nAtoms, dd); 35 : 36 4 : RealVector_t dictVec(ibd.getNumberOfCoefficients()); 37 2 : dictVec << 0, 1, 1, 0, 1, -1; 38 4 : DataContainer dcDict(ibd, dictVec); 39 : 40 4 : Dictionary dictOp(dcDict); 41 : 42 4 : RealVector_t signalVec(dd.getNumberOfCoefficients()); 43 2 : signalVec << 5, 3; 44 4 : DataContainer dcSignal(dd, signalVec); 45 : 46 4 : RepresentationProblem reprProb(dictOp, dcSignal); 47 : 48 4 : WHEN("setting up a OrthogonalMatchingPursuit solver") 49 : { 50 4 : OrthogonalMatchingPursuit solver(reprProb, std::numeric_limits<real_t>::epsilon()); 51 : 52 3 : THEN("cloned OrthogonalMatchingPursuit solver equals original " 53 : "OrthogonalMatchingPursuit solver") 54 : { 55 2 : auto ompClone = solver.clone(); 56 : 57 1 : REQUIRE_NE(ompClone.get(), &solver); 58 1 : REQUIRE_EQ(*ompClone, solver); 59 : } 60 : 61 3 : THEN("the solution is correct") 62 : { 63 2 : 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 : } 70 : } 71 : } 72 2 : } 73 : 74 : TEST_SUITE_END();