MDEventFactoryTest.h 4.16 KB
Newer Older
1
2
#ifndef MANTID_DATAOBJECTS_MDEVENTFACTORYTEST_H_
#define MANTID_DATAOBJECTS_MDEVENTFACTORYTEST_H_
3
4
5
6
7

#include <cxxtest/TestSuite.h>
#include <MantidKernel/Timer.h>
#include <MantidKernel/System.h>

8
#include <MantidDataObjects/MDEventFactory.h>
9

10
using namespace Mantid::DataObjects;
11
using namespace Mantid::API;
12

13
class MDEventFactoryTest : public CxxTest::TestSuite {
14
15
public:
  /** Create MDEW's with various number of dimensions */
16
  void test_factory() {
17
    IMDEventWorkspace_sptr ew;
18
    ew = MDEventFactory::CreateMDWorkspace(4, "MDLeanEvent");
19
20
21
22
23
24
25
    TS_ASSERT_EQUALS(ew->getNumDims(), 4);
    TSM_ASSERT_EQUALS("Should have volume normalization as a default",
                      ew->displayNormalization(),
                      Mantid::API::VolumeNormalization);
    TSM_ASSERT_EQUALS("Should have volume normalization as a default",
                      ew->displayNormalizationHisto(),
                      Mantid::API::VolumeNormalization);
26
27

    size_t n = 9;
28
    auto eventNormalization = Mantid::API::NoNormalization;
29
    auto histoNormalization = Mantid::API::NumEventsNormalization;
30
31
32
33
34
35
36
37
38
39
    ew = MDEventFactory::CreateMDWorkspace(n, "MDLeanEvent", eventNormalization,
                                           histoNormalization);
    TS_ASSERT_EQUALS(ew->getNumDims(), n);
    TSM_ASSERT_EQUALS("Should have no normalization set.",
                      ew->displayNormalization(), eventNormalization);
    TSM_ASSERT_EQUALS("Should have number of events set.",
                      ew->displayNormalizationHisto(), histoNormalization);

    TS_ASSERT_THROWS(ew = MDEventFactory::CreateMDWorkspace(0),
                     std::invalid_argument);
40
41
  }

42
  void test_box_factory() {
Peterson, Peter's avatar
Peterson, Peter committed
43
    BoxController_sptr bc = boost::make_shared<BoxController>(4);
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

    IMDNode *Box = MDEventFactory::createBox(
        4, MDEventFactory::BoxType::MDBoxWithLean, bc);
    TS_ASSERT_EQUALS(Box->getNumDims(), 4);
    MDBox<MDLeanEvent<4>, 4> *leanBox =
        dynamic_cast<MDBox<MDLeanEvent<4>, 4> *>(Box);
    TS_ASSERT(leanBox != NULL);
    delete Box;

    bc.reset(new BoxController(9));
    Box =
        MDEventFactory::createBox(9, MDEventFactory::BoxType::MDBoxWithFat, bc);
    TS_ASSERT_EQUALS(Box->getNumDims(), 9);
    MDBox<MDEvent<9>, 9> *fatBox = dynamic_cast<MDBox<MDEvent<9>, 9> *>(Box);
    TS_ASSERT(fatBox != NULL);
    delete Box;

    bc.reset(new BoxController(3));
    Box = MDEventFactory::createBox(
        3, MDEventFactory::BoxType::MDGridBoxWithLean, bc);
    TS_ASSERT_EQUALS(Box->getNumDims(), 3);
    MDGridBox<MDLeanEvent<3>, 3> *leanGridBox =
        dynamic_cast<MDGridBox<MDLeanEvent<3>, 3> *>(Box);
    TS_ASSERT(leanGridBox != NULL);
    delete Box;

    bc.reset(new BoxController(1));
    Box = MDEventFactory::createBox(
        1, MDEventFactory::BoxType::MDGridBoxWithFat, bc);
    TS_ASSERT_EQUALS(Box->getNumDims(), 1);
    MDGridBox<MDEvent<1>, 1> *fatGridBox =
        dynamic_cast<MDGridBox<MDEvent<1>, 1> *>(Box);
    TS_ASSERT(fatGridBox != NULL);
    delete Box;

    TS_ASSERT_THROWS(MDEventFactory::createBox(
                         0, MDEventFactory::BoxType::MDBoxWithLean, bc),
                     std::invalid_argument);
    TS_ASSERT_THROWS(MDEventFactory::createBox(
                         10, MDEventFactory::BoxType::MDGridBoxWithFat, bc),
                     std::invalid_argument);
85
86
  }

87
  // Templated function that will be called for a specific MDEW
88
89
  template <typename MDE, size_t nd>
  void functionTest(typename MDEventWorkspace<MDE, nd>::sptr ws) {
90
91
92
    test_value = ws->getNumDims();
  }

93
94
95
96
  void test_CALL_MDEVENT_FUNCTION_macro() {
    IMDEventWorkspace_sptr ew(new MDEventWorkspace<MDLeanEvent<1>, 1>());
    TS_ASSERT_EQUALS(ew->getNumDims(), 1);
    TS_ASSERT_EQUALS(ew->getNPoints(), 0);
97
    test_value = 0;
98
99
    CALL_MDEVENT_FUNCTION(functionTest, ew);
    TS_ASSERT_EQUALS(test_value, 1);
100
101
  }

102
103
104
105
  void test_CALL_MDEVENT_FUNCTION_macro_2() {
    IMDEventWorkspace_sptr ew(new MDEventWorkspace<MDLeanEvent<8>, 8>());
    TS_ASSERT_EQUALS(ew->getNumDims(), 8);
    TS_ASSERT_EQUALS(ew->getNPoints(), 0);
106
    test_value = 0;
107
108
    CALL_MDEVENT_FUNCTION(functionTest, ew);
    TS_ASSERT_EQUALS(test_value, 8);
109
110
  }

111
  size_t test_value;
112
113
};

114
#endif /* MANTID_DATAOBJECTS_MDEVENTFACTORYTEST_H_ */