### Question:
DistanceUtil { public static Location speedFilter(Location oldLocation, Location newLocation, double maximumSpeed) { double distance = oldLocation.getDistanceTo(newLocation); long timestampDelta = newLocation.getTimestamp() - oldLocation.getTimestamp(); double currentSpeed = 0; if (timestampDelta != 0) { currentSpeed = distance / ((float) timestampDelta / TimeUnit.SECONDS.toMillis(1)); } if (currentSpeed > maximumSpeed) { double angle = oldLocation.getAngleTo(newLocation); Location adjustedLocation = oldLocation.getShiftedLocation(maximumSpeed, angle); adjustedLocation.setTimestamp(newLocation.getTimestamp()); return adjustedLocation; } else { return newLocation; } }  static long getClosestEvenDistance(double distance, int evenIncrement); static long getReasonableSmallerEvenDistance(double distance); static int getMaximumEvenIncrement(double distance); static Location walkingSpeedFilter(Location oldLocation, Location newLocation); static Location speedFilter(Location oldLocation, Location newLocation, double maximumSpeed); static final double HUMAN_WALKING_SPEED; }### Answer:
@Test public void speedFilter_largerDistanceThanMaximumSpeed_correctChange() throws Exception { Location oldLocation = LocationPredictorTest.GENDARMENMARKT; oldLocation.setTimestamp(0); Location newLocation = oldLocation.getShiftedLocation(5, 0); newLocation.setTimestamp(1000); Location expectedLocation = oldLocation.getShiftedLocation(2, 0); Location actualLocation = DistanceUtil.speedFilter(oldLocation, newLocation, 2); assertEquals(expectedLocation.getLatitude(), actualLocation.getLatitude(), 0); assertEquals(expectedLocation.getLongitude(), actualLocation.getLongitude(), 0); }
@Test public void speedFilter_exactlyMaximumSpeed_noChange() throws Exception { float maximumSpeed = 2; Location oldLocation = LocationPredictorTest.GENDARMENMARKT; oldLocation.setTimestamp(0); Location newLocation = oldLocation.getShiftedLocation(maximumSpeed, 0); newLocation.setTimestamp(1000); Location expectedLocation = oldLocation.getShiftedLocation(maximumSpeed, 0); Location actualLocation = DistanceUtil.speedFilter(oldLocation, newLocation, maximumSpeed); assertEquals(expectedLocation.getLatitude(), actualLocation.getLatitude(), 0); assertEquals(expectedLocation.getLongitude(), actualLocation.getLongitude(), 0); }
@Test public void speedFilter_exactLocations_noChange() throws Exception { float maximumSpeed = 2; Location oldLocation = LocationPredictorTest.GENDARMENMARKT; oldLocation.setTimestamp(0); Location expectedLocation = oldLocation; Location actualLocation = DistanceUtil.speedFilter(oldLocation, oldLocation, maximumSpeed); assertEquals(expectedLocation.getLatitude(), actualLocation.getLatitude(), 0); assertEquals(expectedLocation.getLongitude(), actualLocation.getLongitude(), 0); }
@Test public void speedFilter_smallerDistanceThanMaximumSpeed_noChange() throws Exception { Location oldLocation = LocationPredictorTest.GENDARMENMARKT; oldLocation.setTimestamp(0); Location newLocation = oldLocation.getShiftedLocation(1, 0); newLocation.setTimestamp(1000); Location expectedLocation = oldLocation.getShiftedLocation(1, 0); Location actualLocation = DistanceUtil.speedFilter(oldLocation, newLocation, 2); assertEquals(expectedLocation.getLatitude(), actualLocation.getLatitude(), 0); assertEquals(expectedLocation.getLongitude(), actualLocation.getLongitude(), 0); }