LoadILLSANSTest.h 3.92 KB
Newer Older
1
2
3
4
5
#ifndef MANTID_DATAHANDLING_LOADILLSANSTEST_H_
#define MANTID_DATAHANDLING_LOADILLSANSTEST_H_

#include <cxxtest/TestSuite.h>

6
#include "MantidAPI/AnalysisDataService.h"
7
#include "MantidAPI/MatrixWorkspace.h"
8
#include "MantidDataHandling/LoadILLSANS.h"
9
10
11
12

using Mantid::DataHandling::LoadILLSANS;
using namespace Mantid::API;

13
class LoadILLSANSTest : public CxxTest::TestSuite {
14
public:
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
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
  // This pair of boilerplate methods prevent the suite being created statically
  // This means the constructor isn't called when running other tests
  static LoadILLSANSTest *createSuite() { return new LoadILLSANSTest(); }
  static void destroySuite(LoadILLSANSTest *suite) { delete suite; }

  LoadILLSANSTest()
      : m_testFileTof("ILLD33_001030.nxs"),
        m_testFileNonTof("ILLD33_041714_NonTof.nxs") {}
  void testName() {
    LoadILLSANS alg;
    TS_ASSERT_EQUALS(alg.name(), "LoadILLSANS");
  }

  void testVersion() {
    LoadILLSANS alg;
    TS_ASSERT_EQUALS(alg.version(), 1);
  }

  void test_Init() {
    LoadILLSANS alg;
    TS_ASSERT_THROWS_NOTHING(alg.initialize())
    TS_ASSERT(alg.isInitialized())
  }

  void test_exec_TOF() {
    LoadILLSANS loader;
    loader.initialize();
    loader.setPropertyValue("Filename", m_testFileTof);

    std::string outputSpace = "LoadILLSANSTest_out";
    loader.setPropertyValue("OutputWorkspace", outputSpace);
    TS_ASSERT_THROWS_NOTHING(loader.execute());

    //  test workspace, copied from LoadMuonNexusTest.h
    MatrixWorkspace_sptr output;

    (output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(
         outputSpace));
    MatrixWorkspace_sptr output2D =
        boost::dynamic_pointer_cast<MatrixWorkspace>(output);

    TS_ASSERT_EQUALS(output2D->getNumberHistograms(), 65536 + 2);
    TS_ASSERT_EQUALS(output2D->blocksize(), 100);
    TS_ASSERT_DIFFERS(output2D->run().getPropertyValueAsType<double>("monitor"),
                      0.0);
    AnalysisDataService::Instance().clear();
  }

  void test_exec_nonTOF() {
    LoadILLSANS loader;
    loader.initialize();
    loader.setPropertyValue("Filename", m_testFileNonTof);

    std::string outputSpace = "LoadILLSANSTest_out";
    loader.setPropertyValue("OutputWorkspace", outputSpace);
    TS_ASSERT_THROWS_NOTHING(loader.execute());

    //  test workspace, copied from LoadMuonNexusTest.h
    MatrixWorkspace_sptr output;

    (output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(
         outputSpace));
    MatrixWorkspace_sptr output2D =
        boost::dynamic_pointer_cast<MatrixWorkspace>(output);

    TS_ASSERT_EQUALS(output2D->getNumberHistograms(), 65536 + 2);
    TS_ASSERT_EQUALS(output2D->blocksize(), 1);
    TS_ASSERT_DIFFERS(output2D->run().getPropertyValueAsType<double>("monitor"),
                      0.0);
    AnalysisDataService::Instance().clear();
  }

private:
  std::string m_testFileTof;
  std::string m_testFileNonTof;
90
91
};

92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
class LoadILLSANSTestPerformance : public CxxTest::TestSuite {
public:
  void setUp() override {
    for (int i = 0; i < numberOfIterations; ++i) {
      loadAlgPtrs.emplace_back(setupAlg());
    }
  }

  void testLoadILLSANSPerformance() {
    for (auto alg : loadAlgPtrs) {
      TS_ASSERT_THROWS_NOTHING(alg->execute());
    }
  }

  void tearDown() override {
    for (int i = 0; i < numberOfIterations; i++) {
      delete loadAlgPtrs[i];
      loadAlgPtrs[i] = nullptr;
    }
    Mantid::API::AnalysisDataService::Instance().remove(outWSName);
  }

private:
  std::vector<LoadILLSANS *> loadAlgPtrs;

  const int numberOfIterations = 2;

  const std::string inFileName = "ILLD33_041714_NonTof.nxs";
  const std::string outWSName = "LoadILLSANSWsOut";

  LoadILLSANS *setupAlg() {
    LoadILLSANS *loader = new LoadILLSANS;
    loader->initialize();
    loader->isInitialized();
    loader->setPropertyValue("Filename", inFileName);
    loader->setPropertyValue("OutputWorkspace", outWSName);

    loader->setRethrows(true);
    return loader;
  }
};

134
#endif /* MANTID_DATAHANDLING_LOADILLSANSTEST_H_ */