-
Notifications
You must be signed in to change notification settings - Fork 122
/
AddSampleLogTest.h
138 lines (110 loc) · 4.16 KB
/
AddSampleLogTest.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ifndef ADDSAMPLELOGTEST_H_
#define ADDSAMPLELOGTEST_H_
#include <cxxtest/TestSuite.h>
#include <string>
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAlgorithms/AddSampleLog.h"
#include "MantidKernel/TimeSeriesProperty.h"
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::Algorithms;
class AddSampleLogTest : public CxxTest::TestSuite
{
public:
void test_Workspace2D()
{
MatrixWorkspace_sptr ws = WorkspaceCreationHelper::Create2DWorkspace(10,10);
ExecuteAlgorithm(ws, "My Name", "String", "My Value", 0.0);
}
void test_EventWorkspace()
{
MatrixWorkspace_sptr ws = WorkspaceCreationHelper::CreateEventWorkspace(10,10);
ExecuteAlgorithm(ws, "My Name", "String", "My Value", 0.0);
}
void test_CanOverwrite()
{
MatrixWorkspace_sptr ws = WorkspaceCreationHelper::Create2DWorkspace(10,10);
ExecuteAlgorithm(ws, "My Name", "String", "My Value", 0.0);
ExecuteAlgorithm(ws, "My Name", "String", "My New Value", 0.0);
}
void test_Number()
{
MatrixWorkspace_sptr ws = WorkspaceCreationHelper::Create2DWorkspace(10,10);
ExecuteAlgorithm(ws, "My Name", "Number", "1.234", 1.234);
ExecuteAlgorithm(ws, "My Name", "Number", "2.456", 2.456);
ExecuteAlgorithm(ws, "My Name", "Number", "-987654321", -987654321);
ExecuteAlgorithm(ws, "My Name", "Number", "963", 963);
}
void test_BadNumber()
{
MatrixWorkspace_sptr ws = WorkspaceCreationHelper::Create2DWorkspace(10,10);
ExecuteAlgorithm(ws, "My Name", "Number", "OneTwoThreeFour", 0.0, true);
}
void test_BadNumberSeries()
{
MatrixWorkspace_sptr ws = WorkspaceCreationHelper::Create2DWorkspace(10,10);
ExecuteAlgorithm(ws, "My Name", "Number Series", "FiveSixSeven", 0.0, true);
}
void test_NumberSeries()
{
MatrixWorkspace_sptr ws = WorkspaceCreationHelper::Create2DWorkspace(10,10);
ws->mutableRun().setStartAndEndTime(DateAndTime("2013-12-18T13:40:00"),DateAndTime("2013-12-18T13:42:00"));
ExecuteAlgorithm(ws, "My Name", "Number Series", "1.234", 1.234);
ExecuteAlgorithm(ws, "My Name", "Number Series", "2.456", 2.456);
ExecuteAlgorithm(ws, "My Name", "Number Series", "-1", -1);
ExecuteAlgorithm(ws, "Another Name", "Number Series", "0", 0);
ExecuteAlgorithm(ws, "Another Name", "Number Series", "123456789", 123456789);
}
template<typename T>
void ExecuteAlgorithm(MatrixWorkspace_sptr testWS, std::string LogName, std::string LogType, std::string LogText,
T expectedValue, bool fails=false)
{
//add the workspace to the ADS
AnalysisDataService::Instance().addOrReplace("AddSampleLogTest_Temporary", testWS);
//execute algorithm
AddSampleLog alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize());
TS_ASSERT( alg.isInitialized() )
alg.setPropertyValue("Workspace", "AddSampleLogTest_Temporary");
alg.setPropertyValue("LogName", LogName);
alg.setPropertyValue("LogText", LogText);
alg.setPropertyValue("LogType", LogType);
TS_ASSERT_THROWS_NOTHING(alg.execute())
if (fails)
{
TS_ASSERT( !alg.isExecuted() )
return;
}
else
{
TS_ASSERT( alg.isExecuted() )
}
//check output
MatrixWorkspace_sptr output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(alg.getProperty("Workspace"));
const Run& wSpaceRun = output->run();
Property * prop = NULL;
TS_ASSERT_THROWS_NOTHING(prop = wSpaceRun.getLogData(LogName);)
if (!prop) return;
if (LogType == "String")
{
TS_ASSERT_EQUALS( prop->value(), LogText);
}
else if (LogType == "Number")
{
auto testProp = dynamic_cast<PropertyWithValue<T>*>(prop);
TS_ASSERT(testProp);
TS_ASSERT_DELTA((*testProp)(), expectedValue, 1e-5);
}
else if (LogType == "Number Series")
{
auto testProp = dynamic_cast<TimeSeriesProperty<T>*>(prop);
TS_ASSERT(testProp);
TS_ASSERT_EQUALS(testProp->firstTime(),DateAndTime("2013-12-18T13:40:00"));
TS_ASSERT_DELTA(testProp->firstValue(), expectedValue, 1e-5);
}
//cleanup
AnalysisDataService::Instance().remove(output->getName());
}
};
#endif /*ADDSAMPLELOGTEST_H_*/