forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DateAndTimeHelpersTest.h
48 lines (39 loc) · 2.09 KB
/
DateAndTimeHelpersTest.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
// 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/DateAndTimeHelpers.h"
#include "MantidTypes/Core/DateAndTime.h"
#include <cxxtest/TestSuite.h>
using namespace Mantid::Kernel::DateAndTimeHelpers;
using Mantid::Types::Core::DateAndTime;
class DateAndTimeHelpersTest : 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 DateAndTimeHelpersTest *createSuite() { return new DateAndTimeHelpersTest(); }
static void destroySuite(DateAndTimeHelpersTest *suite) { delete suite; }
void test_verifyAndSanitizeISO8601() {
TS_ASSERT_EQUALS(verifyAndSanitizeISO8601("1990- 1- 2T03:04:02.000"), "1990-01-02T03:04:02.000");
TS_ASSERT_EQUALS(verifyAndSanitizeISO8601("1882-01- 2T03:04:02.000"), "1882-01-02T03:04:02.000");
}
void test_createFromSantizedISO8601() {
DateAndTime date;
TS_ASSERT_THROWS_NOTHING(date = createFromSanitizedISO8601("1882-01- 2T03:04:02"));
TS_ASSERT_EQUALS(date.toISO8601String(), "1882-01-02T03:04:02");
date = createFromSanitizedISO8601("1990- 1- 2T03:04:02.001");
TS_ASSERT_EQUALS(date.toISO8601String(), "1990-01-02T03:04:02.001000000");
}
void test_average() {
std::vector<DateAndTime> times;
TS_ASSERT_THROWS(averageSorted(times), const std::invalid_argument &);
times.emplace_back(createFromSanitizedISO8601("1977-05-25T00:00Z")); // Star Wars IV
times.emplace_back(createFromSanitizedISO8601("1977-09-11T00:00Z")); // ATARI 2600
times.emplace_back(createFromSanitizedISO8601("1980-05-17T00:00Z")); // Star Wars V
times.emplace_back(createFromSanitizedISO8601("1983-05-25T00:00Z")); // Star Wars VI
TS_ASSERT_EQUALS(averageSorted(times), createFromSanitizedISO8601("1979-09-19T00:00Z"));
}
};