Traversal implements Serializable { public double getDistanceAtTime(double time) { if (time > totalDuration || DoubleMath.fuzzyEquals(time, totalDuration, totalDuration * ROUNDING_ERROR_FRACTION)) { return totalDistance; } if (time < 0) { throw new TraversalCalculationException("Negative time provided"); } return SegmentGraphUtilities.accumulateValueTo( sections, TraversalSection::getDuration, TraversalSection::getTotalDistance, TraversalSection::getDistanceAtTime, time); } Traversal(ImmutableList<TraversalSection> sections); ImmutableList<TraversalSection> getSections(); double getTotalDuration(); double getTotalDistance(); double getDistanceAtTime(double time); double getTimeAtDistance(double distance); double getSpeedAtTime(double time); double getSpeedAtDistance(double distance); double getAccelerationAtTime(double time); double getAccelerationAtDistance(double distance); double getDurationAccelerating(); double getDurationAtConstantSpeed(); double getDurationDecelerating(); static final Traversal EMPTY_TRAVERSAL; }
@Test void getDistanceAtTime_returnsExpectedValue() { assertThat(constantAccelerationTraversal.getDistanceAtTime(2.4)).isCloseTo(5.6, within(0.000001)); }
@Test void getDistanceAtTime_whenInputNegative_thenThrowsException() { assertThatThrownBy(() -> constantAccelerationTraversal.getDistanceAtTime(-1)).isInstanceOf(TraversalCalculationException.class); }
@Test void getDistanceAtTime_whenInputBeyondMax_thenReturnsTotalDistance() { assertThat(constantAccelerationTraversal.getDistanceAtTime(1000)).isCloseTo(16, within(1e-9)); }
@Test void getDistanceAtTime_realExample() { assertThat(realTraversal.getDistanceAtTime(4968.894977362377)).isCloseTo(1.4671108491237437, within(1e-9)); }