TopHatFunction extends Function1D<Double, Double> { @Override public Double evaluate(final Double x) { Validate.notNull(x, "x"); Validate.isTrue(x != _x1, "Function is undefined for x = x1"); Validate.isTrue(x != _x2, "Function is undefined for x = x2"); if (x > _x1 && x < _x2) { return _y; } return 0.; } TopHatFunction(final double x1, final double x2, final double y); @Override Double evaluate(final Double x);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNull() { F.evaluate((Double) null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testX1() { F.evaluate(X1); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testX2() { F.evaluate(X2); }
@Test public void test() { assertEquals(F.evaluate(X1 - 1e-15), 0, 0); assertEquals(F.evaluate(X2 + 1e-15), 0, 0); assertEquals(F.evaluate((X1 + X2) / 2), Y, 0); }