diff --git a/Framework/Geometry/inc/MantidGeometry/Crystal/UnitCell.h b/Framework/Geometry/inc/MantidGeometry/Crystal/UnitCell.h index c84c586d813e4212fa89432fcb48f75d79c9284f..b34c2a0dbfc5d0847a4318cf2d5c888193de4d21 100644 --- a/Framework/Geometry/inc/MantidGeometry/Crystal/UnitCell.h +++ b/Framework/Geometry/inc/MantidGeometry/Crystal/UnitCell.h @@ -161,6 +161,8 @@ public: double volume() const; double recVolume() const; virtual void recalculateFromGstar(const Kernel::Matrix<double> &NewGstar); + bool operator==(const UnitCell &other) const; + bool operator!=(const UnitCell &other) const; protected: /// Lattice parameter a,b,c,alpha,beta,gamma (in \f$ \mbox{ \AA } \f$ and diff --git a/Framework/Geometry/src/Crystal/UnitCell.cpp b/Framework/Geometry/src/Crystal/UnitCell.cpp index c1e93394240a49e0c26a7adba44a90872f319673..3a7feab47aa4d1665c9ceefdf1dd49f5ae4a1f50 100644 --- a/Framework/Geometry/src/Crystal/UnitCell.cpp +++ b/Framework/Geometry/src/Crystal/UnitCell.cpp @@ -880,6 +880,13 @@ void UnitCell::recalculateFromGstar(const DblMatrix &NewGstar) { calculateB(); } +bool UnitCell::operator==(const UnitCell &other) const { + return da == other.da; // da error not used in comparison +} +bool UnitCell::operator!=(const UnitCell &other) const { + return !this->operator==(other); +} + std::ostream &operator<<(std::ostream &out, const UnitCell &unitCell) { // always show the lattice constants out << "Lattice Parameters:" << std::fixed << std::setprecision(6) diff --git a/Framework/Geometry/test/UnitCellTest.h b/Framework/Geometry/test/UnitCellTest.h index 45f02dd43b70d34f8f6545ab9973fe294bdc71ce..8450c8c973eb4ef74c2b7ec4ab93e91c37886750 100644 --- a/Framework/Geometry/test/UnitCellTest.h +++ b/Framework/Geometry/test/UnitCellTest.h @@ -170,4 +170,53 @@ public: TS_ASSERT_DIFFERS(precisionLimit.c(), precisionLimitOther.c()); TS_ASSERT_DELTA(precisionLimit.c(), precisionLimitOther.c(), 1e-9); } + + void test_equals_when_unitcell_identical() { + const UnitCell a(2.0, 4.0, 5.0, 90.0, 100.0, 102.0); + const UnitCell b(a); + TS_ASSERT_EQUALS(a, b); + TS_ASSERT(!(a != b)); + } + + void test_not_equals_when_unitcell_differs_in_a() { + const UnitCell a(1.0, 1.0, 1.0, 90.0, 90.0, 90.0); + UnitCell b(a); + b.seta(2.0); + TS_ASSERT_DIFFERS(a, b); + } + + void test_not_equals_when_unitcell_differs_in_b() { + const UnitCell a(1.0, 1.0, 1.0, 90.0, 90.0, 90.0); + UnitCell b(a); + b.setb(2.0); + TS_ASSERT_DIFFERS(a, b); + } + + void test_not_equals_when_unitcell_differs_in_c() { + const UnitCell a(1.0, 1.0, 1.0, 90.0, 90.0, 90.0); + UnitCell b(a); + b.setc(2.0); + TS_ASSERT_DIFFERS(a, b); + } + + void test_not_equals_when_unitcell_differs_in_alpha() { + const UnitCell a(1.0, 1.0, 1.0, 90.0, 90.0, 90.0); + UnitCell b(a); + b.setalpha(100); + TS_ASSERT_DIFFERS(a, b); + } + + void test_not_equals_when_unitcell_differs_in_beta() { + const UnitCell a(1.0, 1.0, 1.0, 90.0, 90.0, 90.0); + UnitCell b(a); + b.setbeta(100); + TS_ASSERT_DIFFERS(a, b); + } + + void test_not_equals_when_unitcell_differs_in_gamma() { + const UnitCell a(1.0, 1.0, 1.0, 90.0, 90.0, 90.0); + UnitCell b(a); + b.setgamma(100); + TS_ASSERT_DIFFERS(a, b); + } };