forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FrequenciesTest.h
103 lines (88 loc) · 3.61 KB
/
FrequenciesTest.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 FrequenciesTest : 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 FrequenciesTest *createSuite() { return new FrequenciesTest(); }
static void destroySuite(FrequenciesTest *suite) { delete suite; }
void test_has_correct_mixins() {
Frequencies data;
TS_ASSERT_THROWS_NOTHING(UNUSED_ARG((dynamic_cast<detail::VectorOf<Frequencies, HistogramY> &>(data))));
TS_ASSERT_THROWS_NOTHING(UNUSED_ARG(dynamic_cast<detail::Addable<Frequencies> &>(data)));
TS_ASSERT_THROWS_NOTHING(UNUSED_ARG(dynamic_cast<detail::Iterable<Frequencies> &>(data)));
TS_ASSERT_THROWS_NOTHING(UNUSED_ARG(dynamic_cast<detail::Offsetable<Frequencies> &>(data)));
TS_ASSERT_THROWS_NOTHING(UNUSED_ARG(dynamic_cast<detail::Scalable<Frequencies> &>(data)));
}
void test_construct_default() {
const Counts counts{};
TS_ASSERT(!counts);
}
void test_construct_from_null_Counts() {
const Counts counts{};
const BinEdges edges{};
const Frequencies frequencies(counts, edges);
TS_ASSERT(!counts);
}
void test_construct_from_empty_Counts() {
const Counts counts(0);
const BinEdges edges{0};
const Frequencies frequencies(counts, edges);
TS_ASSERT_EQUALS(counts.size(), 0);
}
void test_construct_from_empty_Counts_null_BinEdges() {
const Counts counts(0);
const BinEdges edges{};
TS_ASSERT_THROWS(const Frequencies frequencies(counts, edges), const std::logic_error &);
}
void test_construct_from_empty_Counts_size_mismatch() {
const Counts counts(0);
const BinEdges edges{1.0, 2.0};
TS_ASSERT_THROWS(const Frequencies frequencies(counts, edges), const std::logic_error &);
}
void test_construct_from_Counts_null_BinEdges() {
const Counts counts(1);
const BinEdges edges{};
TS_ASSERT_THROWS(const Frequencies frequencies(counts, edges), const std::logic_error &);
}
void test_construct_from_Counts_size_mismatch() {
const Counts counts(2);
const BinEdges edges{1.0, 2.0};
TS_ASSERT_THROWS(const Frequencies frequencies(counts, edges), const std::logic_error &);
}
void test_construct_from_Counts() {
const Counts counts{1.0, 2.0};
const BinEdges edges{0.1, 0.2, 0.4};
const Frequencies frequencies(counts, edges);
TS_ASSERT_EQUALS(frequencies.size(), 2);
TS_ASSERT_DELTA(frequencies[0], 10.0, 1e-14);
TS_ASSERT_DELTA(frequencies[1], 10.0, 1e-14);
}
void test_move_construct_from_Counts() {
Counts counts(1);
const BinEdges edges{1.0, 2.0};
auto old_ptr = &counts[0];
const Frequencies frequencies(std::move(counts), edges);
TS_ASSERT_EQUALS(&frequencies[0], old_ptr);
}
void test_move_construct_from_Counts_and_cow() {
Counts counts(1);
const Counts copy(counts);
const BinEdges edges{1.0, 2.0};
auto old_ptr = &counts[0];
const Frequencies frequencies(std::move(counts), edges);
// ... but made a copy of data, since "copy" also held a reference.
TS_ASSERT_DIFFERS(&frequencies[0], old_ptr);
}
};