forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CountsTest.h
103 lines (88 loc) · 3.64 KB
/
CountsTest.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
94
95
96
97
98
99
100
101
102
103
// 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/BinEdges.h"
#include "MantidHistogramData/Counts.h"
#include "MantidHistogramData/Frequencies.h"
using namespace Mantid;
using namespace HistogramData;
class CountsTest : 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 CountsTest *createSuite() { return new CountsTest(); }
static void destroySuite(CountsTest *suite) { delete suite; }
void test_has_correct_mixins() {
Counts data;
TS_ASSERT_THROWS_NOTHING(UNUSED_ARG((dynamic_cast<detail::VectorOf<Counts, HistogramY> &>(data))));
TS_ASSERT_THROWS_NOTHING(UNUSED_ARG(dynamic_cast<detail::Addable<Counts> &>(data)));
TS_ASSERT_THROWS_NOTHING(UNUSED_ARG(dynamic_cast<detail::Iterable<Counts> &>(data)));
TS_ASSERT_THROWS_NOTHING(UNUSED_ARG(dynamic_cast<detail::Offsetable<Counts> &>(data)));
TS_ASSERT_THROWS_NOTHING(UNUSED_ARG(dynamic_cast<detail::Scalable<Counts> &>(data)));
}
void test_construct_default() {
const Counts counts{};
TS_ASSERT(!counts);
}
void test_construct_from_null_Frequencies() {
const Frequencies frequencies{};
const BinEdges edges{};
const Counts counts(frequencies, edges);
TS_ASSERT(!counts);
}
void test_construct_from_empty_Frequencies() {
const Frequencies frequencies(0);
const BinEdges edges{0};
const Counts counts(frequencies, edges);
TS_ASSERT_EQUALS(counts.size(), 0);
}
void test_construct_from_empty_Frequencies_null_BinEdges() {
const Frequencies frequencies(0);
const BinEdges edges{};
TS_ASSERT_THROWS(const Counts counts(frequencies, edges), const std::logic_error &);
}
void test_construct_from_empty_Frequencies_size_mismatch() {
const Frequencies frequencies(0);
const BinEdges edges{1.0, 2.0};
TS_ASSERT_THROWS(const Counts counts(frequencies, edges), const std::logic_error &);
}
void test_construct_from_Frequencies_null_BinEdges() {
const Frequencies frequencies(1);
const BinEdges edges{};
TS_ASSERT_THROWS(const Counts counts(frequencies, edges), const std::logic_error &);
}
void test_construct_from_Frequencies_size_mismatch() {
const Frequencies frequencies(2);
const BinEdges edges{1.0, 2.0};
TS_ASSERT_THROWS(const Counts counts(frequencies, edges), const std::logic_error &);
}
void test_construct_from_Frequencies() {
const Frequencies frequencies{1.0, 2.0};
const BinEdges edges{0.1, 0.2, 0.4};
const Counts counts(frequencies, edges);
TS_ASSERT_EQUALS(counts.size(), 2);
TS_ASSERT_DELTA(counts[0], 0.1, 1e-14);
TS_ASSERT_DELTA(counts[1], 0.4, 1e-14);
}
void test_move_construct_from_Frequencies() {
Frequencies frequencies(1);
const BinEdges edges{1.0, 2.0};
auto old_ptr = &frequencies[0];
const Counts counts(std::move(frequencies), edges);
TS_ASSERT_EQUALS(&counts[0], old_ptr);
}
void test_move_construct_from_Frequencies_and_cow() {
Frequencies frequencies(1);
const Frequencies copy(frequencies);
const BinEdges edges{1.0, 2.0};
auto old_ptr = &frequencies[0];
const Counts counts(std::move(frequencies), edges);
// ... but made a copy of data, since "copy" also held a reference.
TS_ASSERT_DIFFERS(&counts[0], old_ptr);
}
};