From e1a8b46186d78b3dfdff789e767cb1a2af9ed11b Mon Sep 17 00:00:00 2001
From: Owen Arnold <owen.arnold@stfc.ac.uk>
Date: Wed, 1 Apr 2020 12:51:22 +0100
Subject: [PATCH] OrientedLattice operator== and operator!=

---
 .../MantidGeometry/Crystal/OrientedLattice.h  |  5 +++-
 .../Geometry/src/Crystal/OrientedLattice.cpp  |  6 +++++
 Framework/Geometry/test/OrientedLatticeTest.h | 25 +++++++++++++++++++
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/Framework/Geometry/inc/MantidGeometry/Crystal/OrientedLattice.h b/Framework/Geometry/inc/MantidGeometry/Crystal/OrientedLattice.h
index b39fd094420..4334d1b7c97 100644
--- a/Framework/Geometry/inc/MantidGeometry/Crystal/OrientedLattice.h
+++ b/Framework/Geometry/inc/MantidGeometry/Crystal/OrientedLattice.h
@@ -67,6 +67,9 @@ public:
   static bool GetABC(const Kernel::DblMatrix &UB, Kernel::V3D &a_dir,
                      Kernel::V3D &b_dir, Kernel::V3D &c_dir);
 
+  bool operator==(const OrientedLattice &other) const;
+  bool operator!=(const OrientedLattice &other) const;
+
 private:
   Kernel::DblMatrix U;
   Kernel::DblMatrix UB;
@@ -79,4 +82,4 @@ private:
   void recalculate() override;
 };
 } // namespace Geometry
-} // namespace Mantid
\ No newline at end of file
+} // namespace Mantid
diff --git a/Framework/Geometry/src/Crystal/OrientedLattice.cpp b/Framework/Geometry/src/Crystal/OrientedLattice.cpp
index dae0f1c61d6..94284f3413f 100644
--- a/Framework/Geometry/src/Crystal/OrientedLattice.cpp
+++ b/Framework/Geometry/src/Crystal/OrientedLattice.cpp
@@ -344,5 +344,11 @@ void OrientedLattice::recalculate() {
   UnitCell::recalculate();
   UB = U * getB();
 }
+bool OrientedLattice::operator==(const OrientedLattice &other) const {
+  return UB == other.UB;
+}
+bool OrientedLattice::operator!=(const OrientedLattice &other) const {
+  return UB != other.UB;
+}
 } // Namespace Geometry
 } // Namespace Mantid
diff --git a/Framework/Geometry/test/OrientedLatticeTest.h b/Framework/Geometry/test/OrientedLatticeTest.h
index b1f9379f2ea..be341d5de64 100644
--- a/Framework/Geometry/test/OrientedLatticeTest.h
+++ b/Framework/Geometry/test/OrientedLatticeTest.h
@@ -300,4 +300,29 @@ public:
     TSM_ASSERT_EQUALS(" should be along the y direction", V3D(0, 1, 0), ey);
     TSM_ASSERT_EQUALS("y direction is", V3D(0, -1, 0), eyPrime);
   }
+  void test_equals_when_orientedlattice_identical() {
+    OrientedLattice a(1.0, 2.0, 3.0, 90.0, 90.0,
+                      90.0); // create via lattice parameters
+    OrientedLattice b{a};
+    TS_ASSERT_EQUALS(a, b);
+    TS_ASSERT(!(a != b));
+  }
+
+  void test_not_equals_when_orientedlattice_different_b() {
+    OrientedLattice a(1.0, 2.0, 3.0, 90.0, 90.0,
+                      90.0); // create via lattice parameters
+    OrientedLattice b{a};
+    b.seta(10); // Results in B change
+    TS_ASSERT_DIFFERS(a, b);
+    TS_ASSERT(!(a == b));
+  }
+
+  void test_not_equals_when_orientedlattice_different_u() {
+    OrientedLattice a(1.0, 2.0, 3.0, 90.0, 90.0,
+                      90.0); // create via lattice parameters
+    OrientedLattice b{a};
+    b.setUFromVectors(V3D(0, 1, 0), V3D(1, 0, 0)); // Different U
+    TS_ASSERT_DIFFERS(a, b);
+    TS_ASSERT(!(a == b));
+  }
 };
-- 
GitLab