forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
VarianceVectorOfTest.h
88 lines (76 loc) · 3.09 KB
/
VarianceVectorOfTest.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
// 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/VarianceVectorOf.h"
using Mantid::HistogramData::HistogramX;
using Mantid::HistogramData::detail::Iterable;
using Mantid::HistogramData::detail::VarianceVectorOf;
using Mantid::HistogramData::detail::VectorOf;
class SigmasTester : public VectorOf<SigmasTester, HistogramX>, public Iterable<SigmasTester> {
public:
using VectorOf<SigmasTester, HistogramX>::VectorOf;
using VectorOf<SigmasTester, HistogramX>::operator=;
};
class VarianceVectorOfTester : public VarianceVectorOf<VarianceVectorOfTester, HistogramX, SigmasTester> {
public:
using VarianceVectorOf<VarianceVectorOfTester, HistogramX, SigmasTester>::VarianceVectorOf;
using VarianceVectorOf<VarianceVectorOfTester, HistogramX, SigmasTester>::operator=;
VarianceVectorOfTester(const VarianceVectorOfTester &) = default;
VarianceVectorOfTester &operator=(const VarianceVectorOfTester &) = default;
};
class VarianceVectorOfTest : 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 VarianceVectorOfTest *createSuite() { return new VarianceVectorOfTest(); }
static void destroySuite(VarianceVectorOfTest *suite) { delete suite; }
void test_copy_construct() {
VarianceVectorOfTester other{1.0, 2.0};
VarianceVectorOfTester variances(other);
TS_ASSERT_EQUALS(variances[0], 1.0);
TS_ASSERT_EQUALS(variances[1], 2.0);
}
void test_assign() {
VarianceVectorOfTester other{1.0, 2.0};
VarianceVectorOfTester variances{};
variances = other;
TS_ASSERT_EQUALS(variances[0], 1.0);
TS_ASSERT_EQUALS(variances[1], 2.0);
}
void test_construct_from_Sigmas() {
const SigmasTester sigmas{1.0, 2.0};
VarianceVectorOfTester variances(sigmas);
TS_ASSERT_EQUALS(variances[0], 1.0);
TS_ASSERT_EQUALS(variances[1], 4.0);
}
void test_move_construct_from_Sigmas() {
SigmasTester sigmas{1.0, 2.0};
auto old_ptr = &sigmas[0];
VarianceVectorOfTester variances(std::move(sigmas));
TS_ASSERT_EQUALS(&variances[0], old_ptr);
TS_ASSERT_EQUALS(variances[0], 1.0);
TS_ASSERT_EQUALS(variances[1], 4.0);
}
void test_assign_Sigmas() {
const SigmasTester sigmas{1.0, 2.0};
VarianceVectorOfTester variances{};
variances = sigmas;
TS_ASSERT_EQUALS(variances[0], 1.0);
TS_ASSERT_EQUALS(variances[1], 4.0);
}
void test_move_assign_Sigmas() {
SigmasTester sigmas{1.0, 2.0};
auto old_ptr = &sigmas[0];
VarianceVectorOfTester variances{};
variances = std::move(sigmas);
TS_ASSERT_EQUALS(&variances[0], old_ptr);
TS_ASSERT_EQUALS(variances[0], 1.0);
TS_ASSERT_EQUALS(variances[1], 4.0);
}
};