From b6d19f39658ad3aba44309d9898a850b8cb7df28 Mon Sep 17 00:00:00 2001
From: Samuel Jackson <samuel.jackson@stfc.ac.uk>
Date: Thu, 13 Mar 2014 12:01:25 +0000
Subject: [PATCH] Refs #9174 Add unit test for new options.

---
 .../test/PlotPeakByLogValueTest.h             | 78 +++++++++++++++++++
 1 file changed, 78 insertions(+)

diff --git a/Code/Mantid/Framework/CurveFitting/test/PlotPeakByLogValueTest.h b/Code/Mantid/Framework/CurveFitting/test/PlotPeakByLogValueTest.h
index a4b8a125c48..b194f691b94 100644
--- a/Code/Mantid/Framework/CurveFitting/test/PlotPeakByLogValueTest.h
+++ b/Code/Mantid/Framework/CurveFitting/test/PlotPeakByLogValueTest.h
@@ -15,6 +15,7 @@
 #include "MantidAPI/FunctionFactory.h"
 #include "MantidAPI/WorkspaceGroup.h"
 #include "MantidKernel/TimeSeriesProperty.h"
+#include "MantidKernel/UnitFactory.h"
 
 #include "MantidTestHelpers/WorkspaceCreationHelper.h"
 #include <sstream>
@@ -389,6 +390,53 @@ public:
     TS_ASSERT( fits->getNames().size() == 3 );
   }
 
+
+  void test_createOutputWithExtraOutputOptions()
+  {
+    auto ws = createTestWorkspace();
+    AnalysisDataService::Instance().add( "PLOTPEAKBYLOGVALUETEST_WS", ws );
+    PlotPeakByLogValue alg;
+    alg.initialize();
+    alg.setPropertyValue("Input","PLOTPEAKBYLOGVALUETEST_WS,v0:2");
+    alg.setPropertyValue("OutputWorkspace","PlotPeakResult");
+    alg.setProperty("PassWSIndexToFunction",true);
+    alg.setProperty("CreateOutput", true);
+    alg.setProperty("OutputCompositeMembers", true);
+    alg.setProperty("ConvolveMembers", true);
+    alg.setPropertyValue("Function","name=LinearBackground,A0=0,A1=0;"
+      "(composite=Convolution,FixResolution=true,NumDeriv=true;"
+      "name=Resolution,Workspace=PLOTPEAKBYLOGVALUETEST_WS,WorkspaceIndex=0;"
+      "name=Gaussian,Height=3000,PeakCentre=6493,Sigma=50;);");
+    alg.execute();
+
+    TS_ASSERT( alg.isExecuted() );
+
+    TWS_type result =  WorkspaceCreationHelper::getWS<TableWorkspace>("PlotPeakResult");
+    TS_ASSERT( result );
+
+    auto matrices = AnalysisDataService::Instance().retrieveWS<const WorkspaceGroup>("PlotPeakResult_NormalisedCovarianceMatrices");
+    auto params = AnalysisDataService::Instance().retrieveWS<const WorkspaceGroup>("PlotPeakResult_Parameters");
+    auto fits = AnalysisDataService::Instance().retrieveWS<const WorkspaceGroup>("PlotPeakResult_Workspaces");
+
+    TS_ASSERT( matrices );
+    TS_ASSERT( params );
+    TS_ASSERT( fits );
+
+    TS_ASSERT( matrices->getNames().size() == 2 );
+    TS_ASSERT( params->getNames().size() == 2 );
+    TS_ASSERT( fits->getNames().size() == 2 );
+
+    auto wsNames = fits->getNames();
+    for (size_t i=0; i< wsNames.size(); ++i)
+    {
+      auto fit = AnalysisDataService::Instance().retrieveWS<const MatrixWorkspace>(wsNames[i]);
+      TS_ASSERT( fit );
+      TS_ASSERT( fit->getNumberHistograms() == 5);
+    } 
+
+    AnalysisDataService::Instance().clear();
+  }
+
 private:
 
   WorkspaceGroup_sptr m_wsg;
@@ -415,6 +463,36 @@ private:
     }
   }
 
+  MatrixWorkspace_sptr createTestWorkspace()
+  {
+    const int numHists(2);
+    const int numBins(2000);
+    MatrixWorkspace_sptr testWS = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument(numHists, numBins, true);
+    testWS->getAxis(0)->unit() = Mantid::Kernel::UnitFactory::Instance().create("TOF");
+    MantidVecPtr xdata;
+    xdata.access().resize(numBins+1);
+    // Update X data  to a sensible values. Looks roughly like the MARI binning
+    // Update the Y values. We don't care about errors here
+
+    // We'll simply use a gaussian as a test
+    const double peakOneCentre(6493.0), sigmaSqOne(250*250.), peakTwoCentre(10625.), sigmaSqTwo(50*50);
+    const double peakOneHeight(3000.), peakTwoHeight(1000.);
+    for( int i = 0; i <= numBins; ++i)
+    {
+      const double xValue = 5.0 + 5.5*i;
+      if( i < numBins )
+      {
+        testWS->dataY(0)[i] = peakOneHeight * exp(-0.5*pow(xValue - peakOneCentre, 2.)/sigmaSqOne);
+        testWS->dataY(1)[i] = peakTwoHeight * exp(-0.5*pow(xValue - peakTwoCentre, 2.)/sigmaSqTwo);
+
+      }
+      xdata.access()[i] = xValue;
+    }    
+    testWS->setX(0, xdata);
+    testWS->setX(1, xdata);
+    return testWS;
+  }
+
   void deleteData()
   {
     FrameworkManager::Instance().deleteWorkspace(m_wsg->getName());
-- 
GitLab