forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FilteredTimeSeriesPropertyTest.h
99 lines (82 loc) · 4.02 KB
/
FilteredTimeSeriesPropertyTest.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
// 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 "MantidKernel/FilteredTimeSeriesProperty.h"
#include <cxxtest/TestSuite.h>
using Mantid::Kernel::FilteredTimeSeriesProperty;
class FilteredTimeSeriesPropertyTest : 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 FilteredTimeSeriesPropertyTest *createSuite() { return new FilteredTimeSeriesPropertyTest(); }
static void destroySuite(FilteredTimeSeriesPropertyTest *suite) { delete suite; }
void test_FilteredProperty_Has_Same_Name_As_Original() {
using Mantid::Kernel::TimeSeriesProperty;
const std::string name = "seriesName";
auto source = createTestSeries(name);
auto filter = createTestFilter();
auto filtered = std::make_unique<FilteredTimeSeriesProperty<double>>(std::move(source), filter);
TS_ASSERT_EQUALS(filtered->name(), name);
}
void test_Transferring_Ownership_Makes_Unfiltered_Property_Return_The_Original() {
constexpr bool transferOwnership(true);
doOwnershipTest(transferOwnership);
}
void test_Retaining_Ownership_With_Caller_Makes_Unfiltered_Property_A_Clone() {
constexpr bool transferOwnership(false);
doOwnershipTest(transferOwnership);
}
void test_Construction_Yields_A_Filtered_Property_When_Accessing_Through_The_Filtered_Object() {
auto source = createTestSeries("name");
auto filter = createTestFilter();
auto filtered = std::make_unique<FilteredTimeSeriesProperty<double>>(std::move(source), filter);
TS_ASSERT_EQUALS(filtered->size(), 2);
TS_ASSERT_EQUALS(filtered->nthInterval(0).begin_str(), "2007-Nov-30 16:17:25");
TS_ASSERT_EQUALS(filtered->nthInterval(0).end_str(), "2007-Nov-30 16:17:30");
TS_ASSERT_EQUALS(filtered->nthValue(0), 3);
TS_ASSERT_EQUALS(filtered->nthInterval(1).begin_str(), "2007-Nov-30 16:17:30");
TS_ASSERT_EQUALS(filtered->nthInterval(1).end_str(), "2007-Nov-30 16:17:39");
TS_ASSERT_EQUALS(filtered->nthValue(1), 4);
}
private:
void doOwnershipTest(const bool transferOwnership) {
auto source = createTestSeries("name");
auto filter = createTestFilter();
std::unique_ptr<FilteredTimeSeriesProperty<double>> filtered = nullptr;
// Pointer comparison
if (transferOwnership) {
auto copy = std::unique_ptr<Mantid::Kernel::TimeSeriesProperty<double>>(source->clone());
TS_ASSERT_THROWS_NOTHING(filtered =
std::make_unique<FilteredTimeSeriesProperty<double>>(std::move(source), filter));
source = std::move(copy);
} else {
TS_ASSERT_THROWS_NOTHING(filtered = std::make_unique<FilteredTimeSeriesProperty<double>>(source.get(), filter));
TS_ASSERT_DIFFERS(source.get(), filtered->unfiltered());
}
// Object equality
TS_ASSERT_EQUALS(*source,
*(filtered->unfiltered())); // Objects are considered equal
}
/// Create the test source property
std::unique_ptr<Mantid::Kernel::TimeSeriesProperty<double>> createTestSeries(const std::string &name) {
auto source = std::make_unique<Mantid::Kernel::TimeSeriesProperty<double>>(name);
source->addValue("2007-11-30T16:17:00", 1);
source->addValue("2007-11-30T16:17:10", 2);
source->addValue("2007-11-30T16:17:20", 3);
source->addValue("2007-11-30T16:17:30", 4);
source->addValue("2007-11-30T16:17:40", 5);
return source;
}
/// Create test filter
Mantid::Kernel::TimeSeriesProperty<bool> createTestFilter() {
auto filter = Mantid::Kernel::TimeSeriesProperty<bool>("filter");
filter.addValue("2007-11-30T16:16:50", false);
filter.addValue("2007-11-30T16:17:25", true);
filter.addValue("2007-11-30T16:17:39", false);
return filter;
}
};