diff --git a/Code/Mantid/Framework/Algorithms/CMakeLists.txt b/Code/Mantid/Framework/Algorithms/CMakeLists.txt index 998032e0216af09c2d044d7207dce14546202df4..952d2eb79bd508a9eed6305133086ce39a1663e3 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 0000000000000000000000000000000000000000..f696a74d262f923cc8bd42b42694b043bd850bb8 --- /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_ */