forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
StandardDeviationVectorOfTest.h
90 lines (78 loc) · 3.38 KB
/
StandardDeviationVectorOfTest.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
// 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/HistogramX.h"
#include "MantidHistogramData/StandardDeviationVectorOf.h"
using Mantid::HistogramData::HistogramX;
using Mantid::HistogramData::detail::Iterable;
using Mantid::HistogramData::detail::StandardDeviationVectorOf;
using Mantid::HistogramData::detail::VectorOf;
class VariancesTester : public VectorOf<VariancesTester, HistogramX>, public Iterable<VariancesTester> {
public:
using VectorOf<VariancesTester, HistogramX>::VectorOf;
using VectorOf<VariancesTester, HistogramX>::operator=;
};
class StandardDeviationVectorOfTester
: public StandardDeviationVectorOf<StandardDeviationVectorOfTester, HistogramX, VariancesTester> {
public:
using StandardDeviationVectorOf<StandardDeviationVectorOfTester, HistogramX,
VariancesTester>::StandardDeviationVectorOf;
using StandardDeviationVectorOf<StandardDeviationVectorOfTester, HistogramX, VariancesTester>::operator=;
StandardDeviationVectorOfTester(const StandardDeviationVectorOfTester &) = default;
StandardDeviationVectorOfTester &operator=(const StandardDeviationVectorOfTester &) = default;
};
class StandardDeviationVectorOfTest : 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 StandardDeviationVectorOfTest *createSuite() { return new StandardDeviationVectorOfTest(); }
static void destroySuite(StandardDeviationVectorOfTest *suite) { delete suite; }
void test_copy_construct() {
StandardDeviationVectorOfTester other{1.0, 2.0};
StandardDeviationVectorOfTester variances(other);
TS_ASSERT_EQUALS(variances[0], 1.0);
TS_ASSERT_EQUALS(variances[1], 2.0);
}
void test_assign() {
StandardDeviationVectorOfTester other{1.0, 2.0};
StandardDeviationVectorOfTester variances{};
variances = other;
TS_ASSERT_EQUALS(variances[0], 1.0);
TS_ASSERT_EQUALS(variances[1], 2.0);
}
void test_construct_from_Variances() {
const VariancesTester variances{1.0, 4.0};
StandardDeviationVectorOfTester sigmas(variances);
TS_ASSERT_EQUALS(sigmas[0], 1.0);
TS_ASSERT_EQUALS(sigmas[1], 2.0);
}
void test_move_construct_from_Variances() {
VariancesTester variances{1.0, 4.0};
auto old_ptr = &variances[0];
StandardDeviationVectorOfTester sigmas(std::move(variances));
TS_ASSERT_EQUALS(&sigmas[0], old_ptr);
TS_ASSERT_EQUALS(sigmas[0], 1.0);
TS_ASSERT_EQUALS(sigmas[1], 2.0);
}
void test_assign_Variances() {
const VariancesTester variances{1.0, 4.0};
StandardDeviationVectorOfTester sigmas{};
sigmas = variances;
TS_ASSERT_EQUALS(sigmas[0], 1.0);
TS_ASSERT_EQUALS(sigmas[1], 2.0);
}
void test_move_assign_Variances() {
VariancesTester variances{1.0, 4.0};
auto old_ptr = &variances[0];
StandardDeviationVectorOfTester sigmas{};
sigmas = std::move(variances);
TS_ASSERT_EQUALS(&sigmas[0], old_ptr);
TS_ASSERT_EQUALS(sigmas[0], 1.0);
TS_ASSERT_EQUALS(sigmas[1], 2.0);
}
};