Newer
Older
Russell Taylor
committed
#ifndef CONVERTFROMDISTRIBUTIONTEST_H_
#define CONVERTFROMDISTRIBUTIONTEST_H_
#include <cxxtest/TestSuite.h>
#include "WorkspaceCreationHelper.hh"
#include "MantidAlgorithms/ConvertFromDistribution.h"
#include "MantidAPI/AnalysisDataService.h"
using namespace Mantid::API;
using Mantid::Algorithms::ConvertFromDistribution;
class ConvertFromDistributionTest : public CxxTest::TestSuite
{
public:
ConvertFromDistributionTest() : dist("dist")
{
Roman Tolchenov
committed
MatrixWorkspace_sptr WS = WorkspaceCreationHelper::Create2DWorkspaceBinned(1,10,0,0.5);
Russell Taylor
committed
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
WS->isDistribution(true);
AnalysisDataService::Instance().add(dist,WS);
}
void testName()
{
TS_ASSERT_EQUALS( conv.name(), "ConvertFromDistribution" )
}
void testVersion()
{
TS_ASSERT_EQUALS( conv.version(), 1 )
}
void testCategory()
{
TS_ASSERT_EQUALS( conv.category(), "General" )
}
void testInit()
{
TS_ASSERT_THROWS_NOTHING( conv.initialize() )
TS_ASSERT( conv.isInitialized() )
}
void testExec()
{
if ( !conv.isInitialized() ) conv.initialize();
TS_ASSERT_THROWS_NOTHING( conv.setPropertyValue("Workspace",dist) )
TS_ASSERT_THROWS_NOTHING( conv.execute() )
TS_ASSERT( conv.isExecuted() )
Roman Tolchenov
committed
MatrixWorkspace_const_sptr output;
TS_ASSERT_THROWS_NOTHING( output = boost::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieve(dist)) )
Russell Taylor
committed
const std::vector<double> &X = output->dataX(0);
const std::vector<double> &Y = output->dataY(0);
const std::vector<double> &E = output->dataE(0);
for (int i = 0; i < Y.size(); ++i)
{
TS_ASSERT_EQUALS( X[i], i/2.0 )
TS_ASSERT_EQUALS( Y[i], 1 )
TS_ASSERT_EQUALS( E[i], sqrt(2.0)/2.0 )
}
TS_ASSERT( ! output->isDistribution() )
AnalysisDataService::Instance().remove(dist);
}
private:
ConvertFromDistribution conv;
std::string dist;
};
#endif /*CONVERTFROMDISTRIBUTIONTEST_H_*/