From e25c6e6475d6d9aea1ea0973c6c77d0a484e1e81 Mon Sep 17 00:00:00 2001
From: Raquel Alvarez Banos <raquel.alvarez.banos@gmail.com>
Date: Thu, 21 May 2015 12:05:09 +0100
Subject: [PATCH] Re #9693 Adding unit test

---
 .../Framework/Algorithms/CMakeLists.txt       |  1 +
 .../test/GeneralisedSecondDifferenceTest.h    | 67 +++++++++++++++++++
 2 files changed, 68 insertions(+)
 create mode 100644 Code/Mantid/Framework/Algorithms/test/GeneralisedSecondDifferenceTest.h

diff --git a/Code/Mantid/Framework/Algorithms/CMakeLists.txt b/Code/Mantid/Framework/Algorithms/CMakeLists.txt
index 998032e0216..952d2eb79bd 100644
--- a/Code/Mantid/Framework/Algorithms/CMakeLists.txt
+++ b/Code/Mantid/Framework/Algorithms/CMakeLists.txt
@@ -646,6 +646,7 @@ set ( TEST_FILES
 	FitPeakTest.h
 	FixGSASInstrumentFileTest.h
 	FlatPlateAbsorptionTest.h
+	GeneralisedSecondDifferenceTest.h
 	GenerateEventsFilterTest.h
 	GeneratePeaksTest.h
 	GeneratePythonScriptTest.h
diff --git a/Code/Mantid/Framework/Algorithms/test/GeneralisedSecondDifferenceTest.h b/Code/Mantid/Framework/Algorithms/test/GeneralisedSecondDifferenceTest.h
new file mode 100644
index 00000000000..f696a74d262
--- /dev/null
+++ b/Code/Mantid/Framework/Algorithms/test/GeneralisedSecondDifferenceTest.h
@@ -0,0 +1,67 @@
+#ifndef GENERALISEDSECONDDIFFERENCETEST_H_
+#define GENERALISEDSECONDDIFFERENCETEST_H_
+
+#include <cxxtest/TestSuite.h>
+
+#include "MantidAlgorithms/GeneralisedSecondDifference.h"
+#include <boost/assign.hpp>
+
+using namespace Mantid::Algorithms;
+using namespace Mantid::API;
+
+class GeneralisedSecondDifferenceTest : public CxxTest::TestSuite {
+
+public:
+  void testName() {
+    TS_ASSERT_EQUALS(gsd.name(), "GeneralisedSecondDifference");
+  }
+
+  void testCategory() { TS_ASSERT_EQUALS(gsd.category(), "Arithmetic"); }
+
+  void testInit() {
+    TS_ASSERT_THROWS_NOTHING(gsd.initialize());
+    TS_ASSERT(gsd.isInitialized());
+  }
+
+  void testExec() {
+
+    std::vector<double> x =
+        boost::assign::list_of(0)(1)(2)(3)(4)(5)(6)(7)(8)(9);
+    std::vector<double> y = boost::assign::list_of(0.3)(0.3)(0.3)(0.47)(3.9)
+        (10.3)(3.9)(0.47)(0.3)(0.3);
+    MatrixWorkspace_sptr inputWs = WorkspaceFactory::Instance().create(
+        "Workspace2D", 1, y.size(), y.size());
+    inputWs->dataY(0) = y;
+    inputWs->dataX(0) = x;
+
+    gsd.setProperty("InputWorkspace", inputWs);
+    gsd.setProperty("M", "1");
+    gsd.setProperty("Z", "2");
+    gsd.setPropertyValue("OutputWorkspace", "secondDiff");
+
+    gsd.execute();
+    TS_ASSERT(gsd.isExecuted());
+
+    MatrixWorkspace_sptr outWs = Mantid::API::AnalysisDataService::Instance()
+                                     .retrieveWS<MatrixWorkspace>("secondDiff");
+    TS_ASSERT(outWs);
+
+    TS_ASSERT_EQUALS(outWs->getNumberHistograms(), 1);
+    TS_ASSERT_EQUALS(outWs->blocksize(), 4);
+
+    x = outWs->readX(0);
+    TS_ASSERT_EQUALS(x[0], 3);
+    TS_ASSERT_EQUALS(x[3], 6);
+
+    y = outWs->readY(0);
+    TS_ASSERT_DELTA(y[1], -7.0300, 0.0001);
+    TS_ASSERT_DELTA(y[2], -20.0000, 0.0001);
+
+    Mantid::API::AnalysisDataService::Instance().remove("secondDiff");
+  }
+
+private:
+  GeneralisedSecondDifference gsd;
+};
+
+#endif /* GENERALISEDSECONDDIFERENCETEST_H_ */
-- 
GitLab