forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TableWorkspacePropertyTest.h
100 lines (88 loc) · 3.23 KB
/
TableWorkspacePropertyTest.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
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once
#include <algorithm>
#include <cxxtest/TestSuite.h>
#include <memory>
#include <vector>
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/ColumnFactory.h"
#include "MantidAPI/TableRow.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidKernel/Property.h"
using namespace Mantid::DataObjects;
using namespace Mantid::API;
using namespace Mantid::Kernel;
using namespace std;
class TableWorkspaceAlgorithm : public Algorithm {
public:
/// no arg constructor
TableWorkspaceAlgorithm() : Algorithm() {}
/// virtual destructor
~TableWorkspaceAlgorithm() override = default;
/// 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"; }
private:
/// Initialisation code
void init() override;
/// Execution code
void exec() override;
/// Static reference to the logger class
static Mantid::Kernel::Logger &g_log;
};
void TableWorkspaceAlgorithm::init() {
declareProperty(std::make_unique<WorkspaceProperty<Workspace>>("Table", "", Direction::Input));
}
void TableWorkspaceAlgorithm::exec() {
Workspace_sptr b = getProperty("Table");
TableWorkspace_sptr t = std::dynamic_pointer_cast<TableWorkspace>(b);
TableRow r = t->getFirstRow();
r << "FIRST" << 11;
r.next();
r << "SECOND" << 22;
}
class TableWorkspacePropertyTest : public CxxTest::TestSuite {
public:
// 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; }
TableWorkspacePropertyTest() {
t.reset(new TableWorkspace(10));
t->addColumn("str", "Name");
t->addColumn("int", "Nunber");
AnalysisDataService::Instance().add("tst", std::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:
std::shared_ptr<TableWorkspace> t;
};