DoubleRampFunction extends Function1D<Double, Double> { @Override public Double evaluate(final Double x) { Validate.notNull(x, "x"); if (x < _x1) { return _y1; } if (x > _x2) { return _y2; } return _y1 + (x - _x1) / (_x2 - _x1) * (_y2 - _y1); } DoubleRampFunction(final double x1, final double x2, final double y1, final double y2); @Override Double evaluate(final Double x);  }
@Test public void evaluate() { assertEquals("DoubleRampFunction: evaluate", F.evaluate(X1 - 1e-15), Y1, TOLERANCE_EVALUATE); assertEquals("DoubleRampFunction: evaluate", F.evaluate(X2 + 1e-15), Y2, TOLERANCE_EVALUATE); assertEquals("DoubleRampFunction: evaluate", F.evaluate(0.5 * X1 + 0.5 * X2), 0.5 * Y1 + 0.5 * Y2, TOLERANCE_EVALUATE); assertEquals("DoubleRampFunction: evaluate", F.evaluate(0.2 * X1 + 0.8 * X2), 0.2 * Y1 + 0.8 * Y2, TOLERANCE_EVALUATE); }