forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MDLeanEventTest.h
162 lines (134 loc) · 4.85 KB
/
MDLeanEventTest.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// 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 "MantidDataObjects/MDLeanEvent.h"
#include "MantidDataObjects/MortonIndex/WideInt.h"
#include "MantidKernel/System.h"
#include "MantidKernel/Timer.h"
#include <cxxtest/TestSuite.h>
#include <boost/scoped_array.hpp>
using namespace Mantid;
using namespace Mantid::DataObjects;
class MDLeanEventTest : public CxxTest::TestSuite {
public:
using EventAccessType = DataObjects::EventAccessor;
void test_Constructors() {
MDLeanEvent<3> a;
TS_ASSERT_EQUALS(a.getNumDims(), 3);
TS_ASSERT_EQUALS(a.getSignal(), 1.0);
TS_ASSERT_EQUALS(a.getErrorSquared(), 1.0);
MDLeanEvent<4> b(2.5, 1.5);
TS_ASSERT_EQUALS(b.getNumDims(), 4);
TS_ASSERT_EQUALS(b.getSignal(), 2.5);
TS_ASSERT_EQUALS(b.getErrorSquared(), 1.5);
TS_ASSERT_EQUALS(sizeof(a), sizeof(coord_t) * 3 + 8);
TS_ASSERT_EQUALS(sizeof(b), sizeof(coord_t) * 4 + 8);
}
void test_ConstructorsWithCoords() {
// Fixed-size array
coord_t coords[3] = {0.125, 1.25, 2.5};
MDLeanEvent<3> a(2.5, 1.5, coords);
TS_ASSERT_EQUALS(a.getSignal(), 2.5);
TS_ASSERT_EQUALS(a.getErrorSquared(), 1.5);
TS_ASSERT_EQUALS(a.getCenter(0), 0.125);
TS_ASSERT_EQUALS(a.getCenter(1), 1.25);
TS_ASSERT_EQUALS(a.getCenter(2), 2.5);
// Dynamic array
boost::scoped_array<coord_t> coords2(new coord_t[5]);
coords2[0] = 1.0;
coords2[1] = 2.0;
coords2[2] = 3.0;
MDLeanEvent<3> b(2.5, 1.5, coords2.get());
TS_ASSERT_EQUALS(b.getSignal(), 2.5);
TS_ASSERT_EQUALS(b.getErrorSquared(), 1.5);
TS_ASSERT_EQUALS(b.getCenter(0), 1);
TS_ASSERT_EQUALS(b.getCenter(1), 2);
TS_ASSERT_EQUALS(b.getCenter(2), 3);
}
void test_Coord() {
MDLeanEvent<3> a;
TS_ASSERT_EQUALS(a.getNumDims(), 3);
a.setCenter(0, 0.125);
TS_ASSERT_EQUALS(a.getCenter(0), 0.125);
a.setCenter(1, 1.25);
TS_ASSERT_EQUALS(a.getCenter(0), 0.125);
TS_ASSERT_EQUALS(a.getCenter(1), 1.25);
a.setCenter(2, 2.5);
TS_ASSERT_EQUALS(a.getCenter(0), 0.125);
TS_ASSERT_EQUALS(a.getCenter(1), 1.25);
TS_ASSERT_EQUALS(a.getCenter(2), 2.5);
TS_ASSERT_EQUALS(a.getCenter()[0], 0.125);
TS_ASSERT_EQUALS(a.getCenter()[1], 1.25);
TS_ASSERT_EQUALS(a.getCenter()[2], 2.5);
}
void test_setCenter_array() {
MDLeanEvent<3> a;
coord_t coords[3] = {0.125, 1.25, 2.5};
a.setCoords(coords);
TS_ASSERT_EQUALS(a.getCenter(0), 0.125);
TS_ASSERT_EQUALS(a.getCenter(1), 1.25);
TS_ASSERT_EQUALS(a.getCenter(2), 2.5);
}
/** Note: the copy constructor is not explicitely written but rather is filled
* in by the compiler */
void test_CopyConstructor() {
coord_t coords[3] = {0.125, 1.25, 2.5};
MDLeanEvent<3> b(2.5, 1.5, coords);
MDLeanEvent<3> a(b);
TS_ASSERT_EQUALS(a.getNumDims(), 3);
TS_ASSERT_EQUALS(a.getSignal(), 2.5);
TS_ASSERT_EQUALS(a.getErrorSquared(), 1.5);
TS_ASSERT_EQUALS(a.getCenter(0), 0.125);
TS_ASSERT_EQUALS(a.getCenter(1), 1.25);
TS_ASSERT_EQUALS(a.getCenter(2), 2.5);
}
void test_getError() {
MDLeanEvent<3> a(2.0, 4.0);
TS_ASSERT_EQUALS(a.getSignal(), 2.0);
TS_ASSERT_EQUALS(a.getError(), 2.0);
}
void test_retrieve_coordinates() {
constexpr size_t ND(4);
morton_index::MDSpaceBounds<ND> bounds;
// clang-format off
bounds <<
0.0f, 2.0f,
0.0f, 10.0f,
3.0f, 7.0f,
5.0f, 15.0f;
// clang-format on
morton_index::MDCoordinate<ND> floatCoord;
floatCoord << 1.5f, 10.0f, 5.0f, 5.0f;
MDLeanEvent<ND> event(0.0f, 0.0f, &floatCoord[0]);
using EventAccess = MDLeanEvent<ND>::template AccessFor<MDLeanEventTest>;
EventAccess::convertToIndex(event, bounds);
EventAccess::convertToCoordinates(event, bounds);
TS_ASSERT_EQUALS(event.getCenter(0), 1.5);
TS_ASSERT_EQUALS(event.getCenter(1), 10);
TS_ASSERT_EQUALS(event.getCenter(2), 5);
TS_ASSERT_EQUALS(event.getCenter(3), 5);
}
void test_retrieve_coordinates_3d() {
constexpr size_t ND(3);
morton_index::MDSpaceBounds<ND> bounds;
// clang-format off
bounds <<
0.0f, 2.0f,
0.0f, 10.0f,
3.0f, 7.0f;
// clang-format on
morton_index::MDCoordinate<ND> floatCoord;
floatCoord << 1.5f, 10.0f, 5.0f;
MDLeanEvent<ND> event(0.0f, 0.0f, &floatCoord[0]);
using EventAccess = MDLeanEvent<ND>::template AccessFor<MDLeanEventTest>;
EventAccess::convertToIndex(event, bounds);
EventAccess::convertToCoordinates(event, bounds);
TS_ASSERT_EQUALS(event.getCenter(0), 1.5);
TS_ASSERT_EQUALS(event.getCenter(1), 10);
TS_ASSERT_EQUALS(event.getCenter(2), 5);
}
};