Skip to content

Commit

Permalink
Refs #7449 add test for separating background
Browse files Browse the repository at this point in the history
  • Loading branch information
Vickie Lynch committed Aug 15, 2013
1 parent d3f2311 commit 808795a
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/Framework/Algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ set ( TEST_FILES
SassenaFFTTest.h
ScaleTest.h
ScaleXTest.h
SeparateBackgroundFromSignalTest.h
ShiftLogTimeTest.h
SignalOverErrorTest.h
SmoothDataTest.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ namespace Algorithms
cont_stop.push_back(l-1);
}
}
if(cont_start.size() > cont_stop.size()) cont_stop.push_back(n-1);
vector<size_t> cont_len;
for (size_t l = 0; l < cont_start.size(); ++l)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#ifndef MANTID_ALGORITHMS_SeparateBackgroundFromSignal_H_
#define MANTID_ALGORITHMS_SeparateBackgroundFromSignalTEST_H_

#include <cxxtest/TestSuite.h>

#include "MantidAlgorithms/SeparateBackgroundFromSignal.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidDataObjects/Workspace2D.h"

#include <cmath>

using namespace Mantid;
using namespace Mantid::API;
using namespace Mantid::Kernel;
using namespace Mantid::DataObjects;

using namespace std;

using Mantid::Algorithms::SeparateBackgroundFromSignal;

class SeparateBackgroundFromSignalTest : public CxxTest::TestSuite
{
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static SeparateBackgroundFromSignalTest *createSuite() { return new SeparateBackgroundFromSignalTest(); }
static void destroySuite( SeparateBackgroundFromSignalTest *suite ) { delete suite; }


void test_Calculation()
{

// 1. Generate input workspace
MatrixWorkspace_sptr inWS = generateTestWorkspace();

// 2. Create
Algorithms::SeparateBackgroundFromSignal alg;

alg.initialize();
TS_ASSERT(alg.isInitialized());

alg.setProperty("InputWorkspace", inWS);
alg.setProperty("OutputWorkspace", "Signal");
alg.setProperty("WorkspaceIndex", 0);

alg.execute();
TS_ASSERT(alg.isExecuted());

Workspace2D_sptr outWS = boost::dynamic_pointer_cast<Workspace2D>
(AnalysisDataService::Instance().retrieve("Signal"));

const MantidVec& Signal = outWS->readY(0);
TS_ASSERT_DELTA(Signal[2], 0.0000, 0.0001);
TS_ASSERT_DELTA(Signal[10], 28.000, 0.0001);

const MantidVec& vecX = outWS->readX(0);
TS_ASSERT_DELTA(vecX[0], 0.0, 0.000001);
TS_ASSERT_DELTA(vecX[5], 5.0, 0.000001);
TS_ASSERT_DELTA(vecX[10], 10.0, 0.000001);

return;
}


/** Generate a workspace for test
*/
MatrixWorkspace_sptr generateTestWorkspace()
{
vector<double> data;
data.push_back(1);
data.push_back(2);
data.push_back(1);
data.push_back(1);
data.push_back(9);
data.push_back(11);
data.push_back(13);
data.push_back(20);
data.push_back(24);
data.push_back(32);
data.push_back(28);
data.push_back(48);
data.push_back(42);
data.push_back(77);
data.push_back(67);
data.push_back(33);
data.push_back(27);
data.push_back(20);
data.push_back(9);
data.push_back(2);

MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>
(WorkspaceFactory::Instance().create("Workspace2D", 1, data.size(), data.size()));

MantidVec& vecX = ws->dataX(0);
MantidVec& vecY = ws->dataY(0);
MantidVec& vecE = ws->dataE(0);

for (size_t i = 0; i < data.size(); ++i)
{
vecX[i] = static_cast<double>(i);
vecY[i] = data[i];
vecE[i] = sqrt(data[i]);
}

return ws;
}


};


#endif /* MANTID_ALGORITHMS_SeparateBackgroundFromSignalTEST_H_ */

0 comments on commit 808795a

Please sign in to comment.