Skip to content
Snippets Groups Projects
Commit 808795a5 authored by Vickie Lynch's avatar Vickie Lynch
Browse files

Refs #7449 add test for separating background

parent d3f23111
No related branches found
No related tags found
No related merge requests found
......@@ -622,6 +622,7 @@ set ( TEST_FILES
SassenaFFTTest.h
ScaleTest.h
ScaleXTest.h
SeparateBackgroundFromSignalTest.h
ShiftLogTimeTest.h
SignalOverErrorTest.h
SmoothDataTest.h
......
......@@ -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)
{
......
#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% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment