Newer
Older
#ifndef TESTTABLEWORKSPACEPROPERTY_
#define TESTTABLEWORKSPACEPROPERTY_
#include <vector>
#include <algorithm>
#include <boost/shared_ptr.hpp>
#include <cxxtest/TestSuite.h>
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidKernel/Property.h"
#include "MantidAPI/TableRow.h"
#include "MantidAPI/ColumnFactory.h"
using namespace Mantid::DataObjects;
using namespace Mantid::API;
using namespace Mantid::Kernel;
using namespace std;
class TableWorkspaceAlgorithm : public Algorithm {
TableWorkspaceAlgorithm() : Algorithm() {}
~TableWorkspaceAlgorithm() override {}
/// Algorithm's name for identification overriding a virtual method
const std::string name() const override { return "TableWorkspaceAlgorithm"; }
/// Algorithm's version for identification overriding a virtual method
int version() const override { return (1); }
/// Algorithm's category for identification overriding a virtual method
const std::string category() const override { return "Examples"; }
const std::string summary() const override { return "Test summary"; }
/// Static reference to the logger class
static Mantid::Kernel::Logger &g_log;
void TableWorkspaceAlgorithm::init() {
declareProperty(Mantid::Kernel::make_unique<WorkspaceProperty<Workspace>>(
"Table", "", Direction::Input));
void TableWorkspaceAlgorithm::exec() {
Workspace_sptr b = getProperty("Table");
TableWorkspace_sptr t = boost::dynamic_pointer_cast<TableWorkspace>(b);
TableRow r = t->getFirstRow();
r << "FIRST" << 11;
r.next();
r << "SECOND" << 22;
class TableWorkspacePropertyTest : public CxxTest::TestSuite {
Russell Taylor
committed
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static TableWorkspacePropertyTest *createSuite() {
return new TableWorkspacePropertyTest();
}
static void destroySuite(TableWorkspacePropertyTest *suite) { delete suite; }
Russell Taylor
committed
TableWorkspacePropertyTest() {
t.reset(new TableWorkspace(10));
t->addColumn("str", "Name");
t->addColumn("int", "Nunber");
AnalysisDataService::Instance().add(
"tst", boost::dynamic_pointer_cast<Workspace>(t));
}
void testProperty() {
TableWorkspaceAlgorithm alg;
alg.initialize();
alg.setPropertyValue("Table", "tst");
alg.execute();
TableWorkspace_sptr table;
TS_ASSERT_THROWS_NOTHING(
table =
AnalysisDataService::Instance().retrieveWS<TableWorkspace>("tst"));
TS_ASSERT(table);
TS_ASSERT_EQUALS(table->rowCount(), 10);
TableRow r = table->getFirstRow();
std::string s;
int n;
r >> s >> n;
TS_ASSERT_EQUALS(s, "FIRST");
TS_ASSERT_EQUALS(n, 11);
r.next();
r >> s >> n;
TS_ASSERT_EQUALS(s, "SECOND");
TS_ASSERT_EQUALS(n, 22);
}
private:
boost::shared_ptr<TableWorkspace> t;
};
#endif /*TESTTABLEWORKSPACE_*/