StepInterpolator1D extends Interpolator1D { @Override public Double interpolate(final Interpolator1DDataBundle data, final Double value) { Validate.notNull(value, "value"); Validate.notNull(data, "data bundle"); return data.get(data.getLowerBoundKey(value)); }  @Override Double interpolate(final Interpolator1DDataBundle data, final Double value); @Override double firstDerivative(final Interpolator1DDataBundle data, final Double x); @Override Interpolator1DDataBundle getDataBundle(final double[] x, final double[] y); @Override Interpolator1DDataBundle getDataBundleFromSortedArrays(final double[] x, final double[] y); @Override double[] getNodeSensitivitiesForValue(Interpolator1DDataBundle data, Double value);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullData() { INTERPOLATOR.interpolate((Interpolator1DDataBundle) null, 2.); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullValue() { INTERPOLATOR.interpolate(DATA, null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testLowValue() { INTERPOLATOR.interpolate(DATA, -3.); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testHighValue() { INTERPOLATOR.interpolate(DATA, 15.); }
@Test public void test() { double value = 1; assertEquals(INTERPOLATOR.interpolate(DATA, value), 4.5, EPS); value = 1.1; assertEquals(INTERPOLATOR.interpolate(DATA, value), 4.5, EPS); value = 2 - EPS * 10; assertEquals(INTERPOLATOR.interpolate(DATA, value), 4.5, EPS); value = 2 + EPS / 10; assertEquals(INTERPOLATOR.interpolate(DATA, value), 4.3, EPS); value = 2; assertEquals(INTERPOLATOR.interpolate(DATA, value), 4.3, EPS); value = 3; assertEquals(INTERPOLATOR.interpolate(DATA, value), 6.7, EPS); }
@Test(enabled = false) void printTest() { System.out.println("StepInterpolator1DTest"); final CombinedInterpolatorExtrapolator interpolator = CombinedInterpolatorExtrapolatorFactory.getInterpolator(Interpolator1DFactory.STEP, Interpolator1DFactory.FLAT_EXTRAPOLATOR); for (int i = 0; i < 101; i++) { final double x = 0.5 + i * 3.0 / 100; System.out.println(x + "\t" + interpolator.interpolate(DATA, x)); } }