From f556671eb3e771f80049db36f38b337b40e1c2be Mon Sep 17 00:00:00 2001 From: Gemma Guest Date: Mon, 17 Jul 2017 15:13:40 +0100 Subject: [PATCH 01/11] Refs #8394 Added test and validator creation. Added commented out BoundedValidator creation to NumSteps property of PeakIntensityVsRadius. --- Framework/Crystal/src/PeakIntensityVsRadius.cpp | 7 +++++-- Framework/Crystal/test/PeakIntensityVsRadiusTest.h | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Framework/Crystal/src/PeakIntensityVsRadius.cpp b/Framework/Crystal/src/PeakIntensityVsRadius.cpp index 25841bb6b620..aa1728f3edd6 100644 --- a/Framework/Crystal/src/PeakIntensityVsRadius.cpp +++ b/Framework/Crystal/src/PeakIntensityVsRadius.cpp @@ -6,7 +6,8 @@ #include "MantidAPI/TextAxis.h" #include "MantidAPI/WorkspaceFactory.h" -#include "MantidKernel/ListValidator.h" +#include "MantidKernel/BoundedValidator.h" + #include "MantidKernel/Strings.h" using namespace Mantid::Kernel; @@ -49,8 +50,10 @@ void PeakIntensityVsRadius::init() { declareProperty("RadiusStart", 0.0, "Radius at which to start integrating."); declareProperty("RadiusEnd", 1.0, "Radius at which to stop integrating."); + // auto mustBePositive = boost::make_shared>(); + // mustBePositive->setLower(0); declareProperty( - "NumSteps", 10, + "NumSteps", 10, // mustBePositive, "Number of steps, between start and end, to calculate radius."); declareProperty( diff --git a/Framework/Crystal/test/PeakIntensityVsRadiusTest.h b/Framework/Crystal/test/PeakIntensityVsRadiusTest.h index 9cae1b19c9f0..1970763ea619 100644 --- a/Framework/Crystal/test/PeakIntensityVsRadiusTest.h +++ b/Framework/Crystal/test/PeakIntensityVsRadiusTest.h @@ -70,7 +70,7 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { /** Check the validateInputs() calls */ void doTestValid(bool pass, double BackgroundInnerFactor, double BackgroundOuterFactor, double BackgroundInnerRadius, - double BackgroundOuterRadius) { + double BackgroundOuterRadius, int NumSteps = 16) { PeakIntensityVsRadius alg; TS_ASSERT_THROWS_NOTHING(alg.initialize()) TS_ASSERT(alg.isInitialized()) @@ -82,7 +82,7 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { "OutputWorkspace", "PeakIntensityVsRadiusTest_OutputWS")); TS_ASSERT_THROWS_NOTHING(alg.setProperty("RadiusStart", 0.0)); TS_ASSERT_THROWS_NOTHING(alg.setProperty("RadiusEnd", 1.5)); - TS_ASSERT_THROWS_NOTHING(alg.setProperty("NumSteps", 16)); + TS_ASSERT_THROWS_NOTHING(alg.setProperty("NumSteps", NumSteps)); TS_ASSERT_THROWS_NOTHING( alg.setProperty("BackgroundInnerFactor", BackgroundInnerFactor)); TS_ASSERT_THROWS_NOTHING( @@ -108,6 +108,7 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { doTestValid(false, 0, 1.0, 0, 0.15); doTestValid(false, 1.0, 0, 0.15, 0); doTestValid(false, 1.0, 1.0, 0.12, 0.15); + doTestValid(true, 1.0, 2.0, 0, 0, -8); } MatrixWorkspace_sptr doTest(double BackgroundInnerFactor, @@ -192,6 +193,8 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { TSM_ASSERT_DELTA("After 1.0, the signal is flat", ws->y(0)[12], 1000, 1e-6); TSM_ASSERT_DELTA("After 1.0, the signal is flat", ws->y(0)[15], 1000, 1e-6); } + + void test }; #endif /* MANTID_CRYSTAL_PEAKINTENSITYVSRADIUSTEST_H_ */ From d801745aa1f38bdec6ad3d2d56c75b2c1b3e5df4 Mon Sep 17 00:00:00 2001 From: Gemma Guest Date: Mon, 17 Jul 2017 16:13:03 +0100 Subject: [PATCH 02/11] Updated PeakIntensityVsRadius usage instructions. --- docs/source/algorithms/PeakIntensityVsRadius-v1.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/source/algorithms/PeakIntensityVsRadius-v1.rst b/docs/source/algorithms/PeakIntensityVsRadius-v1.rst index d6179a78564e..3c2dfb61ec14 100644 --- a/docs/source/algorithms/PeakIntensityVsRadius-v1.rst +++ b/docs/source/algorithms/PeakIntensityVsRadius-v1.rst @@ -46,6 +46,12 @@ with the following parameters filled in: Usage ----- +**Example - PeakIntensityVsRadius:** + +The code itself works but disabled from doc tests as takes too long to complete. User should provide its own +event nexus file instead of **TOPAZ_3132_event.nxs** used within this example. The original **TOPAZ_3132_event.nxs** +file is availible in `Mantid system tests repository `_. + .. code-block:: python # Load a SCD data set from systemtests Data and find the peaks From d2a3b59a8b181ae02a56f7960ad638f78fa72d39 Mon Sep 17 00:00:00 2001 From: Gemma Guest Date: Mon, 17 Jul 2017 16:36:20 +0100 Subject: [PATCH 03/11] Refs #8394 Added failing unit test. Added new methods, doTestThrowsForInvalid and doTestNoThrowForValid to make unit tests clearer. Added extra test which ensures that validateInput throws when passed a negative value for the NumSteps property. --- .../Crystal/test/PeakIntensityVsRadiusTest.h | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/Framework/Crystal/test/PeakIntensityVsRadiusTest.h b/Framework/Crystal/test/PeakIntensityVsRadiusTest.h index 1970763ea619..650eebf5a562 100644 --- a/Framework/Crystal/test/PeakIntensityVsRadiusTest.h +++ b/Framework/Crystal/test/PeakIntensityVsRadiusTest.h @@ -70,7 +70,7 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { /** Check the validateInputs() calls */ void doTestValid(bool pass, double BackgroundInnerFactor, double BackgroundOuterFactor, double BackgroundInnerRadius, - double BackgroundOuterRadius, int NumSteps = 16) { + double BackgroundOuterRadius, int NumSteps) { PeakIntensityVsRadius alg; TS_ASSERT_THROWS_NOTHING(alg.initialize()) TS_ASSERT(alg.isInitialized()) @@ -98,17 +98,32 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { } } - void test_validateInputs() { - doTestValid(true, 1.0, 2.0, 0, 0); - doTestValid(true, 0, 0, 0.12, 0.15); - doTestValid(true, 1.0, 0, 0, 0.15); - doTestValid(true, 0, 1.5, 0.15, 0); + void doTestThrowsForInvalid(double BackgroundInnerFactor, + double BackgroundOuterFactor, double BackgroundInnerRadius, + double BackgroundOuterRadius, int NumSteps = 16) { + doTestValid(false, BackgroundInnerFactor, BackgroundOuterFactor, BackgroundInnerRadius, BackgroundOuterRadius, NumSteps); + } + + void doTestNoThrowForValid(double BackgroundInnerFactor, + double BackgroundOuterFactor, double BackgroundInnerRadius, + double BackgroundOuterRadius, int NumSteps = 16) { + doTestValid(true, BackgroundInnerFactor, BackgroundOuterFactor, BackgroundInnerRadius, BackgroundOuterRadius, NumSteps); + } + + void test_validateForValidInputs() { + doTestNoThrowForValid(1.0, 2.0, 0, 0); + doTestNoThrowForValid(0, 0, 0.12, 0.15); + doTestNoThrowForValid(1.0, 0, 0, 0.15); + doTestNoThrowForValid(0, 1.5, 0.15, 0); // Can't specify fixed and variable - doTestValid(false, 1.0, 0, 0.15, 0); - doTestValid(false, 0, 1.0, 0, 0.15); - doTestValid(false, 1.0, 0, 0.15, 0); - doTestValid(false, 1.0, 1.0, 0.12, 0.15); - doTestValid(true, 1.0, 2.0, 0, 0, -8); + } + + void test_validateForInvalidInputs() { + doTestThrowsForInvalid(1.0, 0, 0.15, 0); + doTestThrowsForInvalid(0, 1.0, 0, 0.15); + doTestThrowsForInvalid(1.0, 0, 0.15, 0); + doTestThrowsForInvalid(1.0, 1.0, 0.12, 0.15); + doTestThrowsForInvalid(1.0, 2.0, 0, 0, -8); } MatrixWorkspace_sptr doTest(double BackgroundInnerFactor, @@ -194,7 +209,6 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { TSM_ASSERT_DELTA("After 1.0, the signal is flat", ws->y(0)[15], 1000, 1e-6); } - void test }; #endif /* MANTID_CRYSTAL_PEAKINTENSITYVSRADIUSTEST_H_ */ From 6d2c93a35b6648b0852502028e891fb43d1f3bf6 Mon Sep 17 00:00:00 2001 From: Edward Brown Date: Thu, 20 Jul 2017 09:30:42 +0100 Subject: [PATCH 04/11] Re #8394 Removed assertion duplication. Many assertions were repeated in two of the PeakIntensityVsRadiusTests. They have been extracted into macros which broadly describe what they do. --- .../Crystal/test/PeakIntensityVsRadiusTest.h | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/Framework/Crystal/test/PeakIntensityVsRadiusTest.h b/Framework/Crystal/test/PeakIntensityVsRadiusTest.h index 650eebf5a562..97170b42f92b 100644 --- a/Framework/Crystal/test/PeakIntensityVsRadiusTest.h +++ b/Framework/Crystal/test/PeakIntensityVsRadiusTest.h @@ -1,9 +1,10 @@ #ifndef MANTID_CRYSTAL_PEAKINTENSITYVSRADIUSTEST_H_ #define MANTID_CRYSTAL_PEAKINTENSITYVSRADIUSTEST_H_ -#include "MantidCrystal/PeakIntensityVsRadius.h" #include "MantidAPI/AnalysisDataService.h" +#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/MatrixWorkspace.h" +#include "MantidCrystal/PeakIntensityVsRadius.h" #include "MantidDataObjects/Peak.h" #include "MantidDataObjects/PeaksWorkspace.h" #include "MantidGeometry/Instrument.h" @@ -11,7 +12,6 @@ #include "MantidKernel/Timer.h" #include "MantidKernel/V3D.h" #include "MantidTestHelpers/ComponentCreationHelper.h" -#include "MantidAPI/FrameworkManager.h" #include using namespace Mantid; @@ -99,15 +99,19 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { } void doTestThrowsForInvalid(double BackgroundInnerFactor, - double BackgroundOuterFactor, double BackgroundInnerRadius, - double BackgroundOuterRadius, int NumSteps = 16) { - doTestValid(false, BackgroundInnerFactor, BackgroundOuterFactor, BackgroundInnerRadius, BackgroundOuterRadius, NumSteps); + double BackgroundOuterFactor, + double BackgroundInnerRadius, + double BackgroundOuterRadius, int NumSteps = 16) { + doTestValid(false, BackgroundInnerFactor, BackgroundOuterFactor, + BackgroundInnerRadius, BackgroundOuterRadius, NumSteps); } void doTestNoThrowForValid(double BackgroundInnerFactor, - double BackgroundOuterFactor, double BackgroundInnerRadius, - double BackgroundOuterRadius, int NumSteps = 16) { - doTestValid(true, BackgroundInnerFactor, BackgroundOuterFactor, BackgroundInnerRadius, BackgroundOuterRadius, NumSteps); + double BackgroundOuterFactor, + double BackgroundInnerRadius, + double BackgroundOuterRadius, int NumSteps = 16) { + doTestValid(true, BackgroundInnerFactor, BackgroundOuterFactor, + BackgroundInnerRadius, BackgroundOuterRadius, NumSteps); } void test_validateForValidInputs() { @@ -165,6 +169,10 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { return ws; } +#define TS_ASSERT_FLAT_AFTER_1(ws) \ + TSM_ASSERT_DELTA("After 1.0, the signal is flat", ws->y(0)[12], 1000, 1e-6); \ + TSM_ASSERT_DELTA("After 1.0, the signal is flat", ws->y(0)[15], 1000, 1e-6) + void test_NoBackground() { MatrixWorkspace_sptr ws = doTest(0, 0, 0, 0); // Check the results @@ -174,23 +182,24 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { TS_ASSERT_DELTA(ws->x(0)[2], 0.2, 1e-6); TS_ASSERT_LESS_THAN(ws->y(0)[5], 1000); - TSM_ASSERT_DELTA("After 1.0, the signal is flat", ws->y(0)[12], 1000, 1e-6); - TSM_ASSERT_DELTA("After 1.0, the signal is flat", ws->y(0)[15], 1000, 1e-6); + TS_ASSERT_FLAT_AFTER_1(ws); } +#define TS_ASSERT_FIRST_FOUR_Y_VALUES_CLOSE_TO_ZERO(ws) \ + TS_ASSERT_DELTA(ws->y(0)[0], 0, 10); \ + TS_ASSERT_DELTA(ws->y(0)[1], 0, 10); \ + TS_ASSERT_DELTA(ws->y(0)[2], 0, 10); \ + TS_ASSERT_DELTA(ws->y(0)[3], 0, 10) + void test_VariableBackground() { MatrixWorkspace_sptr ws = doTest(1.0, 2.0, 0, 0); // Check the results TSM_ASSERT_EQUALS("Two peaks", ws->getNumberHistograms(), 2); + TS_ASSERT_FIRST_FOUR_Y_VALUES_CLOSE_TO_ZERO(ws); // Points before 0.5 are approximately zero because the background shell is // in the peak. - TS_ASSERT_DELTA(ws->y(0)[0], 0, 10); - TS_ASSERT_DELTA(ws->y(0)[1], 0, 10); - TS_ASSERT_DELTA(ws->y(0)[2], 0, 10); - TS_ASSERT_DELTA(ws->y(0)[3], 0, 10); - TSM_ASSERT_DELTA("After 1.0, the signal is flat", ws->y(0)[12], 1000, 1e-6); - TSM_ASSERT_DELTA("After 1.0, the signal is flat", ws->y(0)[15], 1000, 1e-6); + TS_ASSERT_FLAT_AFTER_1(ws); } void test_FixedBackground() { @@ -201,14 +210,9 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { // Points before 0.5 are approximately zero because the background shell is // in the peak. - TS_ASSERT_DELTA(ws->y(0)[0], 0, 10); - TS_ASSERT_DELTA(ws->y(0)[1], 0, 10); - TS_ASSERT_DELTA(ws->y(0)[2], 0, 10); - TS_ASSERT_DELTA(ws->y(0)[3], 0, 10); - TSM_ASSERT_DELTA("After 1.0, the signal is flat", ws->y(0)[12], 1000, 1e-6); - TSM_ASSERT_DELTA("After 1.0, the signal is flat", ws->y(0)[15], 1000, 1e-6); + TS_ASSERT_FIRST_FOUR_Y_VALUES_CLOSE_TO_ZERO(ws); + TS_ASSERT_FLAT_AFTER_1(ws); } - }; #endif /* MANTID_CRYSTAL_PEAKINTENSITYVSRADIUSTEST_H_ */ From 9cbd103f84956ea4a449e3e3a897c1f002187d7f Mon Sep 17 00:00:00 2001 From: Edward Brown Date: Thu, 20 Jul 2017 10:04:32 +0100 Subject: [PATCH 05/11] Re #8394 Removed further assertion duplication. - Removed duplicated ASSERT_THROWS_NOTHINGs for algorithm property setters. - Removed duplicated ASSERT_THROWS_NOTHING and ASSERT for initialization of the algorithm object. --- .../Crystal/test/PeakIntensityVsRadiusTest.h | 62 +++++++++---------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/Framework/Crystal/test/PeakIntensityVsRadiusTest.h b/Framework/Crystal/test/PeakIntensityVsRadiusTest.h index 97170b42f92b..b7f59cb7fa6e 100644 --- a/Framework/Crystal/test/PeakIntensityVsRadiusTest.h +++ b/Framework/Crystal/test/PeakIntensityVsRadiusTest.h @@ -67,31 +67,20 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { "PeakIntensityVsRadiusTest_peaks", peakWS); } +#define TS_ASSERT_SUCCESSFUL_INITIALZATION(alg) \ + TS_ASSERT_THROWS_NOTHING(alg.initialize()) \ + TS_ASSERT(alg.isInitialized()) + /** Check the validateInputs() calls */ - void doTestValid(bool pass, double BackgroundInnerFactor, + void doTestValid(bool assertExecuteSuccess, double BackgroundInnerFactor, double BackgroundOuterFactor, double BackgroundInnerRadius, double BackgroundOuterRadius, int NumSteps) { PeakIntensityVsRadius alg; - TS_ASSERT_THROWS_NOTHING(alg.initialize()) - TS_ASSERT(alg.isInitialized()) - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue( - "InputWorkspace", "PeakIntensityVsRadiusTest_MDEWS")); - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue( - "PeaksWorkspace", "PeakIntensityVsRadiusTest_peaks")); - TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue( - "OutputWorkspace", "PeakIntensityVsRadiusTest_OutputWS")); - TS_ASSERT_THROWS_NOTHING(alg.setProperty("RadiusStart", 0.0)); - TS_ASSERT_THROWS_NOTHING(alg.setProperty("RadiusEnd", 1.5)); - TS_ASSERT_THROWS_NOTHING(alg.setProperty("NumSteps", NumSteps)); - TS_ASSERT_THROWS_NOTHING( - alg.setProperty("BackgroundInnerFactor", BackgroundInnerFactor)); - TS_ASSERT_THROWS_NOTHING( - alg.setProperty("BackgroundOuterFactor", BackgroundOuterFactor)); - TS_ASSERT_THROWS_NOTHING( - alg.setProperty("BackgroundInnerRadius", BackgroundInnerRadius)); - TS_ASSERT_THROWS_NOTHING( - alg.setProperty("BackgroundOuterRadius", BackgroundOuterRadius)); - if (!pass) { + TS_ASSERT_SUCCESSFUL_INITIALZATION(alg); + assertNoThrowWhenSettingProperties( + BackgroundInnerFactor, BackgroundOuterFactor, BackgroundInnerRadius, + BackgroundOuterRadius, NumSteps); + if (!assertExecuteSuccess) { TS_ASSERT_THROWS_ANYTHING(alg.execute();); } else { TS_ASSERT_THROWS_NOTHING(alg.execute();); @@ -130,16 +119,10 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { doTestThrowsForInvalid(1.0, 2.0, 0, 0, -8); } - MatrixWorkspace_sptr doTest(double BackgroundInnerFactor, - double BackgroundOuterFactor, - double BackgroundInnerRadius, - double BackgroundOuterRadius) { - // Name of the output workspace. - std::string outWSName("PeakIntensityVsRadiusTest_OutputWS"); - - PeakIntensityVsRadius alg; - TS_ASSERT_THROWS_NOTHING(alg.initialize()) - TS_ASSERT(alg.isInitialized()) + void assertNoThrowWhenSettingProperties( + std::string &outWsName, double BackgroundInnerFactor, + double BackgroundOuterFactor, double BackgroundInnerRadius, + double BackgroundOuterRadius int NumSteps) { TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue( "InputWorkspace", "PeakIntensityVsRadiusTest_MDEWS")); TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue( @@ -148,7 +131,7 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { alg.setPropertyValue("OutputWorkspace", outWSName)); TS_ASSERT_THROWS_NOTHING(alg.setProperty("RadiusStart", 0.0)); TS_ASSERT_THROWS_NOTHING(alg.setProperty("RadiusEnd", 1.5)); - TS_ASSERT_THROWS_NOTHING(alg.setProperty("NumSteps", 16)); + TS_ASSERT_THROWS_NOTHING(alg.setProperty("NumSteps", NumSteps)); TS_ASSERT_THROWS_NOTHING( alg.setProperty("BackgroundInnerFactor", BackgroundInnerFactor)); TS_ASSERT_THROWS_NOTHING( @@ -158,6 +141,21 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { TS_ASSERT_THROWS_NOTHING( alg.setProperty("BackgroundOuterRadius", BackgroundOuterRadius)); TS_ASSERT_THROWS_NOTHING(alg.execute();); + } + + MatrixWorkspace_sptr doTest(double BackgroundInnerFactor, + double BackgroundOuterFactor, + double BackgroundInnerRadius, + double BackgroundOuterRadius, int NumSteps = 16) { + // Name of the output workspace. + std::string outWSName("PeakIntensityVsRadiusTest_OutputWS"); + + PeakIntensityVsRadius alg; + TS_ASSERT_SUCCESSFUL_INITIALZATION(alg); + assertNoThrowWhenSettingProperties( + BackgroundInnerFactor, BackgroundOuterFactor, BackgroundInnerRadius, + BackgroundOuterRadius, NumSteps); + TS_ASSERT_THROWS_NOTHING(alg.execute();); TS_ASSERT(alg.isExecuted()); // Retrieve the workspace from data service. From 8370465f492557aa9bbfbdec42f564c3ec04f79e Mon Sep 17 00:00:00 2001 From: Edward Brown Date: Thu, 20 Jul 2017 12:11:56 +0100 Subject: [PATCH 06/11] Re #8394 Contined Refactoring and Added Failing Test. - Continued to refactor and eliminate duplication from PeakIntensityVsRadius unit tests. - Converted added assertion macros to proper functions. - Added failing unit test to prove lack of validator. --- .../Crystal/src/PeakIntensityVsRadius.cpp | 6 +- .../Crystal/test/PeakIntensityVsRadiusTest.h | 118 ++++++++++-------- 2 files changed, 72 insertions(+), 52 deletions(-) diff --git a/Framework/Crystal/src/PeakIntensityVsRadius.cpp b/Framework/Crystal/src/PeakIntensityVsRadius.cpp index aa1728f3edd6..e4d01f54882f 100644 --- a/Framework/Crystal/src/PeakIntensityVsRadius.cpp +++ b/Framework/Crystal/src/PeakIntensityVsRadius.cpp @@ -50,10 +50,10 @@ void PeakIntensityVsRadius::init() { declareProperty("RadiusStart", 0.0, "Radius at which to start integrating."); declareProperty("RadiusEnd", 1.0, "Radius at which to stop integrating."); - // auto mustBePositive = boost::make_shared>(); - // mustBePositive->setLower(0); + auto mustBePositive = boost::make_shared>(); + mustBePositive->setLower(0); declareProperty( - "NumSteps", 10, // mustBePositive, + "NumSteps", 10,// mustBePositive, "Number of steps, between start and end, to calculate radius."); declareProperty( diff --git a/Framework/Crystal/test/PeakIntensityVsRadiusTest.h b/Framework/Crystal/test/PeakIntensityVsRadiusTest.h index b7f59cb7fa6e..929a9da90e5d 100644 --- a/Framework/Crystal/test/PeakIntensityVsRadiusTest.h +++ b/Framework/Crystal/test/PeakIntensityVsRadiusTest.h @@ -67,62 +67,79 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { "PeakIntensityVsRadiusTest_peaks", peakWS); } -#define TS_ASSERT_SUCCESSFUL_INITIALZATION(alg) \ - TS_ASSERT_THROWS_NOTHING(alg.initialize()) \ - TS_ASSERT(alg.isInitialized()) + void assertSuccessfulInitialization(PeakIntensityVsRadius &alg) { + TS_ASSERT_THROWS_NOTHING(alg.initialize()); + TS_ASSERT(alg.isInitialized()) + } /** Check the validateInputs() calls */ void doTestValid(bool assertExecuteSuccess, double BackgroundInnerFactor, double BackgroundOuterFactor, double BackgroundInnerRadius, double BackgroundOuterRadius, int NumSteps) { PeakIntensityVsRadius alg; - TS_ASSERT_SUCCESSFUL_INITIALZATION(alg); + // Name of the output workspace. + std::string outWSName("PeakIntensityVsRadiusTest_OutputWS"); + assertSuccessfulInitialization(alg); assertNoThrowWhenSettingProperties( - BackgroundInnerFactor, BackgroundOuterFactor, BackgroundInnerRadius, - BackgroundOuterRadius, NumSteps); - if (!assertExecuteSuccess) { - TS_ASSERT_THROWS_ANYTHING(alg.execute();); - } else { + alg, outWSName, BackgroundInnerFactor, BackgroundOuterFactor, + BackgroundInnerRadius, BackgroundOuterRadius, NumSteps); + if (assertExecuteSuccess) { TS_ASSERT_THROWS_NOTHING(alg.execute();); + } else { + TS_ASSERT_THROWS_ANYTHING(alg.execute();); } } - void doTestThrowsForInvalid(double BackgroundInnerFactor, - double BackgroundOuterFactor, - double BackgroundInnerRadius, - double BackgroundOuterRadius, int NumSteps = 16) { + void ensureExecutionThrows(double BackgroundInnerFactor, + double BackgroundOuterFactor, + double BackgroundInnerRadius, + double BackgroundOuterRadius, int NumSteps = 16) { doTestValid(false, BackgroundInnerFactor, BackgroundOuterFactor, BackgroundInnerRadius, BackgroundOuterRadius, NumSteps); } - void doTestNoThrowForValid(double BackgroundInnerFactor, - double BackgroundOuterFactor, - double BackgroundInnerRadius, - double BackgroundOuterRadius, int NumSteps = 16) { + void ensureExecutionNoThrow(double BackgroundInnerFactor, + double BackgroundOuterFactor, + double BackgroundInnerRadius, + double BackgroundOuterRadius, int NumSteps = 16) { doTestValid(true, BackgroundInnerFactor, BackgroundOuterFactor, BackgroundInnerRadius, BackgroundOuterRadius, NumSteps); } - void test_validateForValidInputs() { - doTestNoThrowForValid(1.0, 2.0, 0, 0); - doTestNoThrowForValid(0, 0, 0.12, 0.15); - doTestNoThrowForValid(1.0, 0, 0, 0.15); - doTestNoThrowForValid(0, 1.5, 0.15, 0); + void test_worksWithValidInputs() { + ensureExecutionNoThrow(1.0, 2.0, 0, 0); + ensureExecutionNoThrow(0, 0, 0.12, 0.15); + ensureExecutionNoThrow(1.0, 0, 0, 0.15); + ensureExecutionNoThrow(0, 1.5, 0.15, 0); // Can't specify fixed and variable } - void test_validateForInvalidInputs() { - doTestThrowsForInvalid(1.0, 0, 0.15, 0); - doTestThrowsForInvalid(0, 1.0, 0, 0.15); - doTestThrowsForInvalid(1.0, 0, 0.15, 0); - doTestThrowsForInvalid(1.0, 1.0, 0.12, 0.15); - doTestThrowsForInvalid(1.0, 2.0, 0, 0, -8); + void test_throwsWhenExecutingForInvalidInputs() { + ensureExecutionThrows(1.0, 0, 0.15, 0); + ensureExecutionThrows(0, 1.0, 0, 0.15); + ensureExecutionThrows(1.0, 0, 0.15, 0); + ensureExecutionThrows(1.0, 1.0, 0.12, 0.15); + } + + template + void assertInvalidPropertyValue(PeakIntensityVsRadius &alg, std::string const&name, + PropertyType value) { + TS_ASSERT_THROWS_ANYTHING(alg.setProperty(name, value)) + } + + void test_throwsWhenSettingInvalidPropertyValues() { + PeakIntensityVsRadius alg; + assertSuccessfulInitialization(alg); + assertInvalidPropertyValue(alg, "NumSteps", -8); } - void assertNoThrowWhenSettingProperties( - std::string &outWsName, double BackgroundInnerFactor, - double BackgroundOuterFactor, double BackgroundInnerRadius, - double BackgroundOuterRadius int NumSteps) { + void assertNoThrowWhenSettingProperties(PeakIntensityVsRadius &alg, + std::string &outWSName, + double BackgroundInnerFactor, + double BackgroundOuterFactor, + double BackgroundInnerRadius, + double BackgroundOuterRadius, + int NumSteps) { TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue( "InputWorkspace", "PeakIntensityVsRadiusTest_MDEWS")); TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue( @@ -140,7 +157,6 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { alg.setProperty("BackgroundInnerRadius", BackgroundInnerRadius)); TS_ASSERT_THROWS_NOTHING( alg.setProperty("BackgroundOuterRadius", BackgroundOuterRadius)); - TS_ASSERT_THROWS_NOTHING(alg.execute();); } MatrixWorkspace_sptr doTest(double BackgroundInnerFactor, @@ -151,10 +167,10 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { std::string outWSName("PeakIntensityVsRadiusTest_OutputWS"); PeakIntensityVsRadius alg; - TS_ASSERT_SUCCESSFUL_INITIALZATION(alg); + assertSuccessfulInitialization(alg); assertNoThrowWhenSettingProperties( - BackgroundInnerFactor, BackgroundOuterFactor, BackgroundInnerRadius, - BackgroundOuterRadius, NumSteps); + alg, outWSName, BackgroundInnerFactor, BackgroundOuterFactor, + BackgroundInnerRadius, BackgroundOuterRadius, NumSteps); TS_ASSERT_THROWS_NOTHING(alg.execute();); TS_ASSERT(alg.isExecuted()); @@ -167,9 +183,10 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { return ws; } -#define TS_ASSERT_FLAT_AFTER_1(ws) \ - TSM_ASSERT_DELTA("After 1.0, the signal is flat", ws->y(0)[12], 1000, 1e-6); \ - TSM_ASSERT_DELTA("After 1.0, the signal is flat", ws->y(0)[15], 1000, 1e-6) + void assertFlatAfter1(MatrixWorkspace_sptr ws) { + TSM_ASSERT_DELTA("After 1.0, the signal is flat", ws->y(0)[12], 1000, 1e-6); + TSM_ASSERT_DELTA("After 1.0, the signal is flat", ws->y(0)[15], 1000, 1e-6) + } void test_NoBackground() { MatrixWorkspace_sptr ws = doTest(0, 0, 0, 0); @@ -180,24 +197,25 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { TS_ASSERT_DELTA(ws->x(0)[2], 0.2, 1e-6); TS_ASSERT_LESS_THAN(ws->y(0)[5], 1000); - TS_ASSERT_FLAT_AFTER_1(ws); + assertFlatAfter1(ws); } -#define TS_ASSERT_FIRST_FOUR_Y_VALUES_CLOSE_TO_ZERO(ws) \ - TS_ASSERT_DELTA(ws->y(0)[0], 0, 10); \ - TS_ASSERT_DELTA(ws->y(0)[1], 0, 10); \ - TS_ASSERT_DELTA(ws->y(0)[2], 0, 10); \ - TS_ASSERT_DELTA(ws->y(0)[3], 0, 10) + void assertFirstFourYValuesCloseToZero(MatrixWorkspace_sptr ws) { + TS_ASSERT_DELTA(ws->y(0)[0], 0, 10); + TS_ASSERT_DELTA(ws->y(0)[1], 0, 10); + TS_ASSERT_DELTA(ws->y(0)[2], 0, 10); + TS_ASSERT_DELTA(ws->y(0)[3], 0, 10); + } void test_VariableBackground() { MatrixWorkspace_sptr ws = doTest(1.0, 2.0, 0, 0); // Check the results TSM_ASSERT_EQUALS("Two peaks", ws->getNumberHistograms(), 2); - TS_ASSERT_FIRST_FOUR_Y_VALUES_CLOSE_TO_ZERO(ws); + assertFirstFourYValuesCloseToZero(ws); // Points before 0.5 are approximately zero because the background shell is // in the peak. - TS_ASSERT_FLAT_AFTER_1(ws); + assertFlatAfter1(ws); } void test_FixedBackground() { @@ -208,9 +226,11 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { // Points before 0.5 are approximately zero because the background shell is // in the peak. - TS_ASSERT_FIRST_FOUR_Y_VALUES_CLOSE_TO_ZERO(ws); - TS_ASSERT_FLAT_AFTER_1(ws); + assertFirstFourYValuesCloseToZero(ws); + assertFlatAfter1(ws); } +private: + PeakIntensityVsRadius m_alg; }; #endif /* MANTID_CRYSTAL_PEAKINTENSITYVSRADIUSTEST_H_ */ From 320630b377e43bfb6d8eac22c4a4ab085f858078 Mon Sep 17 00:00:00 2001 From: Edward Brown Date: Thu, 20 Jul 2017 12:27:19 +0100 Subject: [PATCH 07/11] Re #8394: Moved assertions. - Assertions are moved closer to the test methods they are used in. --- .../Crystal/test/PeakIntensityVsRadiusTest.h | 142 +++++++++--------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/Framework/Crystal/test/PeakIntensityVsRadiusTest.h b/Framework/Crystal/test/PeakIntensityVsRadiusTest.h index 929a9da90e5d..09b54abf28cf 100644 --- a/Framework/Crystal/test/PeakIntensityVsRadiusTest.h +++ b/Framework/Crystal/test/PeakIntensityVsRadiusTest.h @@ -25,10 +25,14 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { public: void test_Init() { PeakIntensityVsRadius alg; - TS_ASSERT_THROWS_NOTHING(alg.initialize()) - TS_ASSERT(alg.isInitialized()) + assertSuccessfulInitialization(alg); } + void assertSuccessfulInitialization(PeakIntensityVsRadius &alg) { + TS_ASSERT_THROWS_NOTHING(alg.initialize()); + TS_ASSERT(alg.isInitialized()) + } + //------------------------------------------------------------------------------- /** Create the (blank) MDEW */ static void createMDEW() { @@ -67,27 +71,19 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { "PeakIntensityVsRadiusTest_peaks", peakWS); } - void assertSuccessfulInitialization(PeakIntensityVsRadius &alg) { - TS_ASSERT_THROWS_NOTHING(alg.initialize()); - TS_ASSERT(alg.isInitialized()) + void test_worksWithValidInputs() { + ensureExecutionNoThrow(1.0, 2.0, 0, 0); + ensureExecutionNoThrow(0, 0, 0.12, 0.15); + ensureExecutionNoThrow(1.0, 0, 0, 0.15); + ensureExecutionNoThrow(0, 1.5, 0.15, 0); + // Can't specify fixed and variable } - /** Check the validateInputs() calls */ - void doTestValid(bool assertExecuteSuccess, double BackgroundInnerFactor, - double BackgroundOuterFactor, double BackgroundInnerRadius, - double BackgroundOuterRadius, int NumSteps) { - PeakIntensityVsRadius alg; - // Name of the output workspace. - std::string outWSName("PeakIntensityVsRadiusTest_OutputWS"); - assertSuccessfulInitialization(alg); - assertNoThrowWhenSettingProperties( - alg, outWSName, BackgroundInnerFactor, BackgroundOuterFactor, - BackgroundInnerRadius, BackgroundOuterRadius, NumSteps); - if (assertExecuteSuccess) { - TS_ASSERT_THROWS_NOTHING(alg.execute();); - } else { - TS_ASSERT_THROWS_ANYTHING(alg.execute();); - } + void test_throwsWhenExecutingForInvalidInputs() { + ensureExecutionThrows(1.0, 0, 0.15, 0); + ensureExecutionThrows(0, 1.0, 0, 0.15); + ensureExecutionThrows(1.0, 0, 0.15, 0); + ensureExecutionThrows(1.0, 1.0, 0.12, 0.15); } void ensureExecutionThrows(double BackgroundInnerFactor, @@ -106,31 +102,22 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { BackgroundInnerRadius, BackgroundOuterRadius, NumSteps); } - void test_worksWithValidInputs() { - ensureExecutionNoThrow(1.0, 2.0, 0, 0); - ensureExecutionNoThrow(0, 0, 0.12, 0.15); - ensureExecutionNoThrow(1.0, 0, 0, 0.15); - ensureExecutionNoThrow(0, 1.5, 0.15, 0); - // Can't specify fixed and variable - } - - void test_throwsWhenExecutingForInvalidInputs() { - ensureExecutionThrows(1.0, 0, 0.15, 0); - ensureExecutionThrows(0, 1.0, 0, 0.15); - ensureExecutionThrows(1.0, 0, 0.15, 0); - ensureExecutionThrows(1.0, 1.0, 0.12, 0.15); - } - - template - void assertInvalidPropertyValue(PeakIntensityVsRadius &alg, std::string const&name, - PropertyType value) { - TS_ASSERT_THROWS_ANYTHING(alg.setProperty(name, value)) - } - - void test_throwsWhenSettingInvalidPropertyValues() { + /** Check the validateInputs() calls */ + void doTestValid(bool assertExecuteSuccess, double BackgroundInnerFactor, + double BackgroundOuterFactor, double BackgroundInnerRadius, + double BackgroundOuterRadius, int NumSteps) { PeakIntensityVsRadius alg; + // Name of the output workspace. + std::string outWSName("PeakIntensityVsRadiusTest_OutputWS"); assertSuccessfulInitialization(alg); - assertInvalidPropertyValue(alg, "NumSteps", -8); + assertNoThrowWhenSettingProperties( + alg, outWSName, BackgroundInnerFactor, BackgroundOuterFactor, + BackgroundInnerRadius, BackgroundOuterRadius, NumSteps); + if (assertExecuteSuccess) { + TS_ASSERT_THROWS_NOTHING(alg.execute();); + } else { + TS_ASSERT_THROWS_ANYTHING(alg.execute();); + } } void assertNoThrowWhenSettingProperties(PeakIntensityVsRadius &alg, @@ -159,6 +146,29 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { alg.setProperty("BackgroundOuterRadius", BackgroundOuterRadius)); } + void test_throwsWhenSettingInvalidPropertyValues() { + PeakIntensityVsRadius alg; + assertSuccessfulInitialization(alg); + assertInvalidPropertyValue(alg, "NumSteps", -8); + } + + template + void assertInvalidPropertyValue(PeakIntensityVsRadius &alg, std::string const&name, + PropertyType value) { + TS_ASSERT_THROWS_ANYTHING(alg.setProperty(name, value)) + } + + void test_VariableBackground() { + MatrixWorkspace_sptr ws = doTest(1.0, 2.0, 0, 0); + // Check the results + TSM_ASSERT_EQUALS("Two peaks", ws->getNumberHistograms(), 2); + assertFirstFourYValuesCloseToZero(ws); + + // Points before 0.5 are approximately zero because the background shell is + // in the peak. + assertFlatAfter1(ws); + } + MatrixWorkspace_sptr doTest(double BackgroundInnerFactor, double BackgroundOuterFactor, double BackgroundInnerRadius, @@ -183,23 +193,23 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { return ws; } - void assertFlatAfter1(MatrixWorkspace_sptr ws) { - TSM_ASSERT_DELTA("After 1.0, the signal is flat", ws->y(0)[12], 1000, 1e-6); - TSM_ASSERT_DELTA("After 1.0, the signal is flat", ws->y(0)[15], 1000, 1e-6) - } - - void test_NoBackground() { - MatrixWorkspace_sptr ws = doTest(0, 0, 0, 0); + void test_FixedBackground() { + // Background + MatrixWorkspace_sptr ws = doTest(0, 0, 0.4, 0.5); // Check the results TSM_ASSERT_EQUALS("Two peaks", ws->getNumberHistograms(), 2); - TSM_ASSERT_EQUALS("16 radii specified", ws->blocksize(), 16); - TS_ASSERT_DELTA(ws->x(0)[1], 0.1, 1e-6); - TS_ASSERT_DELTA(ws->x(0)[2], 0.2, 1e-6); - TS_ASSERT_LESS_THAN(ws->y(0)[5], 1000); + // Points before 0.5 are approximately zero because the background shell is + // in the peak. + assertFirstFourYValuesCloseToZero(ws); assertFlatAfter1(ws); } + void assertFlatAfter1(MatrixWorkspace_sptr ws) { + TSM_ASSERT_DELTA("After 1.0, the signal is flat", ws->y(0)[12], 1000, 1e-6); + TSM_ASSERT_DELTA("After 1.0, the signal is flat", ws->y(0)[15], 1000, 1e-6) + } + void assertFirstFourYValuesCloseToZero(MatrixWorkspace_sptr ws) { TS_ASSERT_DELTA(ws->y(0)[0], 0, 10); TS_ASSERT_DELTA(ws->y(0)[1], 0, 10); @@ -207,28 +217,18 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { TS_ASSERT_DELTA(ws->y(0)[3], 0, 10); } - void test_VariableBackground() { - MatrixWorkspace_sptr ws = doTest(1.0, 2.0, 0, 0); + void test_NoBackground() { + MatrixWorkspace_sptr ws = doTest(0, 0, 0, 0); // Check the results TSM_ASSERT_EQUALS("Two peaks", ws->getNumberHistograms(), 2); - assertFirstFourYValuesCloseToZero(ws); + TSM_ASSERT_EQUALS("16 radii specified", ws->blocksize(), 16); + TS_ASSERT_DELTA(ws->x(0)[1], 0.1, 1e-6); + TS_ASSERT_DELTA(ws->x(0)[2], 0.2, 1e-6); - // Points before 0.5 are approximately zero because the background shell is - // in the peak. + TS_ASSERT_LESS_THAN(ws->y(0)[5], 1000); assertFlatAfter1(ws); } - void test_FixedBackground() { - // Background - MatrixWorkspace_sptr ws = doTest(0, 0, 0.4, 0.5); - // Check the results - TSM_ASSERT_EQUALS("Two peaks", ws->getNumberHistograms(), 2); - - // Points before 0.5 are approximately zero because the background shell is - // in the peak. - assertFirstFourYValuesCloseToZero(ws); - assertFlatAfter1(ws); - } private: PeakIntensityVsRadius m_alg; }; From 85234d1d1590ab56c5612f10cc278aafbfd17f91 Mon Sep 17 00:00:00 2001 From: Edward Brown Date: Thu, 20 Jul 2017 13:58:05 +0100 Subject: [PATCH 08/11] Re #8394: Uncommented fix, applied clang-format. - Applied clang format manually to PeakIntensityVsRadius. - Uncommented fix for issue. --- Framework/Crystal/src/PeakIntensityVsRadius.cpp | 6 +++--- Framework/Crystal/test/PeakIntensityVsRadiusTest.h | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Framework/Crystal/src/PeakIntensityVsRadius.cpp b/Framework/Crystal/src/PeakIntensityVsRadius.cpp index e4d01f54882f..fcfafbd3dab9 100644 --- a/Framework/Crystal/src/PeakIntensityVsRadius.cpp +++ b/Framework/Crystal/src/PeakIntensityVsRadius.cpp @@ -1,10 +1,10 @@ #include "MantidCrystal/PeakIntensityVsRadius.h" -#include "MantidDataObjects/PeaksWorkspace.h" #include "MantidAPI/Axis.h" #include "MantidAPI/IMDEventWorkspace.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/TextAxis.h" #include "MantidAPI/WorkspaceFactory.h" +#include "MantidDataObjects/PeaksWorkspace.h" #include "MantidKernel/BoundedValidator.h" @@ -53,7 +53,7 @@ void PeakIntensityVsRadius::init() { auto mustBePositive = boost::make_shared>(); mustBePositive->setLower(0); declareProperty( - "NumSteps", 10,// mustBePositive, + "NumSteps", 10, mustBePositive, "Number of steps, between start and end, to calculate radius."); declareProperty( @@ -179,7 +179,7 @@ void PeakIntensityVsRadius::exec() { // Run the integrate algo with this background IAlgorithm_sptr alg = this->createChildAlgorithm("IntegratePeaksMD", progStep * double(step), - progStep * double(step + 1), false); + progStep *double(step + 1), false); alg->setProperty("InputWorkspace", inWS); alg->setProperty("PeaksWorkspace", peaksWS); alg->setProperty("PeakRadius", radius); diff --git a/Framework/Crystal/test/PeakIntensityVsRadiusTest.h b/Framework/Crystal/test/PeakIntensityVsRadiusTest.h index 09b54abf28cf..2608271fbabe 100644 --- a/Framework/Crystal/test/PeakIntensityVsRadiusTest.h +++ b/Framework/Crystal/test/PeakIntensityVsRadiusTest.h @@ -32,7 +32,7 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { TS_ASSERT_THROWS_NOTHING(alg.initialize()); TS_ASSERT(alg.isInitialized()) } - + //------------------------------------------------------------------------------- /** Create the (blank) MDEW */ static void createMDEW() { @@ -152,9 +152,9 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { assertInvalidPropertyValue(alg, "NumSteps", -8); } - template - void assertInvalidPropertyValue(PeakIntensityVsRadius &alg, std::string const&name, - PropertyType value) { + template + void assertInvalidPropertyValue(PeakIntensityVsRadius &alg, + std::string const &name, PropertyType value) { TS_ASSERT_THROWS_ANYTHING(alg.setProperty(name, value)) } From 10c32af9749e7a112d0d233efe67435f205c0291 Mon Sep 17 00:00:00 2001 From: Edward Brown Date: Thu, 20 Jul 2017 14:15:28 +0100 Subject: [PATCH 09/11] Re #8394 Fix formatting error. --- Framework/Crystal/src/PeakIntensityVsRadius.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Framework/Crystal/src/PeakIntensityVsRadius.cpp b/Framework/Crystal/src/PeakIntensityVsRadius.cpp index fcfafbd3dab9..22d67b2398d3 100644 --- a/Framework/Crystal/src/PeakIntensityVsRadius.cpp +++ b/Framework/Crystal/src/PeakIntensityVsRadius.cpp @@ -179,7 +179,7 @@ void PeakIntensityVsRadius::exec() { // Run the integrate algo with this background IAlgorithm_sptr alg = this->createChildAlgorithm("IntegratePeaksMD", progStep * double(step), - progStep *double(step + 1), false); + progStep * double(step + 1), false); alg->setProperty("InputWorkspace", inWS); alg->setProperty("PeaksWorkspace", peaksWS); alg->setProperty("PeakRadius", radius); From fcc39b488890cab3b984bbd7079b4805724e8ce9 Mon Sep 17 00:00:00 2001 From: Edward Brown Date: Mon, 24 Jul 2017 08:40:40 +0100 Subject: [PATCH 10/11] Re #8394 Remove Unused NumSteps parameter from test helpers. - Removed the unused NumSteps parameter from the PeakIntensityVsRadius test helpers. - Removed the unused m_alg member variable from the PeakIntensityVsRadius suite class. --- .../Crystal/test/PeakIntensityVsRadiusTest.h | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/Framework/Crystal/test/PeakIntensityVsRadiusTest.h b/Framework/Crystal/test/PeakIntensityVsRadiusTest.h index 2608271fbabe..a914f172b43a 100644 --- a/Framework/Crystal/test/PeakIntensityVsRadiusTest.h +++ b/Framework/Crystal/test/PeakIntensityVsRadiusTest.h @@ -89,30 +89,30 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { void ensureExecutionThrows(double BackgroundInnerFactor, double BackgroundOuterFactor, double BackgroundInnerRadius, - double BackgroundOuterRadius, int NumSteps = 16) { + double BackgroundOuterRadius) { doTestValid(false, BackgroundInnerFactor, BackgroundOuterFactor, - BackgroundInnerRadius, BackgroundOuterRadius, NumSteps); + BackgroundInnerRadius, BackgroundOuterRadius); } void ensureExecutionNoThrow(double BackgroundInnerFactor, double BackgroundOuterFactor, double BackgroundInnerRadius, - double BackgroundOuterRadius, int NumSteps = 16) { + double BackgroundOuterRadius) { doTestValid(true, BackgroundInnerFactor, BackgroundOuterFactor, - BackgroundInnerRadius, BackgroundOuterRadius, NumSteps); + BackgroundInnerRadius, BackgroundOuterRadius); } /** Check the validateInputs() calls */ void doTestValid(bool assertExecuteSuccess, double BackgroundInnerFactor, double BackgroundOuterFactor, double BackgroundInnerRadius, - double BackgroundOuterRadius, int NumSteps) { + double BackgroundOuterRadius) { PeakIntensityVsRadius alg; // Name of the output workspace. std::string outWSName("PeakIntensityVsRadiusTest_OutputWS"); assertSuccessfulInitialization(alg); assertNoThrowWhenSettingProperties( alg, outWSName, BackgroundInnerFactor, BackgroundOuterFactor, - BackgroundInnerRadius, BackgroundOuterRadius, NumSteps); + BackgroundInnerRadius, BackgroundOuterRadius); if (assertExecuteSuccess) { TS_ASSERT_THROWS_NOTHING(alg.execute();); } else { @@ -125,8 +125,8 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { double BackgroundInnerFactor, double BackgroundOuterFactor, double BackgroundInnerRadius, - double BackgroundOuterRadius, - int NumSteps) { + double BackgroundOuterRadius) { + auto int constexpr DEFAULT_NUM_STEPS = 16; TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue( "InputWorkspace", "PeakIntensityVsRadiusTest_MDEWS")); TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue( @@ -135,7 +135,7 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { alg.setPropertyValue("OutputWorkspace", outWSName)); TS_ASSERT_THROWS_NOTHING(alg.setProperty("RadiusStart", 0.0)); TS_ASSERT_THROWS_NOTHING(alg.setProperty("RadiusEnd", 1.5)); - TS_ASSERT_THROWS_NOTHING(alg.setProperty("NumSteps", NumSteps)); + TS_ASSERT_THROWS_NOTHING(alg.setProperty("NumSteps", DEFAULT_NUM_STEPS)); TS_ASSERT_THROWS_NOTHING( alg.setProperty("BackgroundInnerFactor", BackgroundInnerFactor)); TS_ASSERT_THROWS_NOTHING( @@ -172,7 +172,7 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { MatrixWorkspace_sptr doTest(double BackgroundInnerFactor, double BackgroundOuterFactor, double BackgroundInnerRadius, - double BackgroundOuterRadius, int NumSteps = 16) { + double BackgroundOuterRadius) { // Name of the output workspace. std::string outWSName("PeakIntensityVsRadiusTest_OutputWS"); @@ -180,7 +180,7 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { assertSuccessfulInitialization(alg); assertNoThrowWhenSettingProperties( alg, outWSName, BackgroundInnerFactor, BackgroundOuterFactor, - BackgroundInnerRadius, BackgroundOuterRadius, NumSteps); + BackgroundInnerRadius, BackgroundOuterRadius); TS_ASSERT_THROWS_NOTHING(alg.execute();); TS_ASSERT(alg.isExecuted()); @@ -228,9 +228,6 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { TS_ASSERT_LESS_THAN(ws->y(0)[5], 1000); assertFlatAfter1(ws); } - -private: - PeakIntensityVsRadius m_alg; }; #endif /* MANTID_CRYSTAL_PEAKINTENSITYVSRADIUSTEST_H_ */ From b684506cdba499d970645db016eb3c7d868330e9 Mon Sep 17 00:00:00 2001 From: Edward Brown Date: Mon, 24 Jul 2017 15:24:59 +0100 Subject: [PATCH 11/11] Re #8394: Removed additional type specifier. - The DEFAULT_NUM_STEPS constant had both auto and int type specifiers this commit removes the int. --- Framework/Crystal/test/PeakIntensityVsRadiusTest.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Framework/Crystal/test/PeakIntensityVsRadiusTest.h b/Framework/Crystal/test/PeakIntensityVsRadiusTest.h index a914f172b43a..121ae7e32716 100644 --- a/Framework/Crystal/test/PeakIntensityVsRadiusTest.h +++ b/Framework/Crystal/test/PeakIntensityVsRadiusTest.h @@ -126,7 +126,7 @@ class PeakIntensityVsRadiusTest : public CxxTest::TestSuite { double BackgroundOuterFactor, double BackgroundInnerRadius, double BackgroundOuterRadius) { - auto int constexpr DEFAULT_NUM_STEPS = 16; + auto constexpr DEFAULT_NUM_STEPS = 16; TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue( "InputWorkspace", "PeakIntensityVsRadiusTest_MDEWS")); TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue(