From 94fd90bbd3c5c5a039a1e2a6abfd56e56b0158eb Mon Sep 17 00:00:00 2001
From: Gemma Guest <gemma.guest@stfc.ac.uk>
Date: Wed, 23 Jan 2019 16:36:28 +0000
Subject: [PATCH] Add unit tests for new behaviour

Changed behaviour:

- Minor change to some tests to add Debug flag to ensure that IvsLam outputs that are being checked are actually created. For group workspaces this is currently true anyway at the moment but might not be going forward.

Add new unit tests:

- Check default output names are correct.
- Check that user can override default names.
- Check both with and without debug outputs.

Also fixed ambiguous overload in reflectometry helpers.

Re #24564
---
 .../test/ReflectometryReductionOneAuto2Test.h | 100 ++++++++++++++++++
 .../MantidTestHelpers/ReflectometryHelper.h   |   7 +-
 2 files changed, 103 insertions(+), 4 deletions(-)

diff --git a/Framework/Algorithms/test/ReflectometryReductionOneAuto2Test.h b/Framework/Algorithms/test/ReflectometryReductionOneAuto2Test.h
index 2330f284549..f568e2e040f 100644
--- a/Framework/Algorithms/test/ReflectometryReductionOneAuto2Test.h
+++ b/Framework/Algorithms/test/ReflectometryReductionOneAuto2Test.h
@@ -876,6 +876,85 @@ public:
     ADS.clear();
   }
 
+  void test_input_workspace_group_with_default_output_workspaces() {
+    ReflectometryReductionOneAuto2 alg;
+    setup_alg_on_input_workspace_group_with_run_number(alg);
+    TS_ASSERT_THROWS_NOTHING(alg.execute());
+
+    // Mandatory workspaces should exist
+    TS_ASSERT_EQUALS(ADS.doesExist("IvsQ_1234"), true);
+    TS_ASSERT_EQUALS(ADS.doesExist("IvsQ_binned_1234"), true);
+    // IvsLam is currently always output for group workspaces
+    TS_ASSERT_EQUALS(ADS.doesExist("IvsLam_1234"), true);
+
+    auto outQGroup = retrieveOutWS("IvsQ_1234");
+    auto outQGroupBinned = retrieveOutWS("IvsQ_binned_1234");
+    TS_ASSERT_EQUALS(outQGroup.size(), 4);
+    TS_ASSERT_EQUALS(outQGroupBinned.size(), 4);
+
+    ADS.clear();
+  }
+
+  void
+  test_input_workspace_group_with_default_output_workspaces_and_debug_on() {
+    ReflectometryReductionOneAuto2 alg;
+    setup_alg_on_input_workspace_group_with_run_number(alg);
+    alg.setProperty("Debug", true);
+    TS_ASSERT_THROWS_NOTHING(alg.execute());
+
+    // Mandatory workspaces should exist
+    TS_ASSERT_EQUALS(ADS.doesExist("IvsQ_1234"), true);
+    TS_ASSERT_EQUALS(ADS.doesExist("IvsQ_binned_1234"), true);
+    TS_ASSERT_EQUALS(ADS.doesExist("IvsLam_1234"), true);
+
+    auto outLamGroup = retrieveOutWS("IvsLam_1234");
+    TS_ASSERT_EQUALS(outLamGroup.size(), 4);
+
+    ADS.clear();
+  }
+
+  void test_input_workspace_group_with_named_output_workspaces() {
+    ReflectometryReductionOneAuto2 alg;
+    setup_alg_on_input_workspace_group_with_run_number(alg);
+    alg.setPropertyValue("OutputWorkspace", "testIvsQ");
+    alg.setPropertyValue("OutputWorkspaceBinned", "testIvsQ_binned");
+    alg.setPropertyValue("OutputWorkspaceWavelength", "testIvsLam");
+    TS_ASSERT_THROWS_NOTHING(alg.execute());
+
+    // Mandatory workspaces should exist
+    TS_ASSERT_EQUALS(ADS.doesExist("testIvsQ"), true);
+    TS_ASSERT_EQUALS(ADS.doesExist("testIvsQ_binned"), true);
+    // IvsLam is currently always output for group workspaces
+    TS_ASSERT_EQUALS(ADS.doesExist("testIvsLam"), true);
+
+    auto outQGroup = retrieveOutWS("testIvsQ");
+    auto outQGroupBinned = retrieveOutWS("testIvsQ_binned");
+    TS_ASSERT_EQUALS(outQGroup.size(), 4);
+    TS_ASSERT_EQUALS(outQGroupBinned.size(), 4);
+
+    ADS.clear();
+  }
+
+  void test_input_workspace_group_with_named_output_workspaces_and_debug_on() {
+    ReflectometryReductionOneAuto2 alg;
+    setup_alg_on_input_workspace_group_with_run_number(alg);
+    alg.setPropertyValue("OutputWorkspace", "testIvsQ");
+    alg.setPropertyValue("OutputWorkspaceBinned", "testIvsQ_binned");
+    alg.setPropertyValue("OutputWorkspaceWavelength", "testIvsLam");
+    alg.setProperty("Debug", true);
+    TS_ASSERT_THROWS_NOTHING(alg.execute());
+
+    // Mandatory workspaces should exist
+    TS_ASSERT_EQUALS(ADS.doesExist("testIvsQ"), true);
+    TS_ASSERT_EQUALS(ADS.doesExist("testIvsQ_binned"), true);
+    TS_ASSERT_EQUALS(ADS.doesExist("testIvsLam"), true);
+
+    auto outLamGroup = retrieveOutWS("testIvsLam");
+    TS_ASSERT_EQUALS(outLamGroup.size(), 4);
+
+    ADS.clear();
+  }
+
   void test_one_transmissionrun() {
     const double startX = 1000;
     const int nBins = 3;
@@ -916,6 +995,7 @@ public:
     alg.setPropertyValue("OutputWorkspaceBinned", "IvsQ_binned");
     alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
     alg.setPropertyValue("FirstTransmissionRun", "transWSGroup");
+    alg.setProperty("Debug", true);
     TS_ASSERT_THROWS_NOTHING(alg.execute());
 
     auto outQGroup = retrieveOutWS("IvsQ");
@@ -1055,6 +1135,7 @@ public:
     alg.setPropertyValue("OutputWorkspaceWavelength", "IvsLam");
     alg.setPropertyValue("FirstTransmissionRun", "transWSGroup");
     alg.setPropertyValue("SecondTransmissionRun", "transWSGroup2");
+    alg.setProperty("Debug", true);
     TS_ASSERT_THROWS_NOTHING(alg.execute());
 
     auto outQGroup = retrieveOutWS("IvsQ");
@@ -1563,6 +1644,25 @@ private:
     flood->getAxis(0)->setUnit("TOF");
     return flood;
   }
+
+  void setup_alg_on_input_workspace_group_with_run_number(
+      ReflectometryReductionOneAuto2 &alg) {
+    std::string const name = "input";
+    prepareInputGroup(name);
+    WorkspaceGroup_sptr group = ADS.retrieveWS<WorkspaceGroup>("input");
+    MatrixWorkspace_sptr ws =
+        ADS.retrieveWS<MatrixWorkspace>(group->getNames()[0]);
+    ws->mutableRun().addProperty<std::string>("run_number", "1234");
+
+    alg.initialize();
+    alg.setChild(true);
+    alg.setPropertyValue("InputWorkspace", name);
+    alg.setProperty("WavelengthMin", 0.0000000001);
+    alg.setProperty("WavelengthMax", 15.0);
+    alg.setProperty("ThetaIn", 10.0);
+    alg.setProperty("ProcessingInstructions", "2");
+    alg.setProperty("MomentumTransferStep", 0.04);
+  }
 };
 
 #endif /* MANTID_ALGORITHMS_REFLECTOMETRYREDUCTIONONEAUTO2TEST_H_ */
diff --git a/Framework/TestHelpers/inc/MantidTestHelpers/ReflectometryHelper.h b/Framework/TestHelpers/inc/MantidTestHelpers/ReflectometryHelper.h
index 2795169baac..66fa7087882 100644
--- a/Framework/TestHelpers/inc/MantidTestHelpers/ReflectometryHelper.h
+++ b/Framework/TestHelpers/inc/MantidTestHelpers/ReflectometryHelper.h
@@ -53,10 +53,9 @@ std::vector<MatrixWorkspace_sptr> retrieveOutWS(std::string const &name);
 // original.
 void applyPolarizationEfficiencies(std::string const &name);
 
-MatrixWorkspace_sptr
-createWorkspaceSingle(const double startX = 1, const int nBins = 3,
-                      const double deltaX = 1,
-                      const std::vector<double> &yValues = {1, 2, 3});
+MatrixWorkspace_sptr createWorkspaceSingle(const double startX, const int nBins,
+                                           const double deltaX,
+                                           const std::vector<double> &yValues);
 
 MatrixWorkspace_sptr createWorkspaceSingle(const double startX = 1,
                                            const int nBins = 3,
-- 
GitLab