Newer
Older
#ifndef MANTID_MDALGORITHMS_MERGEMDTEST_H_
#define MANTID_MDALGORITHMS_MERGEMDTEST_H_
#include "MantidMDAlgorithms/MergeMD.h"
#include "MantidDataObjects/MDEventFactory.h"
#include "MantidGeometry/MDGeometry/IMDDimension.h"
#include "MantidTestHelpers/MDEventsTestHelper.h"
#include <Poco/File.h>
using namespace Mantid;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
using namespace Mantid::Geometry;
using namespace Mantid::MDAlgorithms;
using Mantid::DataObjects::MDEventsTestHelper::makeAnyMDEW;
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
class MergeMDTest : public CxxTest::TestSuite
{
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static MergeMDTest *createSuite() { return new MergeMDTest(); }
static void destroySuite( MergeMDTest *suite ) { delete suite; }
void setUp()
{
makeAnyMDEW<MDEvent<3>, 3>(2, 5., 10., 1, "mde3");
makeAnyMDEW<MDEvent<4>, 4>(2, 5., 10., 1, "mde4");
makeAnyMDEW<MDLeanEvent<3>, 3>(2, 5., 10., 1, "mdle3");
// Several compatible 2D workspaces
makeAnyMDEW<MDLeanEvent<2>, 2>(2, 0., 10., 1, "ws0");
makeAnyMDEW<MDLeanEvent<2>, 2>(6, -5., 10., 1, "ws1");
makeAnyMDEW<MDLeanEvent<2>, 2>(10, 0., 20., 1, "ws2");
}
void test_Init()
{
MergeMD alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
}
void test_failures()
{
do_test_fails("mde3, mde4");
do_test_fails("mde3, mdle3");
}
/** Run MergeMD, expect it to fail */
void do_test_fails(const std::string & inputs)
{
MergeMD alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("InputWorkspaces", inputs) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("OutputWorkspace", "failed_output") );
TS_ASSERT_THROWS_NOTHING( alg.execute(); );
TS_ASSERT( !alg.isExecuted() );
}
void test_exec()
{
// Name of the output workspace.
std::string outWSName("MergeMDTest_OutputWS");
MergeMD alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("InputWorkspaces", "ws0,ws1,ws2") );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("OutputWorkspace", outWSName) );
TS_ASSERT_THROWS_NOTHING( alg.execute(); );
TS_ASSERT( alg.isExecuted() );
// Retrieve the workspace from data service.
IMDEventWorkspace_sptr ws;
TS_ASSERT_THROWS_NOTHING( ws = AnalysisDataService::Instance().retrieveWS<IMDEventWorkspace>(outWSName) );
TS_ASSERT(ws);
if (!ws) return;
// Number of events is the sum of the 3 input ones.
TS_ASSERT_EQUALS( ws->getNPoints(), 2*2 + 6*6 + 10*10);
for (size_t d=0; d<2; d++)
{
IMDDimension_const_sptr dim = ws->getDimension(d);
TS_ASSERT_DELTA( dim->getMinimum(), -5.0, 1e-3);
TS_ASSERT_DELTA( dim->getMaximum(), +20.0, 1e-3);
}