Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
#ifndef MANTID_MDALGORITHMS_SMOOTHMDTEST_H_
#define MANTID_MDALGORITHMS_SMOOTHMDTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidMDAlgorithms/SmoothMD.h"
#include "MantidMDEvents/MDHistoWorkspace.h"
#include "MantidTestHelpers/MDEventsTestHelper.h"
#include "MantidAPI/IMDHistoWorkspace.h"
#include <vector>
using Mantid::MDAlgorithms::SmoothMD;
using namespace Mantid::API;
using namespace Mantid::MDEvents;
class SmoothMDTest : 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 SmoothMDTest *createSuite() { return new SmoothMDTest(); }
static void destroySuite(SmoothMDTest *suite) { delete suite; }
void test_Init() {
SmoothMD alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize())
}
void test_function_is_of_right_type() {
SmoothMD alg;
alg.initialize();
TSM_ASSERT_THROWS("Function can only be of known types for SmoothMD", alg.setProperty("Function", "magic_function"), std::invalid_argument&);
}
void test_reject_negative_width_vector_entry()
{
SmoothMD alg;
alg.initialize();
TSM_ASSERT_THROWS("N-pixels contains zero", alg.setProperty("WidthVector", std::vector<int>(1, 0)), std::invalid_argument&);
}
void test_mandatory_width_vector_entry()
{
SmoothMD alg;
alg.initialize();
TSM_ASSERT_THROWS("Empty WidthVector", alg.setProperty("WidthVector", std::vector<int>()), std::invalid_argument&);
}
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
void test_simple_smooth_hat_function()
{
auto toSmooth = MDEventsTestHelper::makeFakeMDHistoWorkspace(1 /*signal*/, 2 /*numDims*/, 3 /*numBins in each dimension*/);
/*
2D MDHistoWorkspace Input
1 - 1 - 1
1 - 1 - 1
1 - 1 - 1
*/
SmoothMD alg;
alg.setChild(true);
alg.initialize();
std::vector<int> widthVector(1, 3);
alg.setProperty("WidthVector", widthVector);
alg.setProperty("InputWorkspace", toSmooth);
alg.setPropertyValue("OutputWorkspace", "dummy");
alg.execute();
IMDHistoWorkspace_sptr out = alg.getProperty("OutputWorkspace");
/*
2D MDHistoWorkspace Expected
1 - 1 - 1
1 - 1 - 1
1 - 1 - 1
*/
for(size_t i = 0; i < out->getNPoints(); ++i)
{
TS_ASSERT_EQUALS(1, out->getSignalAt(i));
TS_ASSERT_EQUALS(1, out->getErrorAt(i));
}
}
void test_smooth_hat_function()
{
auto toSmooth = MDEventsTestHelper::makeFakeMDHistoWorkspace(1 /*signal*/, 2 /*numDims*/, 3 /*numBins in each dimension*/);
toSmooth->setSignalAt(4, 2.0);
/*
2D MDHistoWorkspace Input
1 - 1 - 1
1 - 2 - 1
1 - 1 - 1
*/
SmoothMD alg;
alg.setChild(true);
alg.initialize();
alg.setProperty("WidthVector", widthVector);
alg.setProperty("InputWorkspace", toSmooth);
alg.setPropertyValue("OutputWorkspace", "dummy");
alg.execute();
IMDHistoWorkspace_sptr out = alg.getProperty("OutputWorkspace");
/*
2D MDHistoWorkspace Expected
5/4 - 7/6 - 5/4
7/6 - 10/9 - 7/6
5/4 - 7/6 - 5/4
*/
TS_ASSERT_EQUALS(5.0/4, out->getSignalAt(0));
TS_ASSERT_EQUALS(7.0/6, out->getSignalAt(1));
TS_ASSERT_EQUALS(10.0/9, out->getSignalAt(4));
}
};
#endif /* MANTID_MDALGORITHMS_SMOOTHMDTEST_H_ */