"...mantiddoc/git@code.ornl.gov:mantidproject/mantid.git" did not exist on "f566a69ae571ec8c7f8a40b98e1d43b4ff60aeb0"
Newer
Older
Steve Williams
committed
#ifndef ADDSAMPLELOGTEST_H_
#define ADDSAMPLELOGTEST_H_
#include <cxxtest/TestSuite.h>
#include <string>
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
Steve Williams
committed
#include "MantidAlgorithms/AddSampleLog.h"
Janik Zikovsky
committed
#include "MantidKernel/TimeSeriesProperty.h"
Steve Williams
committed
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::Algorithms;
class AddSampleLogTest : public CxxTest::TestSuite
{
public:
Janik Zikovsky
committed
void test_Workspace2D()
Gigg, Martyn Anthony
committed
{
Janik Zikovsky
committed
MatrixWorkspace_sptr ws = WorkspaceCreationHelper::Create2DWorkspace(10,10);
ExecuteAlgorithm(ws, "My Name", "String", "My Value", 0.0);
Gigg, Martyn Anthony
committed
}
Janik Zikovsky
committed
void test_EventWorkspace()
Gigg, Martyn Anthony
committed
{
Janik Zikovsky
committed
MatrixWorkspace_sptr ws = WorkspaceCreationHelper::CreateEventWorkspace(10,10);
ExecuteAlgorithm(ws, "My Name", "String", "My Value", 0.0);
Gigg, Martyn Anthony
committed
}
Janik Zikovsky
committed
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
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);
}
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);
ExecuteAlgorithm(ws, "My Name", "Number Series", "1.234", 1.234);
ExecuteAlgorithm(ws, "My Name", "Number Series", "2.456", 2.456);
}
void ExecuteAlgorithm(MatrixWorkspace_sptr testWS, std::string LogName, std::string LogType, std::string LogText,
double expectedValue, bool fails=false)
Gigg, Martyn Anthony
committed
{
Janik Zikovsky
committed
AnalysisDataService::Instance().addOrReplace("AddSampleLogTest_Temporary", testWS);
Gigg, Martyn Anthony
committed
AddSampleLog alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize());
TS_ASSERT( alg.isInitialized() )
Steve Williams
committed
alg.setPropertyValue("Workspace", "AddSampleLogTest_Temporary");
Janik Zikovsky
committed
alg.setPropertyValue("LogName", LogName);
alg.setPropertyValue("LogText", LogText);
alg.setPropertyValue("LogType", LogType);
Steve Williams
committed
TS_ASSERT_THROWS_NOTHING(alg.execute())
Janik Zikovsky
committed
if (fails)
{
TS_ASSERT( !alg.isExecuted() )
return;
}
else
{
TS_ASSERT( alg.isExecuted() )
}
Steve Williams
committed
MatrixWorkspace_sptr output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(alg.getProperty("Workspace"));
Steve Williams
committed
Gigg, Martyn Anthony
committed
const Run& wSpaceRun = output->run();
Property * prop = NULL;
Janik Zikovsky
committed
TS_ASSERT_THROWS_NOTHING(prop = wSpaceRun.getLogData(LogName);)
if (!prop) return;
if (LogType == "String")
{
TS_ASSERT_EQUALS( prop->value(), LogText);
}
else if (LogType == "Number")
{
PropertyWithValue<double> *testProp = dynamic_cast<PropertyWithValue<double>*>(prop);
TS_ASSERT(testProp);
TS_ASSERT_DELTA((*testProp)(), expectedValue, 1e-5);
}
else if (LogType == "Number Series")
{
TimeSeriesProperty<double> *testProp = dynamic_cast<TimeSeriesProperty<double>*>(prop);
TS_ASSERT(testProp);
TS_ASSERT_DELTA(testProp->firstValue(), expectedValue, 1e-5);
}
Steve Williams
committed
//cleanup
AnalysisDataService::Instance().remove(output->getName());
Steve Williams
committed
Gigg, Martyn Anthony
committed
}
Steve Williams
committed
Steve Williams
committed
};
#endif /*ADDSAMPLELOGTEST_H_*/