diff --git a/Code/Mantid/Framework/CurveFitting/test/CalculateGammaBackgroundTest.h b/Code/Mantid/Framework/CurveFitting/test/CalculateGammaBackgroundTest.h index 089eb5ee690b..83a7193ded27 100644 --- a/Code/Mantid/Framework/CurveFitting/test/CalculateGammaBackgroundTest.h +++ b/Code/Mantid/Framework/CurveFitting/test/CalculateGammaBackgroundTest.h @@ -17,7 +17,7 @@ class CalculateGammaBackgroundTest : public CxxTest::TestSuite static void destroySuite( CalculateGammaBackgroundTest *suite ) { delete suite; } //------------------------------------ Success cases --------------------------------------- - void xtest_Input_With_Spectrum_Number_Inside_Forward_Scatter_Range_Gives_Expected_Correction() + void test_Input_With_Spectrum_Number_Inside_Forward_Scatter_Range_Gives_Expected_Correction() { using namespace Mantid::API; auto inputWS = createTestWorkspaceWithFoilChanger(); //specNo=1 @@ -148,7 +148,7 @@ class CalculateGammaBackgroundTest : public CxxTest::TestSuite //------------------------------------ Error cases --------------------------------------- - void xtest_Empty_Function_Property_Throws_Error() + void test_Empty_Function_Property_Throws_Error() { auto alg = createAlgorithm(); alg->setRethrows(true); @@ -158,7 +158,7 @@ class CalculateGammaBackgroundTest : public CxxTest::TestSuite TS_ASSERT(!alg->isExecuted()); } - void xtest_Function_Property_With_Single_Non_ComptonProfile_Throws_Error() + void test_Function_Property_With_Single_Non_ComptonProfile_Throws_Error() { auto alg = createAlgorithm(); alg->setRethrows(true); @@ -169,7 +169,7 @@ class CalculateGammaBackgroundTest : public CxxTest::TestSuite TS_ASSERT(!alg->isExecuted()); } - void xtest_Function_Property_With_Composite_Non_ComptonProfile_Throws_Error() + void test_Function_Property_With_Composite_Non_ComptonProfile_Throws_Error() { auto alg = createAlgorithm(); alg->setRethrows(true); @@ -210,19 +210,19 @@ class CalculateGammaBackgroundTest : public CxxTest::TestSuite Mantid::API::MatrixWorkspace_sptr createTestWorkspaceWithFoilChanger() { double x0(50.0),x1(300.0),dx(0.5); - return ComptonProfileTestHelpers::createSingleSpectrumWorkspace(x0,x1,dx, true,true); + return ComptonProfileTestHelpers::createTestWorkspace(1,x0,x1,dx, true,true); } Mantid::API::MatrixWorkspace_sptr createTestWorkspaceWithNoFoilChanger() { double x0(165.0),x1(166.0),dx(0.5); - return ComptonProfileTestHelpers::createSingleSpectrumWorkspace(x0,x1,dx,false); + return ComptonProfileTestHelpers::createTestWorkspace(1,x0,x1,dx,false); } Mantid::API::MatrixWorkspace_sptr createTwoSpectrumWorkspaceWithFoilChanger() { double x0(50.0),x1(300.0),dx(0.5); - auto singleSpectrum = ComptonProfileTestHelpers::createSingleSpectrumWorkspace(x0,x1,dx, true,true); + auto singleSpectrum = ComptonProfileTestHelpers::createTestWorkspace(1,x0,x1,dx, true,true); const size_t nhist = 2; auto twoSpectrum = Mantid::API::WorkspaceFactory::Instance().create(singleSpectrum, nhist); // Copy data diff --git a/Code/Mantid/Framework/CurveFitting/test/ComptonPeakProfileTest.h b/Code/Mantid/Framework/CurveFitting/test/ComptonPeakProfileTest.h index 1e52ccd2d9b8..6540e240f3d3 100644 --- a/Code/Mantid/Framework/CurveFitting/test/ComptonPeakProfileTest.h +++ b/Code/Mantid/Framework/CurveFitting/test/ComptonPeakProfileTest.h @@ -71,7 +71,7 @@ class ComptonPeakProfileTest : public CxxTest::TestSuite { Mantid::API::IFunction_sptr profile = boost::make_shared(); profile->initialize(); - auto paramWS = ComptonProfileTestHelpers::createSingleSpectrumWorkspace(300,351,0.5,true,true); // Only using for parameters + auto paramWS = ComptonProfileTestHelpers::createTestWorkspace(1,300,351,0.5,true,true); // Only using for parameters profile->setAttributeValue("Mass", 1.0079); TS_ASSERT_THROWS_NOTHING(profile->setWorkspace(paramWS)); profile->setUpForFit(); diff --git a/Code/Mantid/Framework/CurveFitting/test/ComptonProfileTestHelpers.h b/Code/Mantid/Framework/CurveFitting/test/ComptonProfileTestHelpers.h index 92342c3629ff..199fabefdd64 100644 --- a/Code/Mantid/Framework/CurveFitting/test/ComptonProfileTestHelpers.h +++ b/Code/Mantid/Framework/CurveFitting/test/ComptonProfileTestHelpers.h @@ -11,9 +11,9 @@ namespace ComptonProfileTestHelpers { // Forward declare all functions - static Mantid::API::MatrixWorkspace_sptr createSingleSpectrumWorkspace(const double x0, const double x1, - const double dx, const bool singleMassSpectrum = false, - const bool addFoilChanger = false); + static Mantid::API::MatrixWorkspace_sptr createTestWorkspace(const size_t nhist,const double x0, const double x1, + const double dx, const bool singleMassSpectrum = false, + const bool addFoilChanger = false); static Mantid::Geometry::Instrument_sptr createTestInstrumentWithFoilChanger(const Mantid::detid_t id,const Mantid::Kernel::V3D &); static Mantid::Geometry::Instrument_sptr createTestInstrumentWithNoFoilChanger(const Mantid::detid_t id, const Mantid::Kernel::V3D &); @@ -28,13 +28,11 @@ namespace ComptonProfileTestHelpers }; static Mantid::API::MatrixWorkspace_sptr - createSingleSpectrumWorkspace(const double x0, const double x1, const double dx, - const bool singleMassSpectrum,const bool addFoilChanger) + createTestWorkspace(const size_t nhist, const double x0, const double x1, const double dx, + const bool singleMassSpectrum,const bool addFoilChanger) { - int nhist(1); bool isHist(false); - - auto ws2d = WorkspaceCreationHelper::Create2DWorkspaceFromFunction(ones(), nhist, x0,x1,dx,isHist); + auto ws2d = WorkspaceCreationHelper::Create2DWorkspaceFromFunction(ones(), static_cast(nhist), x0,x1,dx,isHist); ws2d->getAxis(0)->setUnit("TOF"); if(singleMassSpectrum) { @@ -43,14 +41,17 @@ namespace ComptonProfileTestHelpers const double peakCentre(164.0), sigmaSq(16*16), peakHeight(0.2); const double noise(0.02); Mantid::Kernel::MersenneTwister mt1998(123456); - for(size_t i = 0; i < nvalues; ++i) + for(size_t i = 0; i < nhist; ++i) { - double x= ws2d->dataX(0)[i]; - double y = peakHeight * exp(-0.5*pow(x - peakCentre, 2.)/sigmaSq); - double r = mt1998.nextValue(); - if(r > 0.5) y += noise*r; - else y -= noise*r; - ws2d->dataY(0)[i] = y; + for(size_t j = 0; j < nvalues; ++j) + { + double x= ws2d->dataX(i)[j]; + double y = peakHeight * exp(-0.5*pow(x - peakCentre, 2.)/sigmaSq); + double r = mt1998.nextValue(); + if(r > 0.5) y += noise*r; + else y -= noise*r; + ws2d->dataY(i)[j] = y; + } } } @@ -78,11 +79,14 @@ namespace ComptonProfileTestHelpers } // Link workspace with detector - auto *spec0 = ws2d->getSpectrum(0); - spec0->setSpectrumNo(1); - spec0->clearDetectorIDs(); - spec0->addDetectorID(id); - + for(size_t i = 0; i < nhist; ++i) + { + const Mantid::specid_t specID = static_cast(id + i); + auto *spec = ws2d->getSpectrum(i); + spec->setSpectrumNo(specID); + spec->clearDetectorIDs(); + spec->addDetectorID(id); + } return ws2d; } diff --git a/Code/Mantid/Framework/CurveFitting/test/ComptonScatteringCountRateTest.h b/Code/Mantid/Framework/CurveFitting/test/ComptonScatteringCountRateTest.h index f73a649922e3..157472ec1562 100644 --- a/Code/Mantid/Framework/CurveFitting/test/ComptonScatteringCountRateTest.h +++ b/Code/Mantid/Framework/CurveFitting/test/ComptonScatteringCountRateTest.h @@ -56,7 +56,7 @@ class ComptonScatteringCountRateTest : public CxxTest::TestSuite using namespace Mantid::API; IFunction_sptr func = createFunctionNoBackground(); // No equality matrix set double x0(165.0),x1(166.0),dx(0.5); - auto testWS = ComptonProfileTestHelpers::createSingleSpectrumWorkspace(x0,x1,dx); + auto testWS = ComptonProfileTestHelpers::createTestWorkspace(1,x0,x1,dx); TS_ASSERT_THROWS_NOTHING(func->setWorkspace(testWS)); } @@ -66,7 +66,7 @@ class ComptonScatteringCountRateTest : public CxxTest::TestSuite using namespace Mantid::API; IFunction_sptr func = createFunctionNoBackground(); double x0(165.0),x1(166.0),dx(0.5); - auto testWS = ComptonProfileTestHelpers::createSingleSpectrumWorkspace(x0,x1,dx); + auto testWS = ComptonProfileTestHelpers::createTestWorkspace(1,x0,x1,dx); auto & dataX = testWS->dataX(0); std::transform(dataX.begin(), dataX.end(), dataX.begin(), std::bind2nd(std::multiplies(),1e-06)); // to seconds func->setWorkspace(testWS); @@ -86,7 +86,7 @@ class ComptonScatteringCountRateTest : public CxxTest::TestSuite using namespace Mantid::API; IFunction_sptr func = createFunctionWithBackground(); double x0(165.0),x1(166.0),dx(0.5); - auto testWS = ComptonProfileTestHelpers::createSingleSpectrumWorkspace(x0,x1,dx); + auto testWS = ComptonProfileTestHelpers::createTestWorkspace(1,x0,x1,dx); auto & dataX = testWS->dataX(0); std::transform(dataX.begin(), dataX.end(), dataX.begin(), std::bind2nd(std::multiplies(),1e-06)); // to seconds func->setWorkspace(testWS); @@ -108,7 +108,7 @@ class ComptonScatteringCountRateTest : public CxxTest::TestSuite using namespace Mantid::API; IFunction_sptr func = createFunctionNoBackground(); double x0(165.0),x1(166.0),dx(0.5); - auto testWS = ComptonProfileTestHelpers::createSingleSpectrumWorkspace(x0,x1,dx); + auto testWS = ComptonProfileTestHelpers::createTestWorkspace(1,x0,x1,dx); auto & dataX = testWS->dataX(0); std::transform(dataX.begin(), dataX.end(), dataX.begin(), std::bind2nd(std::multiplies(),1e-06)); // to seconds func->setWorkspace(testWS); @@ -127,7 +127,7 @@ class ComptonScatteringCountRateTest : public CxxTest::TestSuite func->setAttributeValue("IntensityConstraints", "Matrix(1|2)1|-2"); // I_1 = 2I_2 double x0(165.0),x1(166.0),dx(0.5); - auto testWS = ComptonProfileTestHelpers::createSingleSpectrumWorkspace(x0,x1,dx); + auto testWS = ComptonProfileTestHelpers::createTestWorkspace(1,x0,x1,dx); auto & dataX = testWS->dataX(0); std::transform(dataX.begin(), dataX.end(), dataX.begin(), std::bind2nd(std::multiplies(),1e-06)); // to seconds func->setWorkspace(testWS); @@ -146,7 +146,7 @@ class ComptonScatteringCountRateTest : public CxxTest::TestSuite IFunction_sptr func = createFunctionNoBackground(useTwoIntensityFuncAsFirst); double x0(165.0),x1(166.0),dx(0.5); - auto testWS = ComptonProfileTestHelpers::createSingleSpectrumWorkspace(x0,x1,dx); + auto testWS = ComptonProfileTestHelpers::createTestWorkspace(1,x0,x1,dx); auto & dataX = testWS->dataX(0); std::transform(dataX.begin(), dataX.end(), dataX.begin(), std::bind2nd(std::multiplies(),1e-06)); // to seconds @@ -168,7 +168,7 @@ class ComptonScatteringCountRateTest : public CxxTest::TestSuite func->setAttributeValue("IntensityConstraints", "Matrix(1|2)1|-2"); // I_1 = 2I_2 double x0(165.0),x1(166.0),dx(0.5); - auto testWS = ComptonProfileTestHelpers::createSingleSpectrumWorkspace(x0,x1,dx); + auto testWS = ComptonProfileTestHelpers::createTestWorkspace(1,x0,x1,dx); auto & dataX = testWS->dataX(0); std::transform(dataX.begin(), dataX.end(), dataX.begin(), std::bind2nd(std::multiplies(),1e-06)); // to seconds diff --git a/Code/Mantid/Framework/CurveFitting/test/ConvertToYSpaceTest.h b/Code/Mantid/Framework/CurveFitting/test/ConvertToYSpaceTest.h index 1b970cafe395..9a9b2bbcfe45 100644 --- a/Code/Mantid/Framework/CurveFitting/test/ConvertToYSpaceTest.h +++ b/Code/Mantid/Framework/CurveFitting/test/ConvertToYSpaceTest.h @@ -31,7 +31,7 @@ class ConvertToYSpaceTest : public CxxTest::TestSuite auto alg = createAlgorithm(); double x0(50.0),x1(300.0),dx(0.5); - auto testWS = ComptonProfileTestHelpers::createSingleSpectrumWorkspace(x0,x1,dx, true,true); + auto testWS = ComptonProfileTestHelpers::createTestWorkspace(1,x0,x1,dx, true,true); alg->setProperty("InputWorkspace", testWS); alg->setProperty("Mass", 1.0097); alg->execute(); diff --git a/Code/Mantid/Framework/CurveFitting/test/GaussianComptonProfileTest.h b/Code/Mantid/Framework/CurveFitting/test/GaussianComptonProfileTest.h index a2bb6581b76d..f69d6ca48790 100644 --- a/Code/Mantid/Framework/CurveFitting/test/GaussianComptonProfileTest.h +++ b/Code/Mantid/Framework/CurveFitting/test/GaussianComptonProfileTest.h @@ -82,7 +82,7 @@ class GaussianComptonProfileTest : public CxxTest::TestSuite auto func = createFunctionWithParamsSet(); double x0(370.0),x1(371.0),dx(0.5); //chosen to give put us near the peak for this mass & spectrum - auto testWS = ComptonProfileTestHelpers::createSingleSpectrumWorkspace(x0,x1,dx); + auto testWS = ComptonProfileTestHelpers::createTestWorkspace(1,x0,x1,dx); auto & dataX = testWS->dataX(0); std::transform(dataX.begin(), dataX.end(), dataX.begin(), std::bind2nd(std::multiplies(),1e-06)); // to seconds func->setWorkspace(testWS); diff --git a/Code/Mantid/Framework/CurveFitting/test/GramCharlierComptonProfileTest.h b/Code/Mantid/Framework/CurveFitting/test/GramCharlierComptonProfileTest.h index 822437947ce5..f120a3d18e7e 100644 --- a/Code/Mantid/Framework/CurveFitting/test/GramCharlierComptonProfileTest.h +++ b/Code/Mantid/Framework/CurveFitting/test/GramCharlierComptonProfileTest.h @@ -79,7 +79,7 @@ class GramCharlierComptonProfileTest : public CxxTest::TestSuite auto func = createFunctionWithParamsSet(); double x0(165.0),x1(166.0),dx(0.5); //chosen to give put us near the peak for this mass & spectrum - auto testWS = ComptonProfileTestHelpers::createSingleSpectrumWorkspace(x0,x1,dx); + auto testWS = ComptonProfileTestHelpers::createTestWorkspace(1,x0,x1,dx); auto & dataX = testWS->dataX(0); std::transform(dataX.begin(), dataX.end(), dataX.begin(), std::bind2nd(std::multiplies(),1e-06)); // to seconds func->setWorkspace(testWS);