diff --git a/Code/Mantid/Algorithms/test/AddSampleLogTest.h b/Code/Mantid/Algorithms/test/AddSampleLogTest.h index 2e63ab25d57b88a6015094f3099fdd2d88cf3380..713e6990df04f38188361a3c418b2d50c6470465 100644 --- a/Code/Mantid/Algorithms/test/AddSampleLogTest.h +++ b/Code/Mantid/Algorithms/test/AddSampleLogTest.h @@ -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; - } + + }; diff --git a/Code/Mantid/Algorithms/test/ChainedOperatorTest.h b/Code/Mantid/Algorithms/test/ChainedOperatorTest.h index b538e9a7107b0cbd15fdc87825cef35cba6b07fd..df12606d721ef17637f550360107a2732f3d6902 100644 --- a/Code/Mantid/Algorithms/test/ChainedOperatorTest.h +++ b/Code/Mantid/Algorithms/test/ChainedOperatorTest.h @@ -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. } diff --git a/Code/Mantid/Algorithms/test/WorkspaceCreationHelper.hh b/Code/Mantid/Algorithms/test/WorkspaceCreationHelper.hh index c3ff0f5a5f2f8ddcd5f2eeac46373a659e7e0fb9..c133662f55a0c32071e0d3d47fa86cf4c4cb693a 100644 --- a/Code/Mantid/Algorithms/test/WorkspaceCreationHelper.hh +++ b/Code/Mantid/Algorithms/test/WorkspaceCreationHelper.hh @@ -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_*/