-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #7449 add test for separating background
- Loading branch information
Vickie Lynch
committed
Aug 15, 2013
1 parent
d3f2311
commit 808795a
Showing
3 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
Code/Mantid/Framework/Algorithms/test/SeparateBackgroundFromSignalTest.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ */ |