forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpectrumDefinitionTest.h
106 lines (92 loc) · 3.29 KB
/
SpectrumDefinitionTest.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
104
105
106
// 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 "MantidTypes/SpectrumDefinition.h"
using Mantid::SpectrumDefinition;
class SpectrumDefinitionTest : 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 SpectrumDefinitionTest *createSuite() { return new SpectrumDefinitionTest(); }
static void destroySuite(SpectrumDefinitionTest *suite) { delete suite; }
void test_default_construct() {
SpectrumDefinition def;
TS_ASSERT_EQUALS(def.size(), 0);
}
void test_construct_no_time() {
SpectrumDefinition def(42);
TS_ASSERT_EQUALS(def.size(), 1);
TS_ASSERT_EQUALS(def[0], (std::pair<size_t, size_t>(42, 0)));
}
void test_construct() {
SpectrumDefinition def(42, 7);
TS_ASSERT_EQUALS(def.size(), 1);
TS_ASSERT_EQUALS(def[0], (std::pair<size_t, size_t>(42, 7)));
}
void test_size() {
SpectrumDefinition def;
TS_ASSERT_EQUALS(def.size(), 0);
}
void test_add() {
SpectrumDefinition def;
TS_ASSERT_EQUALS(def.size(), 0);
def.add(42);
TS_ASSERT_EQUALS(def.size(), 1);
TS_ASSERT_EQUALS(def[0], (std::pair<size_t, size_t>(42, 0)));
def.add(24);
TS_ASSERT_EQUALS(def.size(), 2);
TS_ASSERT_EQUALS(def[0], (std::pair<size_t, size_t>(24, 0)));
TS_ASSERT_EQUALS(def[1], (std::pair<size_t, size_t>(42, 0)));
}
void test_add_with_time_index() {
SpectrumDefinition def;
TS_ASSERT_EQUALS(def.size(), 0);
def.add(42, 1);
TS_ASSERT_EQUALS(def.size(), 1);
TS_ASSERT_EQUALS(def[0], (std::pair<size_t, size_t>(42, 1)));
def.add(24, 2);
TS_ASSERT_EQUALS(def.size(), 2);
TS_ASSERT_EQUALS(def[0], (std::pair<size_t, size_t>(24, 2)));
TS_ASSERT_EQUALS(def[1], (std::pair<size_t, size_t>(42, 1)));
}
void test_uniqueness() {
SpectrumDefinition def;
def.add(1);
def.add(1);
TS_ASSERT_EQUALS(def.size(), 1);
def.add(1, 1);
TS_ASSERT_EQUALS(def.size(), 2);
}
void test_elements_are_sorted() {
SpectrumDefinition def;
def.add(1, 1);
def.add(0, 1);
def.add(1);
def.add(2);
def.add(1);
TS_ASSERT_EQUALS(def[0], (std::pair<size_t, size_t>(0, 1)));
TS_ASSERT_EQUALS(def[1], (std::pair<size_t, size_t>(1, 0)));
TS_ASSERT_EQUALS(def[2], (std::pair<size_t, size_t>(1, 1)));
TS_ASSERT_EQUALS(def[3], (std::pair<size_t, size_t>(2, 0)));
}
void test_iterators_empty() {
SpectrumDefinition def;
TS_ASSERT_EQUALS(def.begin(), def.end());
TS_ASSERT_EQUALS(def.cbegin(), def.cend());
}
void test_iterators() {
SpectrumDefinition def;
def.add(1);
TS_ASSERT_DIFFERS(def.begin(), def.end());
TS_ASSERT_DIFFERS(def.cbegin(), def.cend());
TS_ASSERT_EQUALS(def.begin() + 1, def.end());
TS_ASSERT_EQUALS(def.cbegin() + 1, def.cend());
TS_ASSERT_EQUALS(*(def.begin()), (std::pair<size_t, size_t>(1, 0)));
TS_ASSERT_EQUALS(*(def.cbegin()), (std::pair<size_t, size_t>(1, 0)));
}
};