Traversal implements Serializable { public double getAccelerationAtDistance(double distance) { if (DoubleMath.fuzzyEquals(distance, totalDistance, totalDistance * ROUNDING_ERROR_FRACTION)) { TraversalSection lastSection = Iterables.getLast(sections); return lastSection.getAccelerationAtTime(lastSection.getDuration()); } if (distance < 0) { throw new TraversalCalculationException("Negative distance provided."); } if (distance >= totalDistance) { throw new TraversalCalculationException("Distance beyond end of traversal provided"); } return SegmentGraphUtilities.getValueAt( sections, TraversalSection::getTotalDistance, TraversalSection::getAccelerationAtDistance, distance); } 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 getAccelerationAtDistance_returnsExpectedValue() { assertThat(constantAccelerationTraversal.getAccelerationAtDistance(2.4)).isCloseTo(2, within(0.000001)); assertThat(constantAccelerationTraversal.getAccelerationAtDistance(4.4)).isCloseTo(0, within(0.000001)); }
@Test void getAccelerationAtDistance_whenInputNegative_thenThrowsException() { assertThatThrownBy(() -> constantAccelerationTraversal.getAccelerationAtDistance(-1)).isInstanceOf(TraversalCalculationException.class); }
@Test void getAccelerationAtDistance_whenInputBeyondMax_thenThrowsException() { assertThatThrownBy(() -> constantAccelerationTraversal.getAccelerationAtDistance(1000)).isInstanceOf(TraversalCalculationException.class); }