Skip to content
Snippets Groups Projects
Commit 018ce438 authored by Nick Draper's avatar Nick Draper
Browse files

re #1367

Added eventworkspaces to AddSampleLogTest and ChainedOperatorTest
parent 3bb34980
No related branches found
No related tags found
No related merge requests found
......@@ -5,26 +5,38 @@
#include <string>
#include "MantidDataObjects/Workspace2D.h"
#include "WorkspaceCreationHelper.hh"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAlgorithms/AddSampleLog.h"
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
using namespace Mantid::Algorithms;
class AddSampleLogTest : public CxxTest::TestSuite
{
public:
void testInsertion()
void testInsertion2D()
{
ExecuteAlgorithm(WorkspaceCreationHelper::Create2DWorkspace(10,10));
}
void testInsertionEvent()
{
ExecuteAlgorithm(WorkspaceCreationHelper::CreateEventWorkspace(10,10));
}
void ExecuteAlgorithm(MatrixWorkspace_sptr testWS)
{
//add the workspace to the ADS
AnalysisDataService::Instance().add("AddSampleLogTest_Temporary", testWS);
//execute algorithm
AddSampleLog alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize());
TS_ASSERT( alg.isInitialized() )
Workspace2D_sptr testWS = makeDummyWorkspace2D();
alg.setPropertyValue("Workspace", "AddSampleLogTest_Temporary");
alg.setPropertyValue("LogName", "my name");
alg.setPropertyValue("LogText", "my data");
......@@ -32,6 +44,7 @@ public:
TS_ASSERT_THROWS_NOTHING(alg.execute())
TS_ASSERT( alg.isExecuted() )
//check output
MatrixWorkspace_sptr output = boost::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieve(alg.getProperty("Workspace")));
Sample wSpaceSam = output->sample();
......@@ -40,15 +53,13 @@ public:
TS_ASSERT(testProp)
TS_ASSERT_EQUALS(testProp->value(), "my data")
//cleanup
AnalysisDataService::Instance().remove(output->getName());
}
Workspace2D_sptr makeDummyWorkspace2D()
{
Workspace2D_sptr testWorkspace(new Workspace2D);
AnalysisDataService::Instance().add("AddSampleLogTest_Temporary", testWorkspace);
return testWorkspace;
}
};
......
......@@ -38,7 +38,7 @@ public:
MatrixWorkspace_sptr in_work1 = getProperty("InputWorkspace_1");
MatrixWorkspace_sptr in_work2 = getProperty("InputWorkspace_2");
MatrixWorkspace_sptr out_work = (in_work1 + in_work2)/(in_work1 - in_work2)+3;
MatrixWorkspace_sptr out_work = (in_work1 + in_work2)/3+5;
setProperty("OutputWorkspace",out_work);
}
virtual const std::string name() const {return "ComplexOpTest";}
......@@ -57,6 +57,21 @@ public:
MatrixWorkspace_sptr work_in1 = WorkspaceCreationHelper::Create2DWorkspace123(sizex,sizey);
MatrixWorkspace_sptr work_in2 = WorkspaceCreationHelper::Create2DWorkspace154(sizex,sizey);
performTest(work_in1, work_in2);
}
void testChainedOperatorEventWS()
{
int sizex = 10,sizey=20;
// Register the workspace in the data service
MatrixWorkspace_sptr work_in1 = WorkspaceCreationHelper::CreateEventWorkspace(sizex,sizey);
MatrixWorkspace_sptr work_in2 = WorkspaceCreationHelper::CreateEventWorkspace(sizex,sizey);
performTest(work_in1, work_in2);
}
void performTest(MatrixWorkspace_sptr work_in1, MatrixWorkspace_sptr work_in2)
{
ComplexOpTest alg;
std::string wsNameIn1 = "testChainedOperator_in21";
......@@ -82,7 +97,7 @@ public:
private:
void checkData( MatrixWorkspace_sptr work_in1, MatrixWorkspace_sptr work_in2, MatrixWorkspace_sptr work_out1)
void checkData(const MatrixWorkspace_sptr work_in1,const MatrixWorkspace_sptr work_in2, const MatrixWorkspace_sptr work_out1)
{
int ws2LoopCount;
if (work_in2->size() > 0)
......@@ -97,12 +112,12 @@ private:
}
}
void checkDataItem (MatrixWorkspace_sptr work_in1, MatrixWorkspace_sptr work_in2, MatrixWorkspace_sptr work_out1, int i, int ws2Index)
void checkDataItem (const MatrixWorkspace_sptr work_in1, const MatrixWorkspace_sptr work_in2, const MatrixWorkspace_sptr work_out1, int i, int ws2Index)
{
double sig1 = work_in1->dataY(i/work_in1->blocksize())[i%work_in1->blocksize()];
double sig2 = work_in2->dataY(ws2Index/work_in1->blocksize())[ws2Index%work_in1->blocksize()];
double sig3 = work_out1->dataY(i/work_in1->blocksize())[i%work_in1->blocksize()];
TS_ASSERT_DELTA((sig1 + sig2)/(sig1-sig2)+3, sig3, 0.0001);
double sig1 = work_in1->readY(i/work_in1->blocksize())[i%work_in1->blocksize()];
double sig2 = work_in2->readY(ws2Index/work_in1->blocksize())[ws2Index%work_in1->blocksize()];
double sig3 = work_out1->readY(i/work_in1->blocksize())[i%work_in1->blocksize()];
TS_ASSERT_DELTA((sig1 + sig2)/3+5, sig3, 0.0001);
//Note err calculation not checked due to complexity.
}
......
......@@ -181,6 +181,20 @@ public:
return retVal;
}
//not strictly creating a workspace, but really helpfull to see what one contains
static void DisplayData(const MatrixWorkspace_sptr ws)
{
const int numHists = ws->getNumberHistograms();
for (int i = 0; i < numHists; ++i)
{
for (int j = 0; j < ws->blocksize(); ++j)
{
std::cout <<ws->readY(i)[j];
}
std::cout<<std::endl;
}
}
};
#endif /*WORKSPACECREATIONHELPER_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