Newer
Older
#ifndef CONVERTTOMATRIXWORKSPACETEST_H_
#define CONVERTTOMATRIXWORKSPACETEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidAlgorithms/CheckWorkspacesMatch.h"
#include "MantidAlgorithms/ConvertToMatrixWorkspace.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
Janik Zikovsky
committed
using namespace Mantid;
using namespace Mantid::Kernel;
class ConvertToMatrixWorkspaceTest : public CxxTest::TestSuite {
public:
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
void testName() {
Mantid::Algorithms::ConvertToMatrixWorkspace cloner;
TS_ASSERT_EQUALS(cloner.name(), "ConvertToMatrixWorkspace")
}
void testVersion() {
Mantid::Algorithms::ConvertToMatrixWorkspace cloner;
TS_ASSERT_EQUALS(cloner.version(), 1)
}
void testInit() {
Mantid::Algorithms::ConvertToMatrixWorkspace cloner;
TS_ASSERT_THROWS_NOTHING(cloner.initialize())
TS_ASSERT(cloner.isInitialized())
}
void testExec_2D_to_2D() {
Mantid::Algorithms::ConvertToMatrixWorkspace cloner;
cloner.setChild(true);
cloner.initialize();
// create 2D input workspace
Mantid::API::MatrixWorkspace_sptr in =
WorkspaceCreationHelper::Create2DWorkspace(5, 10);
// add instance to variable 'in'
Mantid::API::MatrixWorkspace_sptr out;
TS_ASSERT_THROWS_NOTHING(cloner.setProperty("InputWorkspace", in))
TS_ASSERT_THROWS_NOTHING(cloner.setProperty("OutputWorkspace", "out"))
TS_ASSERT(cloner.execute())
// retrieve OutputWorkspace produced by execute and set it to out
TS_ASSERT_THROWS_NOTHING(out = cloner.getProperty("OutputWorkspace"));
TS_ASSERT(out);
if (!out)
return;
// Best way to test this is to use the CheckWorkspacesMatch algorithm
Mantid::Algorithms::CheckWorkspacesMatch checker;
checker.initialize();
checker.setProperty("Workspace1", in);
checker.setProperty("Workspace2", out);
checker.execute();
TS_ASSERT_EQUALS(checker.getPropertyValue("Result"),
checker.successString());
}
void testExec_Event_to_2D() {
Mantid::Algorithms::ConvertToMatrixWorkspace cloner;
cloner.setChild(true);
cloner.initialize();
Mantid::DataObjects::EventWorkspace_sptr in =
WorkspaceCreationHelper::createEventWorkspaceWithFullInstrument(1, 10);
TS_ASSERT_THROWS_NOTHING(cloner.setProperty("InputWorkspace", in))
TS_ASSERT_THROWS_NOTHING(cloner.setPropertyValue("OutputWorkspace", "out"))
TS_ASSERT(cloner.execute())
Mantid::API::MatrixWorkspace_sptr out;
TS_ASSERT_THROWS_NOTHING(out = cloner.getProperty("OutputWorkspace"));
TS_ASSERT(out);
if (!out)
return;
TS_ASSERT_EQUALS(in->getNumberHistograms(), out->getNumberHistograms());
TS_ASSERT_EQUALS(in->getInstrument()->getName(),
out->getInstrument()->getName());
TS_ASSERT_EQUALS(in->getInstrument()->isParametrized(),
out->getInstrument()->isParametrized());
for (size_t i = 0; i < out->getNumberHistograms(); i++) {
const Mantid::API::ISpectrum *inSpec = in->getSpectrum(i);
const Mantid::API::ISpectrum *outSpec = out->getSpectrum(i);
TSM_ASSERT_EQUALS("Failed on comparing Spectrum Number for Histogram: " +
std::to_string(i),
inSpec->getSpectrumNo(), outSpec->getSpectrumNo());
TSM_ASSERT_EQUALS("Failed on comparing Detector ID for Histogram: " +
*inSpec->getDetectorIDs().begin(),
*outSpec->getDetectorIDs().begin());
TSM_ASSERT_EQUALS("Failed on readX for Histogram: " + i.toString(),
in->readX(i), out->readX(i));
TSM_ASSERT_EQUALS("Failed on readY for Histogram: " + i.toString(),
in->readY(i), out->readY(i));
TSM_ASSERT_EQUALS("Failed on readE for Histogram: " + i.toString(),
in->readE(i), out->readE(i));
};
#endif /*CONVERTTOMATRIXWORKSPACETEST_H_*/