Newer
Older
#ifndef IMD_MATRIX_WORKSPACETEST_H_
#define IMD_MATRIX_WORKSPACETEST_H_
// Tests the MatrixWorkspace as an IMDWorkspace.
#include <cxxtest/TestSuite.h>
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidAPI/NumericAxis.h"
#include "MantidAPI/SpectraAxis.h"
Russell Taylor
committed
#include "MantidGeometry/Instrument.h"
#include "MantidGeometry/MDGeometry/IMDDimension.h"
#include "MantidAPI/MatrixWSIndexCalculator.h"
#include "MantidTestHelpers/FakeObjects.h"
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::Geometry;
// Test the MatrixWorkspace as an IMDWorkspace.
class IMDWorkspaceTest : public CxxTest::TestSuite {
Janik Zikovsky
committed
WorkspaceTester workspace;
Russell Taylor
committed
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static IMDWorkspaceTest *createSuite() { return new IMDWorkspaceTest(); }
static void destroySuite(IMDWorkspaceTest *suite) { delete suite; }
Janik Zikovsky
committed
workspace.getSpectrum(0)->setSpectrumNo(1);
workspace.getSpectrum(1)->setSpectrumNo(2);
for (int i = 0; i < 3; ++i) {
workspace.dataY(0)[i] = i * 10;
workspace.dataE(0)[i] = sqrt(workspace.dataY(0)[i]);
Janik Zikovsky
committed
workspace.dataE(1)[i] = sqrt(workspace.dataY(1)[i]);
Janik Zikovsky
committed
WorkspaceTester matrixWS;
boost::shared_ptr<const Mantid::Geometry::IMDDimension> dimension =
matrixWS.getXDimension();
TSM_ASSERT_EQUALS("Dimension-X does not have the expected dimension id.",
"xDimension", id);
Janik Zikovsky
committed
WorkspaceTester matrixWS;
boost::shared_ptr<const Mantid::Geometry::IMDDimension> dimension =
matrixWS.getYDimension();
TSM_ASSERT_EQUALS("Dimension-Y does not have the expected dimension id.",
"yDimension", id);
Janik Zikovsky
committed
WorkspaceTester matrixWS;
TSM_ASSERT_THROWS_ANYTHING(
"Current implementation should throw runtime error.",
matrixWS.getZDimension());
Janik Zikovsky
committed
WorkspaceTester matrixWS;
TSM_ASSERT_THROWS_ANYTHING(
"Current implementation should throw runtime error.",
matrixWS.getTDimension());
Janik Zikovsky
committed
WorkspaceTester matrixWS;
matrixWS.init(1, 1, 1);
TSM_ASSERT_THROWS("Id doesn't exist. Should throw during find routine.",
matrixWS.getDimensionWithId("3"), std::overflow_error);
Janik Zikovsky
committed
WorkspaceTester matrixWS;
matrixWS.init(1, 1, 1);
boost::shared_ptr<const Mantid::Geometry::IMDDimension> dim =
matrixWS.getDimensionWithId("yDimension");
TSM_ASSERT_EQUALS(
"The dimension id found is not the same as that searched for.",
"yDimension", dim->getDimensionId());
void testGetDimensionOverflow() {
Janik Zikovsky
committed
WorkspaceTester matrixWS;
matrixWS.init(1, 1, 1);
TSM_ASSERT_THROWS(
"The dimension does not exist. Attempting to get it should throw",
matrixWS.getDimensionWithId("1"), std::overflow_error);
Janik Zikovsky
committed
WorkspaceTester matrixWS;
TSM_ASSERT_EQUALS("The expected number of points have not been returned.",
25, matrixWS.getNPoints());
HistogramIndex histogramIndexA = indexCalculator.getHistogramIndex(4);
HistogramIndex histogramIndexB = indexCalculator.getHistogramIndex(5);
HistogramIndex histogramIndexC = indexCalculator.getHistogramIndex(10);
TSM_ASSERT_EQUALS("histogram index has not been calculated correctly.", 0,
histogramIndexA);
TSM_ASSERT_EQUALS("histogram index has not been calculated correctly.", 1,
histogramIndexB);
TSM_ASSERT_EQUALS("histogram index has not been calculated correctly.", 2,
histogramIndexC);
BinIndex binIndexA = indexCalculator.getBinIndex(4, 0);
BinIndex binIndexB = indexCalculator.getBinIndex(12, 2);
TSM_ASSERT_EQUALS("bin index has not been calculated correctly.", 4,
binIndexA);
TSM_ASSERT_EQUALS("bin index has not been calculated correctly.", 2,
binIndexB);
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/**
* Test declaring an input workspace and retrieving as const_sptr or sptr
*/
void testGetProperty_const_sptr() {
const std::string wsName = "InputWorkspace";
IMDWorkspace_sptr wsInput(new WorkspaceTester());
PropertyManagerHelper manager;
manager.declareProperty(wsName, wsInput, Direction::Input);
// Check property can be obtained as const_sptr or sptr
IMDWorkspace_const_sptr wsConst;
IMDWorkspace_sptr wsNonConst;
TS_ASSERT_THROWS_NOTHING(
wsConst = manager.getValue<IMDWorkspace_const_sptr>(wsName));
TS_ASSERT(wsConst != NULL);
TS_ASSERT_THROWS_NOTHING(wsNonConst =
manager.getValue<IMDWorkspace_sptr>(wsName));
TS_ASSERT(wsNonConst != NULL);
TS_ASSERT_EQUALS(wsConst, wsNonConst);
// Check TypedValue can be cast to const_sptr or to sptr
PropertyManagerHelper::TypedValue val(manager, wsName);
IMDWorkspace_const_sptr wsCastConst;
IMDWorkspace_sptr wsCastNonConst;
TS_ASSERT_THROWS_NOTHING(wsCastConst = (IMDWorkspace_const_sptr)val);
TS_ASSERT(wsCastConst != NULL);
TS_ASSERT_THROWS_NOTHING(wsCastNonConst = (IMDWorkspace_sptr)val);
TS_ASSERT(wsCastNonConst != NULL);
TS_ASSERT_EQUALS(wsCastConst, wsCastNonConst);
}
};
#endif /*IMD_MATRIX_WORKSPACETEST_H_*/