Skip to content

Commit

Permalink
Re #9682. Handling case with one interpolation value.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wedel committed Jun 27, 2014
1 parent 625079c commit 167c634
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/Kernel/src/Interpolation.cpp
Expand Up @@ -60,9 +60,9 @@ namespace Kernel
{
size_t N = m_x.size();

if ( N == 0 )
if ( N < 2 )
{
g_log.error() << "No data in Interpolation. Return interpolation value zero.";
g_log.error() << "Need at least two values for interpolation. Return interpolation value zero.";
return 0.0;
}

Expand Down
14 changes: 14 additions & 0 deletions Code/Mantid/Framework/Kernel/test/InterpolationTest.h
Expand Up @@ -59,6 +59,7 @@ class InterpolationTest : public CxxTest::TestSuite
interpolation.setYUnit("dSpacing");

interpolation.addPoint(200.0, 2.0);
interpolation.addPoint(202.0, 3.0);

Interpolation other = interpolation;

Expand Down Expand Up @@ -193,6 +194,19 @@ class InterpolationTest : public CxxTest::TestSuite
TS_ASSERT_THROWS(interpolation.findIndexOfNextLargerValue(m_tableXValues, 2000.0, 1, N - 1), std::range_error)
}

void testInterpolationWithTooFewValues()
{
Interpolation interpolationZero;
Interpolation interpolationOne;
interpolationOne.addPoint(200, 2.0);

for(size_t i = 0; i < m_tableXValues.size(); ++i) {
// When there are only one or two values in the interpolation, it returns 0.0
checkValue(interpolationZero, m_tableXValues[i], 0.0, "zero interpolation values");
checkValue(interpolationOne, m_tableXValues[i], 0.0, "one interpolation value");
}
}

private:
Interpolation getInitializedInterpolation(std::string xUnit, std::string yUnit)
{
Expand Down

0 comments on commit 167c634

Please sign in to comment.