Newer
Older
Russell Taylor
committed
#ifndef CONVERTFROMDISTRIBUTIONTEST_H_
#define CONVERTFROMDISTRIBUTIONTEST_H_
#include <cxxtest/TestSuite.h>
Gigg, Martyn Anthony
committed
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
Russell Taylor
committed
#include "MantidAlgorithms/ConvertFromDistribution.h"
#include "MantidAPI/AnalysisDataService.h"
using namespace Mantid::API;
using Mantid::Algorithms::ConvertFromDistribution;
class ConvertFromDistributionTest : public CxxTest::TestSuite {
Russell Taylor
committed
public:
static ConvertFromDistributionTest *createSuite() {
return new ConvertFromDistributionTest();
}
static void destroySuite(ConvertFromDistributionTest *suite) { delete suite; }
ConvertFromDistributionTest() : dist("dist") {
MatrixWorkspace_sptr WS =
WorkspaceCreationHelper::Create2DWorkspaceBinned(1, 10, 0, 0.5);
Russell Taylor
committed
WS->isDistribution(true);
AnalysisDataService::Instance().add(dist, WS);
Russell Taylor
committed
}
void testName() { TS_ASSERT_EQUALS(conv.name(), "ConvertFromDistribution") }
Russell Taylor
committed
void testVersion() { TS_ASSERT_EQUALS(conv.version(), 1) }
Russell Taylor
committed
void testInit() {
TS_ASSERT_THROWS_NOTHING(conv.initialize())
TS_ASSERT(conv.isInitialized())
Russell Taylor
committed
}
void testExec() {
if (!conv.isInitialized())
conv.initialize();
Russell Taylor
committed
TS_ASSERT_THROWS_NOTHING(conv.setPropertyValue("Workspace", dist))
Russell Taylor
committed
TS_ASSERT_THROWS_NOTHING(conv.execute())
TS_ASSERT(conv.isExecuted())
Russell Taylor
committed
Roman Tolchenov
committed
MatrixWorkspace_const_sptr output;
TS_ASSERT_THROWS_NOTHING(
output =
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(dist))
Russell Taylor
committed
Russell Taylor
committed
const Mantid::MantidVec &X = output->dataX(0);
const Mantid::MantidVec &Y = output->dataY(0);
const Mantid::MantidVec &E = output->dataE(0);
for (size_t i = 0; i < Y.size(); ++i) {
TS_ASSERT_EQUALS(X[i], static_cast<double>(i) / 2.0)
TS_ASSERT_EQUALS(Y[i], 1)
TS_ASSERT_EQUALS(E[i], sqrt(2.0) / 2.0)
Russell Taylor
committed
}
TS_ASSERT(!output->isDistribution())