forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
OffsetableTest.h
85 lines (74 loc) · 2.88 KB
/
OffsetableTest.h
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
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once
#include <cxxtest/TestSuite.h>
#include "MantidHistogramData/FixedLengthVector.h"
#include "MantidHistogramData/HistogramX.h"
#include "MantidHistogramData/Iterable.h"
#include "MantidHistogramData/Offsetable.h"
#include "MantidHistogramData/VectorOf.h"
using Mantid::HistogramData::HistogramX;
using Mantid::HistogramData::detail::FixedLengthVector;
using Mantid::HistogramData::detail::Iterable;
using Mantid::HistogramData::detail::Offsetable;
using Mantid::HistogramData::detail::VectorOf;
class OffsetableTester : public VectorOf<OffsetableTester, HistogramX>,
public Iterable<OffsetableTester>,
public Offsetable<OffsetableTester> {
using VectorOf<OffsetableTester, HistogramX>::VectorOf;
};
// Does Offsetable also work with FixedLengthVector instead of VectorOf?
struct OffsetableTester2 : public FixedLengthVector<OffsetableTester2>, public Offsetable<OffsetableTester2> {
using FixedLengthVector<OffsetableTester2>::FixedLengthVector;
};
class OffsetableTest : 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 OffsetableTest *createSuite() { return new OffsetableTest(); }
static void destroySuite(OffsetableTest *suite) { delete suite; }
void test_plus_equals() {
OffsetableTester lhs{0.1, 0.2};
const double rhs = 0.01;
lhs += rhs;
TS_ASSERT_EQUALS(lhs.size(), 2);
TS_ASSERT_DELTA(lhs[0], 0.11, 1e-14);
TS_ASSERT_DELTA(lhs[1], 0.21, 1e-14);
}
void test_minus_equals() {
OffsetableTester lhs{0.1, 0.2};
const double rhs = 0.01;
lhs -= rhs;
TS_ASSERT_EQUALS(lhs.size(), 2);
TS_ASSERT_DELTA(lhs[0], 0.09, 1e-14);
TS_ASSERT_DELTA(lhs[1], 0.19, 1e-14);
}
void test_plus() {
const OffsetableTester rhs1{0.1, 0.2};
const double rhs2 = 0.01;
const OffsetableTester lhs(rhs1 + rhs2);
TS_ASSERT_EQUALS(lhs.size(), 2);
TS_ASSERT_DELTA(lhs[0], 0.11, 1e-14);
TS_ASSERT_DELTA(lhs[1], 0.21, 1e-14);
}
void test_minus() {
const OffsetableTester rhs1{0.1, 0.2};
const double rhs2 = 0.01;
const OffsetableTester lhs(rhs1 - rhs2);
TS_ASSERT_EQUALS(lhs.size(), 2);
TS_ASSERT_DELTA(lhs[0], 0.09, 1e-14);
TS_ASSERT_DELTA(lhs[1], 0.19, 1e-14);
}
void test_with_FixedLengthVector() {
OffsetableTester2 lhs{0.1, 0.2};
const double rhs = 0.01;
lhs += rhs;
TS_ASSERT_EQUALS(lhs.size(), 2);
TS_ASSERT_DELTA(lhs[0], 0.11, 1e-14);
TS_ASSERT_DELTA(lhs[1], 0.21, 1e-14);
}
};