Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for ClearInstrumentParameters.
Refs #10020.
- Loading branch information
Harry Jeffery
committed
Aug 4, 2014
1 parent
82db0df
commit 743c0f1
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
Code/Mantid/Framework/Algorithms/test/ClearInstrumentParametersTest.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#ifndef CLEARINSTRUMENTPARAMETERSTEST_H | ||
#define CLEARINSTRUMENTPARAMETERSTEST_H | ||
|
||
#include <cxxtest/TestSuite.h> | ||
|
||
#include "MantidAlgorithms/ClearInstrumentParameters.h" | ||
#include "MantidAPI/AnalysisDataService.h" | ||
#include "MantidDataHandling/LoadInstrument.h" | ||
#include "MantidDataObjects/Workspace2D.h" | ||
|
||
using namespace Mantid::Algorithms; | ||
using namespace Mantid::API; | ||
using namespace Mantid::Kernel; | ||
using namespace Mantid::Geometry; | ||
using namespace Mantid::DataHandling; | ||
using namespace Mantid::DataObjects; | ||
|
||
class ClearInstrumentParametersTest : public CxxTest::TestSuite | ||
{ | ||
public: | ||
|
||
void testClearInstrumentParameters() | ||
{ | ||
//Load a workspace | ||
prepareWorkspace(); | ||
|
||
//Set some parameters | ||
setParam("nickel-holder", "testDouble", 1.23); | ||
setParam("nickel-holder", "testString", "hello world"); | ||
|
||
//Clear the parameters | ||
clearParameters(); | ||
|
||
//Check the parameters | ||
checkEmpty("nickel-holder", "testDouble"); | ||
checkEmpty("nickel-holder", "testString"); | ||
} | ||
|
||
void setParam(std::string cName, std::string pName, std::string value) | ||
{ | ||
Instrument_const_sptr inst = m_ws->getInstrument(); | ||
ParameterMap& paramMap = m_ws->instrumentParameters(); | ||
boost::shared_ptr<const IComponent> comp = inst->getComponentByName(cName); | ||
paramMap.addString(comp->getComponentID(), pName, value); | ||
} | ||
|
||
void setParam(std::string cName, std::string pName, double value) | ||
{ | ||
Instrument_const_sptr inst = m_ws->getInstrument(); | ||
ParameterMap& paramMap = m_ws->instrumentParameters(); | ||
boost::shared_ptr<const IComponent> comp = inst->getComponentByName(cName); | ||
paramMap.addDouble(comp->getComponentID(), pName, value); | ||
} | ||
|
||
void checkEmpty(std::string cName, std::string pName) | ||
{ | ||
Instrument_const_sptr inst = m_ws->getInstrument(); | ||
ParameterMap& paramMap = m_ws->instrumentParameters(); | ||
boost::shared_ptr<const IComponent> comp = inst->getComponentByName(cName); | ||
bool exists = paramMap.contains(comp.get(), pName); | ||
TS_ASSERT_EQUALS(exists, false); | ||
} | ||
|
||
void clearParameters() | ||
{ | ||
ClearInstrumentParameters clearer; | ||
TS_ASSERT_THROWS_NOTHING(clearer.initialize()); | ||
clearer.setPropertyValue("Workspace", m_ws->name()); | ||
TS_ASSERT_THROWS_NOTHING(clearer.execute()); | ||
TS_ASSERT(clearer.isExecuted()); | ||
} | ||
|
||
void prepareWorkspace() | ||
{ | ||
LoadInstrument loaderIDF2; | ||
|
||
TS_ASSERT_THROWS_NOTHING(loaderIDF2.initialize()); | ||
|
||
std::string wsName = "SaveParameterFileTestIDF2"; | ||
Workspace_sptr ws = WorkspaceFactory::Instance().create("Workspace2D",1,1,1); | ||
Workspace2D_sptr ws2D = boost::dynamic_pointer_cast<Workspace2D>(ws); | ||
|
||
TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(wsName, ws2D)); | ||
|
||
loaderIDF2.setPropertyValue("Filename", "IDFs_for_UNIT_TESTING/IDF_for_UNIT_TESTING2.xml"); | ||
loaderIDF2.setPropertyValue("Workspace", wsName); | ||
TS_ASSERT_THROWS_NOTHING(loaderIDF2.execute()); | ||
TS_ASSERT( loaderIDF2.isExecuted() ); | ||
|
||
m_ws = boost::dynamic_pointer_cast<MatrixWorkspace>(ws2D); | ||
} | ||
|
||
private: | ||
MatrixWorkspace_sptr m_ws; | ||
}; | ||
|
||
#endif /* CLEARINSTRUMENTPARAMETERSTEST_H */ |