forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ScalableTest.h
93 lines (81 loc) · 3.05 KB
/
ScalableTest.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
86
87
88
89
90
91
92
93
// 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/Scalable.h"
#include "MantidHistogramData/VectorOf.h"
using Mantid::HistogramData::HistogramX;
using Mantid::HistogramData::detail::FixedLengthVector;
using Mantid::HistogramData::detail::Iterable;
using Mantid::HistogramData::detail::Scalable;
using Mantid::HistogramData::detail::VectorOf;
class ScalableTester : public VectorOf<ScalableTester, HistogramX>,
public Iterable<ScalableTester>,
public Scalable<ScalableTester> {
using VectorOf<ScalableTester, HistogramX>::VectorOf;
};
// Does Scalable also work with FixedLengthVector instead of VectorOf?
struct ScalableTester2 : public FixedLengthVector<ScalableTester2>, public Scalable<ScalableTester2> {
using FixedLengthVector<ScalableTester2>::FixedLengthVector;
};
class ScalableTest : 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 ScalableTest *createSuite() { return new ScalableTest(); }
static void destroySuite(ScalableTest *suite) { delete suite; }
void test_times_equals() {
ScalableTester lhs{0.1, 0.2};
const double rhs = 3.0;
lhs *= rhs;
TS_ASSERT_EQUALS(lhs.size(), 2);
TS_ASSERT_DELTA(lhs[0], 0.3, 1e-14);
TS_ASSERT_DELTA(lhs[1], 0.6, 1e-14);
}
void test_divide_equals() {
ScalableTester lhs{0.1, 0.2};
const double rhs = 2.0;
lhs /= rhs;
TS_ASSERT_EQUALS(lhs.size(), 2);
TS_ASSERT_DELTA(lhs[0], 0.05, 1e-14);
TS_ASSERT_DELTA(lhs[1], 0.1, 1e-14);
}
void test_times() {
const ScalableTester rhs1{0.1, 0.2};
const double rhs2 = 3.0;
const ScalableTester lhs(rhs1 * rhs2);
TS_ASSERT_EQUALS(lhs.size(), 2);
TS_ASSERT_DELTA(lhs[0], 0.3, 1e-14);
TS_ASSERT_DELTA(lhs[1], 0.6, 1e-14);
}
void test_divide() {
const ScalableTester rhs1{0.1, 0.2};
const double rhs2 = 2.0;
const ScalableTester lhs(rhs1 / rhs2);
TS_ASSERT_EQUALS(lhs.size(), 2);
TS_ASSERT_DELTA(lhs[0], 0.05, 1e-14);
TS_ASSERT_DELTA(lhs[1], 0.1, 1e-14);
}
void test_times_reverse_order() {
const ScalableTester rhs{0.1, 0.2};
const ScalableTester lhs(3.0 * rhs);
TS_ASSERT_EQUALS(lhs.size(), 2);
TS_ASSERT_DELTA(lhs[0], 0.3, 1e-14);
TS_ASSERT_DELTA(lhs[1], 0.6, 1e-14);
}
void test_with_FixedLengthVector() {
ScalableTester2 lhs{0.1, 0.2};
const double rhs = 3.0;
lhs *= rhs;
TS_ASSERT_EQUALS(lhs.size(), 2);
TS_ASSERT_DELTA(lhs[0], 0.3, 1e-14);
TS_ASSERT_DELTA(lhs[1], 0.6, 1e-14);
}
};