forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeightedEventNoTimeTest.h
84 lines (71 loc) · 2.54 KB
/
WeightedEventNoTimeTest.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
// 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 WeightedEventNoTimeTest : public CxxTest::TestSuite {
public:
void testConstructors() {
TofEvent e(123, 456);
WeightedEvent we;
WeightedEventNoTime wen, wen2;
// Empty
wen = WeightedEventNoTime();
TS_ASSERT_EQUALS(wen.tof(), 0);
TS_ASSERT_EQUALS(wen.pulseTime(), 0);
TS_ASSERT_EQUALS(wen.weight(), 1.0);
TS_ASSERT_EQUALS(wen.error(), 1.0);
// From WeightedEvent
we = WeightedEvent(456, 789, 2.5, 1.5 * 1.5);
wen = WeightedEventNoTime(we);
TS_ASSERT_EQUALS(wen.tof(), 456);
TS_ASSERT_EQUALS(wen.pulseTime(), 0); // Lost the time!
TS_ASSERT_EQUALS(wen.weight(), 2.5);
TS_ASSERT_EQUALS(wen.error(), 1.5);
// Default one weight from TofEvent
wen = WeightedEventNoTime(e);
TS_ASSERT_EQUALS(wen.tof(), 123);
TS_ASSERT_EQUALS(wen.pulseTime(), 0);
TS_ASSERT_EQUALS(wen.weight(), 1.0);
TS_ASSERT_EQUALS(wen.error(), 1.0);
// TofEvent + weights
wen = WeightedEventNoTime(e, 3.5, 0.5 * 0.5);
TS_ASSERT_EQUALS(wen.tof(), 123);
TS_ASSERT_EQUALS(wen.pulseTime(), 0);
TS_ASSERT_EQUALS(wen.weight(), 3.5);
TS_ASSERT_EQUALS(wen.error(), 0.5);
// Full constructor
wen = WeightedEventNoTime(456, 2.5, 1.5 * 1.5);
TS_ASSERT_EQUALS(wen.tof(), 456);
TS_ASSERT_EQUALS(wen.pulseTime(), 0); // Never had time
TS_ASSERT_EQUALS(wen.weight(), 2.5);
TS_ASSERT_EQUALS(wen.error(), 1.5);
}
void testAssignAndCopy_AndEquality() {
WeightedEventNoTime wen, wen2;
// Copy constructor
wen = WeightedEventNoTime();
wen2 = WeightedEventNoTime(456, 2.5, 1.5 * 1.5);
TS_ASSERT(!(wen == wen2));
wen = wen2;
TS_ASSERT_EQUALS(wen.tof(), 456);
TS_ASSERT_EQUALS(wen.pulseTime(), 0); // Never had time
TS_ASSERT_EQUALS(wen.weight(), 2.5);
TS_ASSERT_EQUALS(wen.error(), 1.5);
TS_ASSERT(wen == wen2);
}
};