From 5fdcfa206af419b887589f0becb244cdd10e6474 Mon Sep 17 00:00:00 2001
From: Matthew Andrew <matthew.andrew@tessella.com>
Date: Mon, 9 Mar 2020 11:45:24 +0000
Subject: [PATCH] Updated MantidAxesTest.h Re #28194

This updates the test to check that the new return values of replaceWorkspaceArtists and removeWorkspaceArtists return correctly.
---
 qt/widgets/mplcpp/test/MantidAxesTest.h | 37 +++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/qt/widgets/mplcpp/test/MantidAxesTest.h b/qt/widgets/mplcpp/test/MantidAxesTest.h
index 46cb4b71f9f..553d956cb55 100644
--- a/qt/widgets/mplcpp/test/MantidAxesTest.h
+++ b/qt/widgets/mplcpp/test/MantidAxesTest.h
@@ -56,8 +56,9 @@ public:
     const std::string wsName{"myname"};
     const auto ws = createWorkspaceInADS(wsName, {1, 2, 4});
     axes.plot(ws, 0, "red", "mylabel");
-    axes.removeWorkspaceArtists(ws);
+    auto removed = axes.removeWorkspaceArtists(ws);
 
+    TS_ASSERT_EQUALS(removed, true);
     TS_ASSERT_EQUALS(0, Python::Len(axes.pyobj().attr("lines")));
     AnalysisDataService::Instance().remove(wsName);
   }
@@ -68,11 +69,43 @@ public:
     const auto wsOld = createWorkspaceInADS(wsName, {1, 2, 4});
     axes.plot(wsOld, 0, "red", "mylabel");
     const auto wsNew = createWorkspaceInADS(wsName, {2, 3, 5});
-    axes.replaceWorkspaceArtists(wsNew);
+    auto replaces = axes.replaceWorkspaceArtists(wsNew);
 
     auto newLine = axes.pyobj().attr("lines")[0];
     TS_ASSERT_EQUALS(2.5, newLine.attr("get_xdata")()[0]);
     TS_ASSERT_EQUALS("red", newLine.attr("get_color")());
+    TS_ASSERT_EQUALS(replaces, true);
+
+    AnalysisDataService::Instance().remove(wsName);
+  }
+
+  void testRemovingWorkspaceNotOnPlotReturnsFalse() {
+    MantidAxes axes{pyAxes()};
+    const std::string wsName{"myname"};
+    const std::string wsName2{"mynamenotPlotted"};
+    const auto ws = createWorkspaceInADS(wsName, {1, 2, 4});
+    const auto wsNotPlotted = createWorkspaceInADS(wsName2, {1, 2, 4});
+    axes.plot(ws, 0, "red", "mylabel");
+    auto removed = axes.removeWorkspaceArtists(wsNotPlotted);
+
+    TS_ASSERT_EQUALS(removed, false);
+    TS_ASSERT_EQUALS(1, Python::Len(axes.pyobj().attr("lines")));
+    AnalysisDataService::Instance().remove(wsName);
+  }
+
+  void testReplacingWorkspaceNotOnPlotReturnsFalse() {
+    MantidAxes axes{pyAxes()};
+    const std::string wsName{"myname"};
+    const std::string wsName2{"myname2"};
+    const auto wsOld = createWorkspaceInADS(wsName, {2, 3, 5});
+    axes.plot(wsOld, 0, "red", "mylabel");
+    const auto wsNew = createWorkspaceInADS(wsName2, {1, 2, 4});
+    auto replaces = axes.replaceWorkspaceArtists(wsNew);
+
+    auto newLine = axes.pyobj().attr("lines")[0];
+    TS_ASSERT_EQUALS(2.5, newLine.attr("get_xdata")()[0]);
+    TS_ASSERT_EQUALS("red", newLine.attr("get_color")());
+    TS_ASSERT_EQUALS(replaces, false);
 
     AnalysisDataService::Instance().remove(wsName);
   }
-- 
GitLab