Skip to content

Commit

Permalink
Refs #4036 unary op test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Janik Zikovsky committed Nov 8, 2011
1 parent f52f008 commit 1899fe1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@ namespace BinaryOperationMDTestHelper

} // (end namespace)

namespace UnaryOperationMDTestHelper
{
/// Run a unary algorithm.
Mantid::MDEvents::MDHistoWorkspace_sptr doTest(std::string algoName, std::string inName, std::string outName,
bool succeeds=true);

} // (end namespace)

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,41 @@ namespace BinaryOperationMDTestHelper
}

} // (end namespace)



namespace UnaryOperationMDTestHelper
{

MDHistoWorkspace_sptr doTest(std::string algoName, std::string inName, std::string outName,
bool succeeds)
{
MDHistoWorkspace_sptr histo = MDEventsTestHelper::makeFakeMDHistoWorkspace(1.0, 2, 5, 10.0, 1.0);
IMDEventWorkspace_sptr event = MDEventsTestHelper::makeMDEW<2>(3, 0.0, 10.0, 1);
WorkspaceSingleValue_sptr scalar = WorkspaceCreationHelper::CreateWorkspaceSingleValue(2.5);
AnalysisDataService::Instance().addOrReplace("histo", histo);
AnalysisDataService::Instance().addOrReplace("event", event);
AnalysisDataService::Instance().addOrReplace("scalar", scalar);

IAlgorithm* alg = FrameworkManager::Instance().createAlgorithm(algoName);
alg->initialize();
alg->setPropertyValue("InputWorkspace", inName );
alg->setPropertyValue("OutputWorkspace", outName );
alg->execute();
if (succeeds)
{
if (!alg->isExecuted())
throw std::runtime_error("Algorithm " + algoName + " did not succeed.");
IMDWorkspace_sptr out = boost::dynamic_pointer_cast<IMDWorkspace>( AnalysisDataService::Instance().retrieve(outName));
if (!out)
throw std::runtime_error("Algorithm " + algoName + " did not create the output workspace.");
return boost::dynamic_pointer_cast<MDHistoWorkspace>(out);
}
else
{
if (alg->isExecuted())
throw std::runtime_error("Algorithm " + algoName + " did not fail as expected.");
return (MDHistoWorkspace_sptr());
}
}
} // (end namespace)

0 comments on commit 1899fe1

Please sign in to comment.