### Question:
TimeSquareCurveInterpolator implements CurveInterpolator, Serializable { @Override public BoundCurveInterpolator bind(DoubleArray xValues, DoubleArray yValues) { return new Bound(xValues, yValues); } private  TimeSquareCurveInterpolator(); @Override String getName(); @Override BoundCurveInterpolator bind(DoubleArray xValues, DoubleArray yValues); @Override String toString(); static final String NAME; static final CurveInterpolator INSTANCE; }### Answer:
@Test public void test_interpolation() { BoundCurveInterpolator bci = TIME_SQUARE_INTERPOLATOR.bind(X_DATA, Y_DATA, FLAT_EXTRAPOLATOR, FLAT_EXTRAPOLATOR); for (int i = 0; i < X_DATA.size(); i++) { assertThat(bci.interpolate(X_DATA.get(i))).isCloseTo(Y_DATA.get(i), offset(TOL)); } for (int i = 0; i < X_TEST.size(); i++) { assertThat(bci.interpolate(X_TEST.get(i))).isCloseTo(Y_TEST.get(i), offset(TOL)); } }
@Test public void test_firstDerivative() { BoundCurveInterpolator bci = TIME_SQUARE_INTERPOLATOR.bind(X_DATA, Y_DATA, FLAT_EXTRAPOLATOR, FLAT_EXTRAPOLATOR); double eps = 1e-8; double lo = bci.interpolate(0.2); double hi = bci.interpolate(0.2 + eps); double deriv = (hi - lo) / eps; assertThat(bci.firstDerivative(0.2)).isCloseTo(deriv, offset(1e-6)); }
@Test public void test_firstNode() { BoundCurveInterpolator bci = TIME_SQUARE_INTERPOLATOR.bind(X_DATA, Y_DATA, FLAT_EXTRAPOLATOR, FLAT_EXTRAPOLATOR); assertThat(bci.interpolate(0.0)).isCloseTo(3.0, offset(TOL)); assertThat(bci.parameterSensitivity(0.0).get(0)).isCloseTo(1d, offset(TOL)); assertThat(bci.parameterSensitivity(0.0).get(1)).isCloseTo(0d, offset(TOL)); }
@Test public void test_allNodes() { BoundCurveInterpolator bci = TIME_SQUARE_INTERPOLATOR.bind(X_DATA, Y_DATA, FLAT_EXTRAPOLATOR, FLAT_EXTRAPOLATOR); for (int i = 0; i < X_DATA.size(); i++) { assertThat(bci.interpolate(X_DATA.get(i))).isCloseTo(Y_DATA.get(i), offset(TOL)); } }
@Test public void test_lastNode() { BoundCurveInterpolator bci = TIME_SQUARE_INTERPOLATOR.bind(X_DATA, Y_DATA, FLAT_EXTRAPOLATOR, FLAT_EXTRAPOLATOR); assertThat(bci.interpolate(5.0)).isCloseTo(2.0, offset(TOL)); assertThat(bci.parameterSensitivity(5.0).get(X_DATA.size() - 2)).isCloseTo(0d, offset(TOL)); assertThat(bci.parameterSensitivity(5.0).get(X_DATA.size() - 1)).isCloseTo(1d, offset(TOL)); }