ValuesInSIUnits { public static double convertSpeed(double speed, LengthUnit sourceLengthUnit, TimeUnit sourceTimeUnit) { return speed * LengthUnit.METERS.getUnitsIn(sourceLengthUnit) / getTimeUnitAsSeconds(sourceTimeUnit); } private  ValuesInSIUnits(); static double convertDuration(double duration, TimeUnit sourceUnit); static double convertSpeed(double speed, LengthUnit sourceLengthUnit, TimeUnit sourceTimeUnit); static double convertAcceleration(double acceleration, LengthUnit sourceLengthUnit, TimeUnit sourceTimeUnit); static double convertJerk(double jerk, LengthUnit sourceLengthUnit, TimeUnit sourceTimeUnit);  }
@Test void convertSpeed_whenValueGetsLarger_thenPrecisionIsMaintained() { double kmPerMsSpeed = 1.31211; double siSpeed = kmPerMsSpeed * 1000 * 1000; assertThat(ValuesInSIUnits.convertSpeed(kmPerMsSpeed, LengthUnit.KILOMETERS, TimeUnit.MILLISECONDS)).isCloseTo(siSpeed, withinPercentage(TOLERANCE)); }
@Test void convertSpeed_whenValueGetsSmaller_thenPrecisionIsMaintained() { double mmPerMinuteSpeed = 1.31211; double siSpeed = mmPerMinuteSpeed / (1000 * 60); assertThat(ValuesInSIUnits.convertSpeed(mmPerMinuteSpeed, LengthUnit.MILLIMETERS, TimeUnit.MINUTES)).isCloseTo(siSpeed, withinPercentage(TOLERANCE)); }