Skip to content

Commit

Permalink
Add unit test for ClearInstrumentParameters.
Browse files Browse the repository at this point in the history
Refs #10020.
  • Loading branch information
Harry Jeffery committed Aug 4, 2014
1 parent 82db0df commit 743c0f1
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/Framework/Algorithms/CMakeLists.txt
Expand Up @@ -522,6 +522,7 @@ set ( TEST_FILES
ChangePulsetimeTest.h
CheckWorkspacesMatchTest.h
ChopDataTest.h
ClearInstrumentParametersTest.h
ClearMaskFlagTest.h
CloneWorkspaceTest.h
CommutativeBinaryOperationTest.h
Expand Down
@@ -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 */

0 comments on commit 743c0f1

Please sign in to comment.