forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnitFactoryTest.h
44 lines (37 loc) · 1.77 KB
/
UnitFactoryTest.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
// 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 "MantidKernel/Unit.h"
#include "MantidKernel/UnitFactory.h"
#include <memory>
using namespace Mantid::Kernel;
class UnitFactoryTest : public CxxTest::TestSuite {
public:
void test_Create_With_Valid_Unit_Gives_Valid_Pointer() {
std::shared_ptr<Unit> first;
TS_ASSERT_THROWS_NOTHING(first = UnitFactory::Instance().create("TOF"));
TSM_ASSERT("UnitFactory::create did not throw but it returned an empty pointer", first);
}
void test_Create_With_Unknown_Unit_Throws_Exception() {
TS_ASSERT_THROWS(UnitFactory::Instance().create("_NOT_A_REAL_UNIT"), const Exception::NotFoundError &);
}
void test_getKeys_Includes_Label_and_TOF() {
auto keys = UnitFactory::Instance().getKeys();
TSM_ASSERT("Cannot find Label in the keys of the unit factory",
std::find(keys.begin(), keys.end(), "Label") != keys.end());
TSM_ASSERT("Cannot find TOF in the keys of the unit factory",
std::find(keys.begin(), keys.end(), "TOF") != keys.end());
}
void test_getConvertibleUnits_Includes_TOF_but_not_label() {
auto keys = UnitFactory::Instance().getConvertibleUnits();
TSM_ASSERT("Can find Label in the ConvertibleUnits of the unit factory",
std::find(keys.begin(), keys.end(), "Label") == keys.end());
TSM_ASSERT("Cannot find TOF in the ConvertibleUnits of the unit factory",
std::find(keys.begin(), keys.end(), "TOF") != keys.end());
}
};