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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef MANTID_ALGORITHMS_INTERPOLATIONOPTIONTEST_H_
#define MANTID_ALGORITHMS_INTERPOLATIONOPTIONTEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidAlgorithms/InterpolationOption.h"
#include "MantidHistogramData/Histogram.h"
#include "MantidHistogramData/Points.h"
#include "MantidHistogramData/LinearGenerator.h"
#include "MantidKernel/PropertyWithValue.h"
#include "MantidTestHelpers/HistogramDataTestHelper.h"
using Mantid::Algorithms::InterpolationOption;
using namespace Mantid::HistogramData;
class InterpolationOptionTest : 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 InterpolationOptionTest *createSuite() {
return new InterpolationOptionTest();
}
static void destroySuite(InterpolationOptionTest *suite) { delete suite; }
//----------------------------------------------------------------------------
// Success tests
//----------------------------------------------------------------------------
void test_Property_Defaults_To_Linear_Interpolation() {
InterpolationOption interpolateOpt;
auto prop = interpolateOpt.property();
TS_ASSERT(prop);
TS_ASSERT_EQUALS("Interpolation", prop->name());
TS_ASSERT_EQUALS("Linear", prop->getDefault());
}
void test_Documentation_Is_Not_Empty() {
InterpolationOption interpolateOpt;
TS_ASSERT(!interpolateOpt.propertyDoc().empty())
}
void test_Apply_With_Linear_Succeeds() {
using namespace Mantid::HistogramData;
InterpolationOption interpolateOpt;
Histogram inOut(Points(7, LinearGenerator(0, 0.5)),
Counts({-3, 0, -4, 0, 4, 0, 3}));
Histogram input(inOut);
interpolateOpt.applyInplace(inOut, 2);
const std::vector<double> expectedY = {-3, -3.5, -4, 0, 4, 3.5, 3};
checkData(input, inOut, expectedY);
}
void test_Apply_With_CSpline_Succeeds() {
InterpolationOption interpolateOptEnum;
// Set by enum
interpolateOptEnum.set(InterpolationOption::Value::CSpline);
Histogram inOut(Points(7, LinearGenerator(0, 0.5)),
Counts({-3, 0, -4, 0, 4, 0, 3}));
const Histogram input(inOut);
interpolateOptEnum.applyInplace(inOut, 2);
const std::vector<double> expectedY = {-3, -4.625, -4, 0., 4, 4.625, 3};
checkData(input, inOut, expectedY);
// Set by string
InterpolationOption interpolateOptStr;
interpolateOptStr.set("CSpline");
Histogram inOutStr(input);
interpolateOptStr.applyInplace(inOutStr, 2);
checkData(input, inOutStr, expectedY);
}
//----------------------------------------------------------------------------
// Failure tests
//----------------------------------------------------------------------------
void test_set_From_String_Throws_With_Unknown_Type() {
InterpolationOption interpolateOpt;
TS_ASSERT_THROWS(interpolateOpt.set("Unknown"), std::invalid_argument);
}
void test_set_From_String_Throws_With_Empty_String() {
InterpolationOption interpolateOpt;
TS_ASSERT_THROWS(interpolateOpt.set(""), std::invalid_argument);
}
private:
void checkData(const Histogram &input, const Histogram &output,
const std::vector<double> &expectedY) {
TS_ASSERT_EQUALS(input.x(), output.x());
TS_ASSERT_EQUALS(input.xMode(), output.xMode());
TS_ASSERT_EQUALS(input.yMode(), output.yMode());
const auto &outY = output.y();
for (size_t i = 0; i < expectedY.size(); ++i) {
TS_ASSERT_DELTA(expectedY[i], outY[i], 1e-14);
}
}
};
#endif /* MANTID_ALGORITHMS_INTERPOLATIONOPTIONTEST_H_ */