Skip to content
Snippets Groups Projects
Commit ea636e14 authored by Raquel Alvarez Banos's avatar Raquel Alvarez Banos
Browse files

Re #13952 Added two tests to test period subtraction

parent dd40f84f
No related merge requests found
......@@ -171,7 +171,7 @@ public:
AnalysisDataService::Instance().remove(outWSName);
}
void test_groupAsymmetry() {
void test_groupAsymmetry_singlePeriod() {
// Name of the output workspace.
const std::string outWSName = outputWorkspaceName("GroupAsymmetry");
......@@ -213,7 +213,56 @@ public:
AnalysisDataService::Instance().remove(outWSName);
}
void test_pairAsymmetry() {
void test_groupAsymmetry_twoPeriods_minus() {
// Name of the output workspace.
const std::string outWSName = outputWorkspaceName("GroupAsymmetry");
MatrixWorkspace_sptr inWS = createWorkspace(3);
MatrixWorkspace_sptr inWSSecond = createWorkspace();
MuonCalculateAsymmetry alg;
alg.initialize();
alg.setProperty("FirstPeriodWorkspace", inWS);
alg.setProperty("SecondPeriodWorkspace", inWSSecond);
alg.setProperty("PeriodOperation", "-");
alg.setProperty("OutputType", "GroupAsymmetry");
alg.setProperty("GroupIndex", 2);
alg.setPropertyValue("OutputWorkspace", outWSName);
TS_ASSERT_THROWS_NOTHING(alg.execute(););
TS_ASSERT(alg.isExecuted());
// Retrieve the workspace from data service.
auto ws =
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSName);
TS_ASSERT(ws);
if (ws) {
TS_ASSERT_EQUALS(ws->getNumberHistograms(), 1);
TS_ASSERT_EQUALS(ws->blocksize(), 3);
TS_ASSERT_EQUALS(ws->readX(0)[0], 1);
TS_ASSERT_EQUALS(ws->readX(0)[1], 2);
TS_ASSERT_EQUALS(ws->readX(0)[2], 3);
TS_ASSERT_DELTA(ws->readY(0)[0], 0.0030, 0.0001);
TS_ASSERT_DELTA(ws->readY(0)[1], -0.0455, 0.0001);
TS_ASSERT_DELTA(ws->readY(0)[2], -0.1511, 0.0001);
TS_ASSERT_DELTA(ws->readE(0)[0], 0.1066, 0.0001);
TS_ASSERT_DELTA(ws->readE(0)[1], 0.1885, 0.0001);
TS_ASSERT_DELTA(ws->readE(0)[2], 0.3295, 0.0001);
}
// Remove workspace from the data service.
AnalysisDataService::Instance().remove(outWSName);
}
void test_groupAsymmetry_twoPeriods_plus() {
// TODO: write test once plus operation is fixed
}
void test_pairAsymmetry_singlePeriod() {
// Name of the output workspace.
const std::string outWSName = outputWorkspaceName("GroupAsymmetry");
......@@ -257,6 +306,55 @@ public:
AnalysisDataService::Instance().remove(outWSName);
}
void test_pairAsymmetry_twoPeriods_minus() {
// Name of the output workspace.
const std::string outWSName = outputWorkspaceName("GroupAsymmetry");
MatrixWorkspace_sptr inWS = createWorkspace(3);
MatrixWorkspace_sptr inWSSecond = createWorkspace();
MuonCalculateAsymmetry alg;
alg.initialize();
alg.setProperty("FirstPeriodWorkspace", inWS);
alg.setProperty("SecondPeriodWorkspace", inWSSecond);
alg.setProperty("OutputType", "PairAsymmetry");
alg.setProperty("PairFirstIndex", 2);
alg.setProperty("PairSecondIndex", 0);
alg.setPropertyValue("OutputWorkspace", outWSName);
TS_ASSERT_THROWS_NOTHING(alg.execute());
TS_ASSERT(alg.isExecuted());
// Retrieve the workspace from data service.
auto ws =
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSName);
TS_ASSERT(ws);
if (ws) {
TS_ASSERT_EQUALS(ws->getNumberHistograms(), 1);
TS_ASSERT_EQUALS(ws->blocksize(), 3);
TS_ASSERT_DELTA(ws->readY(0)[0], 1.1785, 0.0001);
TS_ASSERT_DELTA(ws->readY(0)[1], 0.9750, 0.0001);
TS_ASSERT_DELTA(ws->readY(0)[2], 0.8333, 0.0001);
TS_ASSERT_EQUALS(ws->readX(0)[0], 1.5);
TS_ASSERT_EQUALS(ws->readX(0)[1], 2.5);
TS_ASSERT_EQUALS(ws->readX(0)[2], 3);
TS_ASSERT_DELTA(ws->readE(0)[0], 0.5290, 0.001);
TS_ASSERT_DELTA(ws->readE(0)[1], 0.4552, 0.001);
TS_ASSERT_DELTA(ws->readE(0)[2], 0.4073, 0.001);
}
// Remove workspace from the data service.
AnalysisDataService::Instance().remove(outWSName);
}
void test_pairAsymmetry_twoPeriods_plus() {
// TODO: write unit test for "+" operation once it is fixed
}
private:
std::string outputWorkspaceName(std::string testName) {
return "MuonCalculateAsymmetryTest_" + testName + "_OutputWS";
......
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