Skip to content

Commit

Permalink
Refs #8394 Added failing unit test.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gemmaguest committed Jul 17, 2017
1 parent f556671 commit d2a3b59
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions Framework/Crystal/test/PeakIntensityVsRadiusTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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_ */

0 comments on commit d2a3b59

Please sign in to comment.