From aebe6ac36b79fdcc6d04a0fb23980f9b45add94a Mon Sep 17 00:00:00 2001
From: Simon Heybrock <simon.heybrock@esss.se>
Date: Wed, 29 Jul 2015 08:25:05 +0200
Subject: [PATCH] Re #13236 Added test that exposes the WedgeOffset bug in
 Q1DWeigthed.

---
 .../Algorithms/test/Q1DWeightedTest.h         | 106 ++++++++++++++++++
 1 file changed, 106 insertions(+)

diff --git a/Code/Mantid/Framework/Algorithms/test/Q1DWeightedTest.h b/Code/Mantid/Framework/Algorithms/test/Q1DWeightedTest.h
index d0eb3455b7b..13bbc48ffb2 100644
--- a/Code/Mantid/Framework/Algorithms/test/Q1DWeightedTest.h
+++ b/Code/Mantid/Framework/Algorithms/test/Q1DWeightedTest.h
@@ -92,6 +92,112 @@ public:
 
   }
 
+  // Test whether the WedgeOffset parameter works correctly.
+  void testWedgeOffset() {
+    // Setup is copied from testExec().
+    Mantid::DataHandling::LoadSpice2D loader;
+    loader.initialize();
+    loader.setPropertyValue("Filename", "BioSANS_exp61_scan0004_0001.xml");
+    const std::string inputWS("wav");
+    loader.setPropertyValue("OutputWorkspace", inputWS);
+    loader.execute();
+
+    // Move detector to its correct position
+    Mantid::DataHandling::MoveInstrumentComponent mover;
+    mover.initialize();
+    mover.setPropertyValue("Workspace", inputWS);
+    mover.setPropertyValue("ComponentName", "detector1");
+
+    // According to the instrument geometry, the center of the detector is
+    // located at N_pixel / 2 + 0.5
+    // X = (16-192.0/2.0+0.5)*5.15/1000.0 = -0.409425
+    // Y = (95-192.0/2.0+0.5)*5.15/1000.0 = -0.002575
+    mover.setPropertyValue("X", "0.409425");
+    mover.setPropertyValue("Y", "0.002575");
+    mover.execute();
+
+    const std::string outputWS("result");
+    const std::string wedgeWS1("wedge1");
+    const std::string wedgeWS2("wedge2");
+
+    // Test method:
+    // We use two wedges, which implies that they have an offset of 90 degree.
+    // We then call the algorithm twice, once with offset 0, once with offset
+    // 90. With offset 90 the wedges are thus logically "swapped", so we check
+    // if their values match.
+
+    if (!radial_average.isInitialized())
+      radial_average.initialize();
+    TS_ASSERT_THROWS_NOTHING(
+        radial_average.setPropertyValue("InputWorkspace", inputWS))
+    TS_ASSERT_THROWS_NOTHING(
+        radial_average.setPropertyValue("OutputWorkspace", outputWS))
+    TS_ASSERT_THROWS_NOTHING(
+        radial_average.setPropertyValue("OutputBinning", "0.01,0.001,0.11"))
+    TS_ASSERT_THROWS_NOTHING(
+        radial_average.setPropertyValue("NPixelDivision", "3"))
+    TS_ASSERT_THROWS_NOTHING(
+        radial_average.setPropertyValue("ErrorWeighting", "1"))
+    TS_ASSERT_THROWS_NOTHING(
+        radial_average.setPropertyValue("WedgeWorkspace", wedgeWS1))
+    TS_ASSERT_THROWS_NOTHING(
+        radial_average.setPropertyValue("NumberOfWedges", "2"))
+    TS_ASSERT_THROWS_NOTHING(
+        radial_average.setPropertyValue("WedgeAngle", "30"))
+    TS_ASSERT_THROWS_NOTHING(
+        radial_average.setPropertyValue("WedgeOffset", "0"))
+
+    TS_ASSERT_THROWS_NOTHING(radial_average.execute())
+    TS_ASSERT(radial_average.isExecuted())
+
+    if (!radial_average.isInitialized())
+      radial_average.initialize();
+    TS_ASSERT_THROWS_NOTHING(
+        radial_average.setPropertyValue("InputWorkspace", inputWS))
+    TS_ASSERT_THROWS_NOTHING(
+        radial_average.setPropertyValue("OutputWorkspace", outputWS))
+    TS_ASSERT_THROWS_NOTHING(
+        radial_average.setPropertyValue("OutputBinning", "0.01,0.001,0.11"))
+    TS_ASSERT_THROWS_NOTHING(
+        radial_average.setPropertyValue("NPixelDivision", "3"))
+    TS_ASSERT_THROWS_NOTHING(
+        radial_average.setPropertyValue("ErrorWeighting", "1"))
+    TS_ASSERT_THROWS_NOTHING(
+        radial_average.setPropertyValue("WedgeWorkspace", wedgeWS2))
+    TS_ASSERT_THROWS_NOTHING(
+        radial_average.setPropertyValue("NumberOfWedges", "2"))
+    TS_ASSERT_THROWS_NOTHING(
+        radial_average.setPropertyValue("WedgeAngle", "30"))
+    TS_ASSERT_THROWS_NOTHING(
+        radial_average.setPropertyValue("WedgeOffset", "90"))
+
+    TS_ASSERT_THROWS_NOTHING(radial_average.execute())
+    TS_ASSERT(radial_average.isExecuted())
+
+    // Get wedge 0 of the result with offset 0.
+    auto result1 = boost::dynamic_pointer_cast<Mantid::API::WorkspaceGroup>(
+        Mantid::API::AnalysisDataService::Instance().retrieve(wedgeWS1));
+    auto wedge1 = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(
+        result1->getItem(0));
+
+    // Get wedge 1 of the result with offset 90.
+    auto result2 = boost::dynamic_pointer_cast<Mantid::API::WorkspaceGroup>(
+        Mantid::API::AnalysisDataService::Instance().retrieve(wedgeWS2));
+    auto wedge2 = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(
+        result2->getItem(1));
+
+    double tolerance = 1e-12;
+
+    // The two wedges shold be identical.
+    for (size_t i = 0; i < wedge1->dataY(0).size(); ++i)
+      TS_ASSERT_DELTA(wedge1->dataY(0)[i], wedge2->dataY(0)[i], tolerance);
+
+    Mantid::API::AnalysisDataService::Instance().remove(inputWS);
+    Mantid::API::AnalysisDataService::Instance().remove(outputWS);
+    Mantid::API::AnalysisDataService::Instance().remove(wedgeWS1);
+    Mantid::API::AnalysisDataService::Instance().remove(wedgeWS2);
+  }
+
 private:
   Mantid::Algorithms::Q1DWeighted radial_average;
   std::string inputWS;
-- 
GitLab