Skip to content

Commit

Permalink
Re #11868 Update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
raquelalvarezbanos committed Oct 2, 2015
1 parent 1b26541 commit b7f8c42
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions Code/Mantid/Framework/Algorithms/test/CalMuonDetectorPhasesTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/ITableWorkspace.h"
#include <boost/assign/list_of.hpp>

using namespace Mantid::API;
Expand Down Expand Up @@ -34,46 +35,64 @@ class CalMuonDetectorPhasesTest : public CxxTest::TestSuite

void testExecute()
{
auto ws = createWorkspace("Microseconds");
auto ws = createWorkspace(4, 100, "Microseconds");
auto calc = AlgorithmManager::Instance().create("CalMuonDetectorPhases");
calc->initialize();
calc->setChild(true);
calc->setProperty("InputWorkspace", ws);
calc->setProperty("Frequency", 25.);
calc->setPropertyValue("Frequency", "25");
calc->setPropertyValue("DataFitted", "fit");
calc->setPropertyValue("DetectorTable", "tab");

TS_ASSERT_THROWS_NOTHING(calc->execute());

WorkspaceGroup_sptr fitResults = calc->getProperty("DataFitted");
ITableWorkspace_sptr detTab = calc->getProperty("DetectorTable");
ITableWorkspace_sptr tab = calc->getProperty("DetectorTable");

// Check the table workspace
TS_ASSERT_EQUALS(tab->rowCount(), 4);
TS_ASSERT_EQUALS(tab->columnCount(), 3);
// Test asymmetries
TS_ASSERT_DELTA(tab->Double(0,1), 0.099, 0.001);
TS_ASSERT_DELTA(tab->Double(1,1), 0.099, 0.001);
TS_ASSERT_DELTA(tab->Double(2,1), 0.099, 0.001);
TS_ASSERT_DELTA(tab->Double(3,1), 0.100, 0.001);
// Test phases
TS_ASSERT_DELTA(tab->Double(0,2), 6.281, 0.001);
TS_ASSERT_DELTA(tab->Double(1,2), 0.785, 0.001);
TS_ASSERT_DELTA(tab->Double(2,2), 1.570, 0.001);
TS_ASSERT_DELTA(tab->Double(3,2), 2.354, 0.001);

}

MatrixWorkspace_sptr createWorkspace(std::string units) {
MatrixWorkspace_sptr createWorkspace(size_t nspec, size_t maxt, std::string units) {

// Create a fake muon dataset
double a = 0.1; // Amplitude of the oscillations
double w = 25.; // Frequency of the oscillations
double tau = 2.2; // Muon life time
size_t maxt = 100; // Maximum time

MantidVec X(maxt);
MantidVec Y(maxt);
for (size_t s = 0; s < 4; s++) {
MantidVec X;
MantidVec Y;
MantidVec E;
for (size_t s = 0; s < nspec; s++) {
for (size_t t = 0; t < maxt; t++) {
double x = static_cast<double>(t) / maxt;
double e = exp(-x / tau);
X.push_back(x);
Y.push_back(a * sin(w * t + s * M_PI / 4.) * e + e);
Y.push_back(a * sin(w * x + s * M_PI / nspec) * e + e);
E.push_back(0.005);
}
}

auto createWS = AlgorithmManager::Instance().create("CreateWorkspace");
createWS->initialize();
createWS->setChild(true);
createWS->setProperty("UnitX", units);
createWS->setProperty("DataX", X);
createWS->setProperty("DataY", Y);
createWS->setProperty("NSpec", 4);
createWS->setProperty("DataE", E);
createWS->setProperty("NSpec", static_cast<int>(nspec));
createWS->setPropertyValue("OutputWorkspace", "ws");
createWS->execute();
MatrixWorkspace_sptr ws = createWS->getProperty("OutputWorkspace");
Expand Down

0 comments on commit b7f8c42

Please sign in to comment.