Skip to content

Commit

Permalink
Begin unit test of new property re #8398
Browse files Browse the repository at this point in the history
Unit test present just tests that it executes without error.
Also some fixes to ensure it executes without error.

Signed-off-by: Karl Palmen <karl.palmen@stfc.ac.uk>
  • Loading branch information
KarlPalmen committed Dec 17, 2013
1 parent 89bd573 commit 8171401
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 5 deletions.
Expand Up @@ -81,7 +81,7 @@ namespace DataHandling
"Path to an Fullprof .irf file to load.");

// Output table workspace
auto wsprop = new WorkspaceProperty<API::ITableWorkspace>("OutputTableWorkspace", "", Direction::Output);
auto wsprop = new WorkspaceProperty<API::ITableWorkspace>("OutputTableWorkspace", "", Direction::Output, PropertyMode::Optional);
declareProperty(wsprop, "Name of the output TableWorkspace containing profile parameters or bank information. ");

// Bank to import
Expand Down Expand Up @@ -187,12 +187,13 @@ namespace DataHandling
// Generate output table workspace
API::ITableWorkspace_sptr outTabWs = genTableWorkspace(bankparammap);

// 6. Output table workspace
setProperty("OutputTableWorkspace", outTabWs);

// 7. If workspace, put parameters there
// If workspace, put parameters there
if(workspace){
putParametersIntoWorkspace( outTabWs, workspace );
}
else
{ // else, output the output table workspace
setProperty("OutputTableWorkspace", outTabWs);
}

return;
Expand Down
Expand Up @@ -6,12 +6,15 @@
#include "MantidDataHandling/LoadFullprofResolution.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidAPI/TableRow.h"
#include "MantidDataHandling/LoadInstrument.h"
#include "MantidDataObjects/Workspace2D.h"
#include <fstream>
#include <Poco/File.h>

using Mantid::DataHandling::LoadFullprofResolution;

using namespace Mantid;
using namespace Mantid::DataHandling;
using namespace Mantid::DataObjects;
using namespace Mantid::Kernel;
using namespace Mantid::API;
Expand Down Expand Up @@ -267,6 +270,38 @@ class LoadFullprofResolutionTest : public CxxTest::TestSuite
return;
}

//----------------------------------------------------------------------------------------------
/** Test that when the workspace property is used
** that parameters are correctly loaded into this workspace
* The GEM instrument is used
*/
void test_workspace()
{
// Generate file
string filename("TestWorskpace.irf");
generate1BankIrfFile(filename);

// Load workspace wsName
load_GEM();

// Set up algorithm to load into the workspace
LoadFullprofResolution alg;
alg.initialize();

alg.setProperty("Filename", filename);
alg.setPropertyValue("Banks", "1");
alg.setProperty("Workspace", wsName);

// Execute
TS_ASSERT_THROWS_NOTHING(alg.execute());
TS_ASSERT(alg.isExecuted());

// Check parameters in workspace

// Clean
Poco::File("TestWorskpace.irf").remove();
}

//----------------------------------------------------------------------------------------------
/** Test that the number from the NPROF is read correctly
** and has correct name in table.
Expand Down Expand Up @@ -380,6 +415,33 @@ class LoadFullprofResolutionTest : public CxxTest::TestSuite
return;
}


//----------------------------------------------------------------------------------------------
/** Generate a GEM workspace
*/
void load_GEM()
{
LoadInstrument loaderGEM;

TS_ASSERT_THROWS_NOTHING(loaderGEM.initialize());

//create a workspace with some sample data
wsName = "LoadFullprofResolutionWorkspace";
Workspace_sptr ws = WorkspaceFactory::Instance().create("Workspace2D",1,1,1);
Workspace2D_sptr ws2D = boost::dynamic_pointer_cast<Workspace2D>(ws);

//put this workspace in the data service
TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(wsName, ws2D));

// Path to test input file
loaderGEM.setPropertyValue("Filename", "GEM_Definition.xml");
//inputFile = loaderIDF2.getPropertyValue("Filename");
loaderGEM.setPropertyValue("Workspace", wsName);
TS_ASSERT_THROWS_NOTHING(loaderGEM.execute());
TS_ASSERT( loaderGEM.isExecuted() );

}

//----------------------------------------------------------------------------------------------
/** Generate a 1 bank .irf file
*/
Expand Down Expand Up @@ -573,6 +635,9 @@ class LoadFullprofResolutionTest : public CxxTest::TestSuite
return 29; // Change this value if you add or remove any rows from the OutputTableWorkspace
}

private:
std::string wsName; // For Workspace property

};


Expand Down

0 comments on commit 8171401

Please sign in to comment.