### Question:
RungeKuttaIntegrator1D extends Integrator1D<Double, Double> { @Override public Double integrate(Function<Double, Double> f, Double lower, Double upper) { ArgChecker.notNull(lower, "lower"); ArgChecker.notNull(upper, "upper"); if (Double.isNaN(lower) || Double.isInfinite(lower) || Double.isInfinite(upper) || Double.isNaN(upper)) { throw new IllegalArgumentException("lower or upper was NaN or Inf"); } double h = (upper - lower) / _minSteps; double f1, f2, f3, x; x = lower; f1 = f.apply(x); if (Double.isNaN(f1) || Double.isInfinite(f1)) { throw new IllegalArgumentException("function evaluation returned NaN or Inf"); } double result = 0.0; for (int i = 0; i < _minSteps; i++) { f2 = f.apply(x + h / 2.0); if (Double.isNaN(f2) || Double.isInfinite(f2)) { throw new IllegalArgumentException("function evaluation returned NaN or Inf"); } f3 = f.apply(x + h); if (Double.isNaN(f3) || Double.isInfinite(f3)) { throw new IllegalArgumentException("function evaluation returned NaN or Inf"); } result += calculateRungeKuttaFourthOrder(f, x, h, f1, f2, f3); f1 = f3; x += h; } return result; } RungeKuttaIntegrator1D(double absTol, double relTol, int minSteps);  RungeKuttaIntegrator1D(double tol, int minSteps);  RungeKuttaIntegrator1D(double atol, double rtol);  RungeKuttaIntegrator1D(double tol);  RungeKuttaIntegrator1D(int minSteps);  RungeKuttaIntegrator1D(); double getRelativeTolerance(); @Override Double integrate(Function<Double, Double> f, Double lower, Double upper);  }### Answer:
@Test public void test() { final double eps = 1e-9; final int minSteps = 10; final Integrator1D<Double, Double> integrator = new RungeKuttaIntegrator1D(eps, eps, minSteps); double lower = 0; double upper = 2.0; assertThat(4.0).isCloseTo(integrator.integrate(CUBE, lower, upper), offset(eps)); lower = 0.0; upper = 1.5; assertThat(0.625).isCloseTo(integrator.integrate(TRIANGLE, lower, upper), offset(eps)); lower = -30; upper = 30; assertThat(1.0).isCloseTo(integrator.integrate(MIX_NORM, lower, upper), offset(eps)); }
@Test public void testCutoff() { final double eps = 1e-9; final int minSteps = 10; final Integrator1D<Double, Double> integrator = new RungeKuttaIntegrator1D(eps, eps, minSteps); final double lower = -1.0; final double upper = 1.0; assertThat(0.0).isCloseTo(integrator.integrate(SIN_INV_X, lower, upper), offset(eps)); }