Skip to content

Commit

Permalink
refs #7539. Method to clear the oriented lattice off a sample.
Browse files Browse the repository at this point in the history
Remove the oriented lattice. Additional unit tests provided to cover this functionality.
  • Loading branch information
OwenArnold committed Aug 5, 2013
1 parent 346187f commit a31edc5
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/Sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ namespace Mantid
/// Returns the width
double getWidth() const;
//@}
/// Delete the oriented lattice
void clearOrientedLattice();

private:
/// The sample name
Expand Down
12 changes: 11 additions & 1 deletion Code/Mantid/Framework/API/src/Sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,16 @@ namespace Mantid
return version;
}


/**
* Delete the oriented lattice.
*/
void Sample::clearOrientedLattice()
{
if(m_lattice)
{
delete m_lattice;
m_lattice = NULL;
}
}
}
}
91 changes: 91 additions & 0 deletions Code/Mantid/Framework/API/test/SampleTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,97 @@ class SampleTest : public CxxTest::TestSuite

}

void test_clearOrientedLattice()
{
Sample sample;
OrientedLattice *latt = new OrientedLattice(1.0,2.0,3.0, 90, 90, 90);
TS_ASSERT_THROWS_NOTHING(sample.setOrientedLattice(latt));

TS_ASSERT(sample.hasOrientedLattice())
TS_ASSERT_THROWS_NOTHING(sample.getOrientedLattice())

// Now clear it.
sample.clearOrientedLattice();

TS_ASSERT(!sample.hasOrientedLattice())
TS_ASSERT_THROWS(sample.getOrientedLattice(), std::runtime_error&)
}

void test_clearOrientedLattice_and_the_copy_constructor()
{
// Create a sample with an oriented lattice.
Sample sampleA;
OrientedLattice *latticeA = new OrientedLattice(1.0,2.0,3.0, 90, 90, 90);
TS_ASSERT_THROWS_NOTHING(sampleA.setOrientedLattice(latticeA));

// Copy the sample.
Sample sampleB(sampleA);

// Check oriented lattice objects on both.
TS_ASSERT(sampleA.hasOrientedLattice())
TS_ASSERT_THROWS_NOTHING(sampleA.getOrientedLattice())
TS_ASSERT(sampleB.hasOrientedLattice())
TS_ASSERT_THROWS_NOTHING(sampleB.getOrientedLattice())

// Now clear one.
sampleA.clearOrientedLattice();

// One should be cleared, the other should not.
TS_ASSERT(!sampleA.hasOrientedLattice())
TS_ASSERT_THROWS(sampleA.getOrientedLattice(), std::runtime_error&)
TS_ASSERT(sampleB.hasOrientedLattice())
TS_ASSERT_THROWS_NOTHING(sampleB.getOrientedLattice())

// Now clear both.
sampleA.clearOrientedLattice(); // Not strictly necessary, but object should be able to survive such calls.
sampleB.clearOrientedLattice();

// Both should be cleared.
TS_ASSERT(!sampleA.hasOrientedLattice())
TS_ASSERT_THROWS(sampleA.getOrientedLattice(), std::runtime_error&)
TS_ASSERT(!sampleB.hasOrientedLattice())
TS_ASSERT_THROWS(sampleB.getOrientedLattice(), std::runtime_error&)

}

void test_clearOrientedLattice_and_assignment()
{
// Create a sample with an oriented lattice.
Sample sampleA;
OrientedLattice *latticeA = new OrientedLattice(1.0, 2.0, 3.0, 90, 90, 90);
TS_ASSERT_THROWS_NOTHING(sampleA.setOrientedLattice(latticeA));

// Create and then assign to the sample.
Sample sampleB;
sampleB = sampleA;

// Check oriented lattice objects on both.
TS_ASSERT(sampleA.hasOrientedLattice())
TS_ASSERT_THROWS_NOTHING(sampleA.getOrientedLattice())
TS_ASSERT(sampleB.hasOrientedLattice())
TS_ASSERT_THROWS_NOTHING(sampleB.getOrientedLattice())

// Now clear one.
sampleA.clearOrientedLattice();

// One should be cleared, the other should not.
TS_ASSERT(!sampleA.hasOrientedLattice())
TS_ASSERT_THROWS(sampleA.getOrientedLattice(), std::runtime_error&)
TS_ASSERT(sampleB.hasOrientedLattice())
TS_ASSERT_THROWS_NOTHING(sampleB.getOrientedLattice())

// Now clear both.
sampleA.clearOrientedLattice(); // Not strictly necessary, but object should be able to survive such calls.
sampleB.clearOrientedLattice();

// Both should be cleared.
TS_ASSERT(!sampleA.hasOrientedLattice())
TS_ASSERT_THROWS(sampleA.getOrientedLattice(), std::runtime_error&)
TS_ASSERT(!sampleB.hasOrientedLattice())
TS_ASSERT_THROWS(sampleB.getOrientedLattice(), std::runtime_error&)

}


void test_Material_Returns_The_Correct_Value()
{
Expand Down

0 comments on commit a31edc5

Please sign in to comment.