CombinedInterpolatorExtrapolator extends Interpolator1D { @Override public Double interpolate(final Interpolator1DDataBundle data, final Double value) { Validate.notNull(data, "data"); Validate.notNull(value, "value"); if (value < data.firstKey()) { if (_leftExtrapolator != null) { return _leftExtrapolator.interpolate(data, value); } } else if (value > data.lastKey()) { if (_rightExtrapolator != null) { return _rightExtrapolator.interpolate(data, value); } } return _interpolator.interpolate(data, value); } CombinedInterpolatorExtrapolator(final Interpolator1D interpolator);  CombinedInterpolatorExtrapolator(final Interpolator1D interpolator, final Interpolator1D extrapolator);  CombinedInterpolatorExtrapolator(final Interpolator1D interpolator, final Interpolator1D leftExtrapolator, final Interpolator1D rightExtrapolator); @Override Interpolator1DDataBundle getDataBundle(final double[] x, final double[] y); @Override Interpolator1DDataBundle getDataBundleFromSortedArrays(final double[] x, final double[] y); Interpolator1D getInterpolator(); Interpolator1D getLeftExtrapolator(); Interpolator1D getRightExtrapolator(); @Override Double interpolate(final Interpolator1DDataBundle data, final Double value); @Override double firstDerivative(final Interpolator1DDataBundle data, final Double value); @Override double[] getNodeSensitivitiesForValue(final Interpolator1DDataBundle data, final Double value); @Override String toString();  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData() { COMBINED1.interpolate(null, 2.3); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullValue() { COMBINED1.interpolate(DATA, null); }
@Test public void testInterpolatorOnly() { final double x = 6.7; assertEquals(COMBINED1.interpolate(DATA, x), F.evaluate(x), 1e-15); try { COMBINED1.interpolate(DATA, x - 100); Assert.fail(); } catch (final IllegalArgumentException e) { } try { COMBINED1.interpolate(DATA, x + 100); Assert.fail(); } catch (final IllegalArgumentException e) { } }
@Test public void testOneExtrapolator() { final double x = 3.6; assertEquals(COMBINED2.interpolate(DATA, x), F.evaluate(x), 1e-15); assertEquals(COMBINED2.interpolate(DATA, x - 100), F.evaluate(0.), 1e-15); assertEquals(COMBINED2.interpolate(DATA, x + 100), F.evaluate(9.), 1e-15); }
@Test public void testTwoExtrapolators() { final double x = 3.6; assertEquals(COMBINED3.interpolate(DATA, x), F.evaluate(x), 1e-15); assertEquals(COMBINED3.interpolate(DATA, x - 100), F.evaluate(0.), 1e-15); assertEquals(COMBINED3.interpolate(DATA, x + 100), F.evaluate(x + 100), 1e-5); }