Skip to content

Commit

Permalink
Added additional unit tests
Browse files Browse the repository at this point in the history
Refs #10092
  • Loading branch information
DanNixon committed Sep 9, 2014
1 parent fcc6685 commit 5ca90c7
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 deletions Code/Mantid/MantidQt/API/test/BatchAlgorithmRunnerTest.h
Expand Up @@ -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";
}

/**
Expand All @@ -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());
Expand All @@ -79,19 +80,47 @@ 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<MatrixWorkspace>(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<MatrixWorkspace>(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.
*/
void test_basicBatchWorkspaceFailure()
{
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());
Expand All @@ -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());
Expand All @@ -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;

};

Expand Down

0 comments on commit 5ca90c7

Please sign in to comment.