forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeightedEventTest.h
72 lines (62 loc) · 2.1 KB
/
WeightedEventTest.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
// 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/Events.h"
#include "MantidKernel/Timer.h"
#include <cmath>
#include <cxxtest/TestSuite.h>
using namespace Mantid;
using namespace Mantid::Kernel;
using namespace Mantid::DataObjects;
using Mantid::Types::Event::TofEvent;
using std::runtime_error;
using std::size_t;
using std::vector;
//==========================================================================================
class WeightedEventTest : public CxxTest::TestSuite {
public:
void testConstructors() {
TofEvent e(123, 456);
WeightedEvent we, we2;
// Empty
we = WeightedEvent();
TS_ASSERT_EQUALS(we.tof(), 0);
TS_ASSERT_EQUALS(we.pulseTime(), 0);
TS_ASSERT_EQUALS(we.weight(), 1.0);
TS_ASSERT_EQUALS(we.error(), 1.0);
// Default one weight
we = WeightedEvent(e);
TS_ASSERT_EQUALS(we.tof(), 123);
TS_ASSERT_EQUALS(we.pulseTime(), 456);
TS_ASSERT_EQUALS(we.weight(), 1.0);
TS_ASSERT_EQUALS(we.error(), 1.0);
// TofEvent + weights
we = WeightedEvent(e, 3.5, 0.5 * 0.5);
TS_ASSERT_EQUALS(we.tof(), 123);
TS_ASSERT_EQUALS(we.pulseTime(), 456);
TS_ASSERT_EQUALS(we.weight(), 3.5);
TS_ASSERT_EQUALS(we.error(), 0.5);
// Full constructor
we = WeightedEvent(456, 789, 2.5, 1.5 * 1.5);
TS_ASSERT_EQUALS(we.tof(), 456);
TS_ASSERT_EQUALS(we.pulseTime(), 789);
TS_ASSERT_EQUALS(we.weight(), 2.5);
TS_ASSERT_EQUALS(we.error(), 1.5);
}
void testAssignAndCopy() {
WeightedEvent we, we2;
// Copy constructor
we = WeightedEvent();
we2 = WeightedEvent(456, 789, 2.5, 1.5 * 1.5);
// cppcheck-suppress redundantAssignment
we = we2;
TS_ASSERT_EQUALS(we.tof(), 456);
TS_ASSERT_EQUALS(we.pulseTime(), 789);
TS_ASSERT_EQUALS(we.weight(), 2.5);
TS_ASSERT_EQUALS(we.error(), 1.5);
}
};