From 5ca90c761fdafae3151f382afc15faa6690b9117 Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Tue, 9 Sep 2014 11:18:18 +0100 Subject: [PATCH] Added additional unit tests Refs #10092 --- .../API/test/BatchAlgorithmRunnerTest.h | 50 +++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/Code/Mantid/MantidQt/API/test/BatchAlgorithmRunnerTest.h b/Code/Mantid/MantidQt/API/test/BatchAlgorithmRunnerTest.h index 120654d9050a..d53905660d68 100644 --- a/Code/Mantid/MantidQt/API/test/BatchAlgorithmRunnerTest.h +++ b/Code/Mantid/MantidQt/API/test/BatchAlgorithmRunnerTest.h @@ -37,20 +37,21 @@ class BatchAlgorithmRunnerTest : public CxxTest::TestSuite createWsAlg->setProperty("Function", "Exp Decay"); createWsAlg->setProperty("XMax", 20.0); createWsAlg->setProperty("BinWidth", 1.0); + inputFromCreateProps["InputWorkspace"] = "BatchAlgorithmRunnerTest_Create"; - cropRuntimeProps["InputWorkspace"] = "BatchAlgorithmRunnerTest_Create"; cropWsAlg = AlgorithmManager::Instance().create("CropWorkspace", -1); cropWsAlg->initialize(); cropWsAlg->setProperty("OutputWorkspace", "BatchAlgorithmRunnerTest_Crop"); cropWsAlg->setProperty("StartWorkspaceIndex", 4); cropWsAlg->setProperty("EndWorkspaceIndex", 5); + inputFromCropProps["InputWorkspace"] = "BatchAlgorithmRunnerTest_Crop"; - scaleRuntimeProps["InputWorkspace"] = "BatchAlgorithmRunnerTest_Crop"; scaleWsAlg = AlgorithmManager::Instance().create("Scale", -1); scaleWsAlg->initialize(); scaleWsAlg->setProperty("OutputWorkspace", "BatchAlgorithmRunnerTest_Scale"); scaleWsAlg->setProperty("Factor", 5.0); scaleWsAlg->setProperty("Operation", "Add"); + inputFromScaleProps["InputWorkspace"] = "BatchAlgorithmRunnerTest_Scale"; } /** @@ -63,8 +64,8 @@ class BatchAlgorithmRunnerTest : public CxxTest::TestSuite // Add them to the queue // Define the input (and inout, if used) WS properties here runner.addAlgorithm(createWsAlg); - runner.addAlgorithm(cropWsAlg, cropRuntimeProps); - runner.addAlgorithm(scaleWsAlg, scaleRuntimeProps); + runner.addAlgorithm(cropWsAlg, inputFromCreateProps); + runner.addAlgorithm(scaleWsAlg, inputFromCropProps); // Run queue TS_ASSERT(runner.executeBatch()); @@ -79,6 +80,34 @@ class BatchAlgorithmRunnerTest : public CxxTest::TestSuite TS_ASSERT_EQUALS("Scale", history.getAlgorithmHistory(2)->name()) } + /** + * Tests runs of multiple batches on the same runner. + */ + void test_basicMultipleBatch() + { + BatchAlgorithmRunner runner(NULL); + std::string wsName = "BatchAlgorithmRunnerTest_Crop"; + + // Run 1 + runner.addAlgorithm(createWsAlg); + runner.addAlgorithm(cropWsAlg, inputFromCreateProps); + TS_ASSERT(runner.executeBatch()); + + auto historyRun1 = AnalysisDataService::Instance().retrieveWS(wsName)->getHistory(); + TS_ASSERT_EQUALS("CreateSampleWorkspace", historyRun1.getAlgorithmHistory(0)->name()) + TS_ASSERT_EQUALS("CropWorkspace", historyRun1.getAlgorithmHistory(1)->name()) + + // Run 2 + runner.addAlgorithm(scaleWsAlg, inputFromCreateProps); + runner.addAlgorithm(cropWsAlg, inputFromScaleProps); + TS_ASSERT(runner.executeBatch()); + + auto historyRun2 = AnalysisDataService::Instance().retrieveWS(wsName)->getHistory(); + TS_ASSERT_EQUALS("CreateSampleWorkspace", historyRun1.getAlgorithmHistory(0)->name()) + TS_ASSERT_EQUALS("Scale", historyRun2.getAlgorithmHistory(1)->name()) + TS_ASSERT_EQUALS("CropWorkspace", historyRun2.getAlgorithmHistory(2)->name()) + } + /** * Tests failure caused by setting a property such that it fails validation. */ @@ -86,12 +115,12 @@ class BatchAlgorithmRunnerTest : public CxxTest::TestSuite { BatchAlgorithmRunner runner(NULL); - cropRuntimeProps["InputWorkspace"] = "BatchAlgorithmRunner_NoWorkspace"; + inputFromCreateProps["InputWorkspace"] = "BatchAlgorithmRunner_NoWorkspace"; // Add them to the queue // Define the input (and inout, if used) WS properties here runner.addAlgorithm(createWsAlg); - runner.addAlgorithm(cropWsAlg, cropRuntimeProps); + runner.addAlgorithm(cropWsAlg, inputFromCreateProps); // Run queue TS_ASSERT(!runner.executeBatch()); @@ -104,12 +133,12 @@ class BatchAlgorithmRunnerTest : public CxxTest::TestSuite { BatchAlgorithmRunner runner(NULL); - cropRuntimeProps["NotAValidProperty"] = "sample_data.nxs"; + inputFromCreateProps["NotAValidProperty"] = "sample_data.nxs"; // Add them to the queue // Define the input (and inout, if used) WS properties here runner.addAlgorithm(createWsAlg); - runner.addAlgorithm(cropWsAlg, cropRuntimeProps); + runner.addAlgorithm(cropWsAlg, inputFromCreateProps); // Run queue TS_ASSERT(!runner.executeBatch()); @@ -120,8 +149,9 @@ class BatchAlgorithmRunnerTest : public CxxTest::TestSuite IAlgorithm_sptr cropWsAlg; IAlgorithm_sptr scaleWsAlg; - BatchAlgorithmRunner::AlgorithmRuntimeProps cropRuntimeProps; - BatchAlgorithmRunner::AlgorithmRuntimeProps scaleRuntimeProps; + BatchAlgorithmRunner::AlgorithmRuntimeProps inputFromCreateProps; + BatchAlgorithmRunner::AlgorithmRuntimeProps inputFromCropProps; + BatchAlgorithmRunner::AlgorithmRuntimeProps inputFromScaleProps; };