Skip to content

Commit

Permalink
Unit tests added for equal opeartor in python and c++
Browse files Browse the repository at this point in the history
  • Loading branch information
warunawickramasingha committed Dec 3, 2024
1 parent 8f83b5c commit 86448cc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
10 changes: 10 additions & 0 deletions Framework/DataObjects/test/PeakShapeDetectorBinTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,14 @@ class PeakShapeDetectorBinTest : public CxxTest::TestSuite {
TS_ASSERT_EQUALS(shape2.getDetectorBinList(), shape1.getDetectorBinList());
TS_ASSERT_EQUALS(shape2.toJSON(), shape1.toJSON());
}

void test_equal_operator() {
std::vector<std::tuple<int32_t, double, double>> detPeakBinList1 = {{100, 10, 50}, {200, 34, 55}};
PeakShapeDetectorBin shape1(detPeakBinList1, SpecialCoordinateSystem::None, "algo1", 1);

std::vector<std::tuple<int32_t, double, double>> detPeakBinList2 = {{100, 10, 50}, {200, 34, 55}};
PeakShapeDetectorBin shape2(detPeakBinList2, SpecialCoordinateSystem::None, "algo2", 2);

TS_ASSERT_EQUALS(shape1, shape2);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ void export_PeakShapeDetectorBin() {
class_<PeakShapeDetectorBin, bases<Mantid::Geometry::PeakShape>, boost::noncopyable>("PeakShapeDetectorBin", no_init)
.def("__init__", make_constructor(&createPeakShapeDetectorBin, default_call_policies(),
(arg("detectorBinList"), arg("frame") = SpecialCoordinateSystem::None,
arg("algorithmName") = "", arg("algorithmVersion") = -1)));
arg("algorithmName") = "", arg("algorithmVersion") = -1)))
.def("__eq__", &PeakShapeDetectorBin::operator==, arg("self"), arg("other"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ def test_set_peak_shape(self):
no_shape = NoShape()
sphere = PeakShapeSpherical(1)
ellipse = PeakShapeEllipsoid([V3D(1, 0, 0), V3D(0, 1, 0), V3D(0, 0, 1)], [0.1, 0.2, 0.3], [0.4, 0.5, 0.6], [0.7, 0.8, 0.9])
detectorXList = [(14500, 20.45, 50.89), (45670, 109.88, 409.56), (60995, 56009.89, 70988.89)]
detectorBin = PeakShapeDetectorBin(detectorXList, SpecialCoordinateSystem.NONE, "test", 1)
detector_x_list = [(14500, 20.45, 50.89), (45670, 109.88, 409.56), (60995, 56009.89, 70988.89)]
detector_bin = PeakShapeDetectorBin(detector_x_list, SpecialCoordinateSystem.NONE, "test", 1)

self.assertEqual(self._peak.getPeakShape().shapeName(), "none")

Expand All @@ -188,15 +188,17 @@ def test_set_peak_shape(self):
self._peak.setPeakShape(no_shape)
self.assertEqual(self._peak.getPeakShape().shapeName(), "none")

self._peak.setPeakShape(detectorBin)
self._peak.setPeakShape(detector_bin)
self.assertEqual(self._peak.getPeakShape().shapeName(), "PeakShapeDetectorBin")
self.assertEqual(self._peak.getPeakShape().algorithmVersion(), 1)
self.assertEqual(self._peak.getPeakShape().algorithmName(), "test")
det_bin_dict = json.loads(self._peak.getPeakShape().toJSON())
for i in range(3):
self.assertEqual(det_bin_dict["detectors"][i]["detId"], detectorXList[i][0])
self.assertEqual(det_bin_dict["detectors"][i]["startX"], detectorXList[i][1])
self.assertEqual(det_bin_dict["detectors"][i]["endX"], detectorXList[i][2])
self.assertEqual(det_bin_dict["detectors"][i]["detId"], detector_x_list[i][0])
self.assertEqual(det_bin_dict["detectors"][i]["startX"], detector_x_list[i][1])
self.assertEqual(det_bin_dict["detectors"][i]["endX"], detector_x_list[i][2])
detector_bin_copy = PeakShapeDetectorBin(detector_x_list, SpecialCoordinateSystem.NONE, "test2", 2)
self.assertEqual(detector_bin, detector_bin_copy)


if __name__ == "__main__":
Expand Down

0 comments on commit 86448cc

Please sign in to comment.