TransitioningCompositeClock implements Clock { public static double interpolate(double start, double end, double lambda) { return (start + (3 * lambda * lambda - 2 * lambda * lambda * lambda) * (end - start)); } TransitioningCompositeClock(TimeTravelClock timeTravelClock,
                                     Clock realClock); void goTimeTravel(Date targetDate); void returnToRealTime(); @Override long getTimeInMillisSinceEpoch(); static double interpolate(double start, double end, double lambda); static final long TRANSITION_TIME_MILLIS; }
@Test public void testInterpolant() { double tol = 1e-3; assertEquals(0, TransitioningCompositeClock.interpolate(0, 10, 0), tol); assertEquals(1, TransitioningCompositeClock.interpolate(1, 10, 0), tol); assertEquals(10, TransitioningCompositeClock.interpolate(0, 10, 1), tol); assertEquals(5, TransitioningCompositeClock.interpolate(0, 10, 0.5), tol); double epsilon = 1e-4; double dydx0 = (TransitioningCompositeClock.interpolate(0, 1, epsilon) - TransitioningCompositeClock.interpolate(0, 1, 0)) / epsilon; assertEquals(0.0, dydx0, tol); double dydx1 = (TransitioningCompositeClock.interpolate(0, 1, 1) - TransitioningCompositeClock.interpolate(0, 1, 1 - epsilon)) / epsilon; assertEquals(0.0, dydx1, tol); }