Skip to content

Commit

Permalink
Re #12687 clone() for MementoTableWorkspace.
Browse files Browse the repository at this point in the history
Previously (before 12687) there was no implementation of clone(). That
is, when calling clone() though a base class (e.g., ITableWorkspace) we
would use TableWorkspace::clone() on an object of type
MementoTableWorkspace. Was that doing the right thing?
  • Loading branch information
SimonHeybrock committed Jun 30, 2015
1 parent ec90b59 commit 158a00b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,23 @@ class DLLExport MementoTableWorkspace : public TableWorkspace {
MementoTableWorkspace(int nRows = 0);
~MementoTableWorkspace();

/// Returns a clone of the workspace
std::unique_ptr<MementoTableWorkspace> clone() const {
return std::unique_ptr<MementoTableWorkspace>(doClone());
}

protected:
/// Protected copy constructor. May be used by childs for cloning.
MementoTableWorkspace(const MementoTableWorkspace &other);
MementoTableWorkspace(const MementoTableWorkspace &other)
: ITableWorkspace(other), TableWorkspace(other) {}
/// Protected copy assignment operator. Assignment not implemented.
MementoTableWorkspace &operator=(const MementoTableWorkspace &other);

private:
virtual MementoTableWorkspace *doClone() const {
return new MementoTableWorkspace(*this);
}

static bool expectedColumn(Mantid::API::Column_const_sptr expected,
Mantid::API::Column_const_sptr candidate);
};
Expand Down
34 changes: 34 additions & 0 deletions Code/Mantid/Framework/DataObjects/test/MementoTableWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,40 @@ class MementoTableWorkspaceTest : public CxxTest::TestSuite
TSM_ASSERT_EQUALS("Wrong number of columns constructed", 11, pWs->columnCount());
}

void testClone()
{
MementoTableWorkspace tw(1);

tw.getColumn(0)->cell<std::string>(0) = "a";
tw.getColumn(1)->cell<std::string>(0) = "b";
tw.getColumn(2)->cell<int>(0) = 421;
tw.getColumn(3)->cell<std::string>(0) = "c";
tw.getColumn(4)->cell<double>(0) = 1.1;
tw.getColumn(5)->cell<double>(0) = 2.1;
tw.getColumn(6)->cell<double>(0) = 3.1;
tw.getColumn(7)->cell<double>(0) = 4.1;
tw.getColumn(8)->cell<double>(0) = 5.1;
tw.getColumn(9)->cell<double>(0) = 6.1;
tw.getColumn(10)->cell<std::string>(0) = "d";

auto cloned = tw.clone();

// Check clone is same as original.
TS_ASSERT_EQUALS(tw.columnCount(), cloned->columnCount());
TS_ASSERT_EQUALS(tw.rowCount(), cloned->rowCount());
TS_ASSERT_EQUALS("a", cloned->getColumn(0)->cell<std::string>(0));
TS_ASSERT_EQUALS("b", cloned->getColumn(1)->cell<std::string>(0));
TS_ASSERT_EQUALS(421, cloned->getColumn(2)->cell<int>(0));
TS_ASSERT_EQUALS("c", cloned->getColumn(3)->cell<std::string>(0));
TS_ASSERT_EQUALS(1.1, cloned->getColumn(4)->cell<double>(0));
TS_ASSERT_EQUALS(2.1, cloned->getColumn(5)->cell<double>(0));
TS_ASSERT_EQUALS(3.1, cloned->getColumn(6)->cell<double>(0));
TS_ASSERT_EQUALS(4.1, cloned->getColumn(7)->cell<double>(0));
TS_ASSERT_EQUALS(5.1, cloned->getColumn(8)->cell<double>(0));
TS_ASSERT_EQUALS(6.1, cloned->getColumn(9)->cell<double>(0));
TS_ASSERT_EQUALS("d", cloned->getColumn(10)->cell<std::string>(0));
}

void testCompareWithWrongNColumns()
{
//Create a table workspace with too few columns.
Expand Down

0 comments on commit 158a00b

Please sign in to comment.