Skip to content

Commit

Permalink
Refs #9445. Added clone method to PoldiPeak
Browse files Browse the repository at this point in the history
Also added equality operator to MillerIndices, since the lack of it was
failing the test for PoldiPeak::clone.
  • Loading branch information
Michael Wedel committed May 21, 2014
1 parent 4e1011f commit 16fe428
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
Expand Up @@ -47,6 +47,7 @@ class MANTID_SINQ_DLL MillerIndices {
int l() const;

int operator[](int index);
bool operator ==(MillerIndices &other) const;

const std::vector<int>& asVector() const;

Expand Down
Expand Up @@ -53,6 +53,8 @@ class MANTID_SINQ_DLL PoldiPeak

~PoldiPeak() {}

PoldiPeak_sptr clone() const;

const MillerIndices& hkl() const;
void setHKL(MillerIndices hkl);

Expand Down
Expand Up @@ -51,6 +51,11 @@ int MillerIndices::operator [](int index)
return m_asVector[index];
}

bool MillerIndices::operator ==(MillerIndices &other) const
{
return m_h == other.m_h && m_k == other.m_k && m_l == other.m_l;
}

const std::vector<int> &MillerIndices::asVector() const
{
return m_asVector;
Expand Down
5 changes: 5 additions & 0 deletions Code/Mantid/Framework/SINQ/src/PoldiUtilities/PoldiPeak.cpp
Expand Up @@ -7,6 +7,11 @@
namespace Mantid {
namespace Poldi {

PoldiPeak_sptr PoldiPeak::clone() const
{
return PoldiPeak_sptr(new PoldiPeak(*this));
}

const MillerIndices &PoldiPeak::hkl() const
{
return m_hkl;
Expand Down
10 changes: 10 additions & 0 deletions Code/Mantid/Framework/SINQ/test/MillerIndicesTest.h
Expand Up @@ -84,6 +84,16 @@ class MillerIndicesTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(copyVector.size(), 3);
TS_ASSERT_EQUALS(copyVector[0], hkl[0]);
}

void testEquality()
{
MillerIndices hklOne(1, 1, 0);
MillerIndices hklTwo(1, 1, 0);
MillerIndices hklThree(1, 2, 0);

TS_ASSERT_EQUALS(hklOne, hklTwo);
TS_ASSERT_DIFFERS(hklOne, hklThree);
}
};

#endif // MANTID_SINQ_MILLERINDICESTEST_H
11 changes: 11 additions & 0 deletions Code/Mantid/Framework/SINQ/test/PoldiPeakTest.h
Expand Up @@ -175,6 +175,17 @@ class PoldiPeakTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(peaks[1]->q(), 1.0);
TS_ASSERT_EQUALS(peaks[2]->q(), 3.0);
}

void testClone()
{
PoldiPeak_sptr peak = PoldiPeak::create(1.0, 200.00);
PoldiPeak_sptr clone = peak->clone();

TS_ASSERT_EQUALS(peak->d(), clone->d());
TS_ASSERT_EQUALS(peak->fwhm(), clone->fwhm());
TS_ASSERT_EQUALS(peak->intensity(), clone->intensity());
TS_ASSERT_EQUALS(peak->hkl(), clone->hkl());
}
};

#endif // MANTID_SINQ_POLDIPEAKTEST_H

0 comments on commit 16fe428

Please sign in to comment.