forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
YValidationTest.h
58 lines (46 loc) · 1.96 KB
/
YValidationTest.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
// 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 <cxxtest/TestSuite.h>
#include "MantidHistogramData/Counts.h"
#include "MantidHistogramData/Frequencies.h"
#include "MantidHistogramData/HistogramY.h"
#include "MantidHistogramData/YValidation.h"
#include <cfloat>
#include <numeric>
using Mantid::HistogramData::Counts;
using Mantid::HistogramData::Frequencies;
using Mantid::HistogramData::HistogramY;
using Mantid::HistogramData::isValid;
class YValidationTest : 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 YValidationTest *createSuite() { return new YValidationTest(); }
static void destroySuite(YValidationTest *suite) { delete suite; }
// FixedLengthVector contains validation, so we need to take a detour for
// creating a potentially invalid HistogramY.
HistogramY makeY(std::initializer_list<double> list) {
std::vector<double> helper(list.size());
std::iota(helper.begin(), helper.end(), 0.0);
HistogramY y(helper);
std::copy(list.begin(), list.end(), y.begin());
return y;
}
void test_works_for_HistogramY() { TS_ASSERT(isValid(HistogramY{1.0, 2.0})); }
void test_works_for_Counts() { TS_ASSERT(isValid(Counts{1.0, 2.0})); }
void test_works_for_Frequencies() { TS_ASSERT(isValid(Frequencies{1.0, 2.0})); }
void test_length_zero() { TS_ASSERT(isValid(HistogramY(0))); }
void test_accepts_nan() {
TS_ASSERT(isValid(makeY({NAN})));
TS_ASSERT(isValid(makeY({-NAN})));
}
void test_detects_inf() {
TS_ASSERT(!isValid(makeY({INFINITY})));
TS_ASSERT(!isValid(makeY({-INFINITY})));
}
};