### Question:
ScalarFirstOrderDifferentiator implements Differentiator<Double, Double, Double> { @Override public Function<Double, Double> differentiate(Function<Double, Double> function) { ArgChecker.notNull(function, "function"); switch (differenceType) { case FORWARD: return new Function<Double, Double>() { @SuppressWarnings("synthetic-access") @Override public Double apply(Double x) { ArgChecker.notNull(x, "x"); return (function.apply(x + eps) - function.apply(x)) / eps; } }; case CENTRAL: return new Function<Double, Double>() { @SuppressWarnings("synthetic-access") @Override public Double apply(Double x) { ArgChecker.notNull(x, "x"); return (function.apply(x + eps) - function.apply(x - eps)) / twoEps; } }; case BACKWARD: return new Function<Double, Double>() { @SuppressWarnings("synthetic-access") @Override public Double apply(Double x) { ArgChecker.notNull(x, "x"); return (function.apply(x) - function.apply(x - eps)) / eps; } }; default: throw new IllegalArgumentException("Can only handle forward, backward and central differencing"); } } ScalarFirstOrderDifferentiator();  ScalarFirstOrderDifferentiator(FiniteDifferenceType differenceType);  ScalarFirstOrderDifferentiator(FiniteDifferenceType differenceType, double eps); @Override Function<Double, Double> differentiate(Function<Double, Double> function); @Override Function<Double, Double> differentiate(
      Function<Double, Double> function,
      Function<Double, Boolean> domain);  }### Answer:
@Test public void testNullFunction() { assertThatIllegalArgumentException() .isThrownBy(() -> CENTRAL.differentiate((Function<Double, Double>) null)); }
@Test public void test() { final double x = 0.2245; assertThat(FORWARD.differentiate(F).apply(x)).isCloseTo(DX_ANALYTIC.apply(x), offset(10 * EPS)); assertThat(CENTRAL.differentiate(F).apply(x)).isCloseTo(DX_ANALYTIC.apply(x), offset(EPS * EPS)); assertThat(BACKWARD.differentiate(F).apply(x)).isCloseTo(DX_ANALYTIC.apply(x), offset(10 * EPS)); }
@Test public void domainTest() { final double[] x = new double[] {1.2, 0, Math.PI}; final Function<Double, Double> alFunc = CENTRAL.differentiate(F, DOMAIN); for (int i = 0; i < 3; i++) { assertThat(alFunc.apply(x[i])).isCloseTo(DX_ANALYTIC.apply(x[i]), offset(1e-8)); } }