Newer
Older
#ifndef MANTID_DATAHANDLING_LOADILLREFLECTOMETRYTEST_H_
#define MANTID_DATAHANDLING_LOADILLREFLECTOMETRYTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidDataHandling/LoadILLReflectometry.h"
using Mantid::DataHandling::LoadILLReflectometry;
class LoadILLReflectometryTest : public CxxTest::TestSuite {
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static LoadILLReflectometryTest *createSuite() {
return new LoadILLReflectometryTest();
}
static void destroySuite(LoadILLReflectometryTest *suite) { delete suite; }
LoadILLReflectometryTest() : m_dataFile("ILLD17-161876-Ni.nxs") {}
void test_Init() {
LoadILLReflectometry loader;
TS_ASSERT_THROWS_NOTHING(loader.initialize())
TS_ASSERT(loader.isInitialized())
}
void testName() {
LoadILLReflectometry loader;
TS_ASSERT_EQUALS(loader.name(), "LoadILLReflectometry");
}
void test_exec() {
// Name of the output workspace.
std::string outWSName("LoadILLReflectometryTest_OutputWS");
LoadILLReflectometry loader;
TS_ASSERT_THROWS_NOTHING(loader.initialize())
TS_ASSERT(loader.isInitialized())
TS_ASSERT_THROWS_NOTHING(loader.setPropertyValue("Filename", m_dataFile));
TS_ASSERT_THROWS_NOTHING(
loader.setPropertyValue("OutputWorkspace", outWSName));
TS_ASSERT_THROWS_NOTHING(loader.execute(););
TS_ASSERT(loader.isExecuted());
MatrixWorkspace_sptr output =
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWSName);
TS_ASSERT(output);
TS_ASSERT_EQUALS(output->getNumberHistograms(), 256 + 2);
double channelWidth = getPropertyFromRun<double>(output, "channel_width");
TS_ASSERT_EQUALS(channelWidth, 57.0);
double analyserAngle = getPropertyFromRun<double>(output, "dan.value");
TS_ASSERT_EQUALS(analyserAngle, 3.1909999847412109);
// Remove workspace from the data service.
AnalysisDataService::Instance().clear();
}
std::string m_dataFile;
template <typename T>
T getPropertyFromRun(MatrixWorkspace_const_sptr inputWS,
const std::string &propertyName) {
if (inputWS->run().hasProperty(propertyName)) {
Mantid::Kernel::Property *prop = inputWS->run().getProperty(propertyName);
return boost::lexical_cast<T>(prop->value());
} else {
std::string mesg =
"No '" + propertyName + "' property found in the input workspace....";
throw std::runtime_error(mesg);
}
}
#endif /* MANTID_DATAHANDLING_LOADILLREFLECTOMETRYTEST_H_ */