Skip to content

Commit

Permalink
Implement & test copy constructor/assignment operator.
Browse files Browse the repository at this point in the history
Refs #9252
  • Loading branch information
martyngigg committed Apr 4, 2014
1 parent 3934969 commit a764967
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/Unit.h
Expand Up @@ -14,6 +14,7 @@ namespace Mantid
{
namespace Kernel
{

/** The base units (abstract) class. All concrete units should inherit from
this class and provide implementations of the caption(), label(),
toTOF() and fromTOF() methods. They also need to declare (but NOT define)
Expand Down
29 changes: 25 additions & 4 deletions Code/Mantid/Framework/Kernel/src/Unit.cpp
Expand Up @@ -29,11 +29,32 @@ namespace Kernel
{
}

/// Copy Constructor
Unit::Unit(const Unit & other) : initialized(false),
l1(other.l1), l2(other.l2), twoTheta(other.twoTheta),
emode(other.emode), efixed(other.efixed), delta(other.delta)
/**
* @param other The unit that initializes this
*/
Unit::Unit(const Unit & other)
{
// call assignment operator
*this = other;
}

/**
* @param rhs A unit object whose state is copied to this
* @return A reference to this object
*/
Unit &Unit::operator=(const Unit &rhs)
{
if(this != &rhs)
{
initialized = rhs.initialized;
l1 = rhs.l1;
l2 = rhs.l2;
twoTheta = rhs.twoTheta;
emode = rhs.emode;
efixed = rhs.efixed;
delta = rhs.delta;
}
return *this;
}

/**
Expand Down
24 changes: 24 additions & 0 deletions Code/Mantid/Framework/Kernel/test/UnitTest.h
Expand Up @@ -240,6 +240,30 @@ class UnitTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS( tof.unitID(), "TOF" );
}

void test_copy_constructor_on_concrete_type()
{
Units::TOF first;
first.initialize(1.0,1.0,1.0,1.0,1.0,1.0);
Units::TOF second(first);
TS_ASSERT_EQUALS(first.isInitialized(), second.isInitialized());
TS_ASSERT_EQUALS(first.unitID(), second.unitID())
TS_ASSERT_EQUALS(first.caption(), second.caption())
TS_ASSERT_EQUALS(first.label(), second.label())
}

void test_copy_assignment_operator_on_concrete_type()
{
Units::TOF first;
first.initialize(1.0,1.0,1.0,1.0,1.0,1.0);
Units::TOF second;
second = first;
TS_ASSERT_EQUALS(first.isInitialized(), second.isInitialized());
TS_ASSERT_EQUALS(first.unitID(), second.unitID())
TS_ASSERT_EQUALS(first.caption(), second.caption())
TS_ASSERT_EQUALS(first.label(), second.label())
}


void testTOF_caption()
{
TS_ASSERT_EQUALS( tof.caption(), "Time-of-flight" );
Expand Down

0 comments on commit a764967

Please sign in to comment.