コード例 #1
0
 // Make method non-static so that Settings is initialized
 @SuppressWarnings("static-method")
 public void testSpeed() {
   assertEquals("?", Units.getDistanceFromKilometers(null));
   final boolean savedMetrics = Settings.isUseMetricUnits();
   try {
     Settings.setUseMetricUnits(true);
     assertSpeed("123 km/h", 122.782f);
     assertSpeed("123 km/h", 123.456f);
     assertSpeed("12.3 km/h", 12.3456f);
     assertSpeed("1.23 km/h", 1.23456f);
     assertSpeed("123 m/h", 0.123456f);
     Settings.setUseMetricUnits(false);
     assertSpeed("76.7 mph", 123.456f);
     assertSpeed("7.67 mph", 12.3456f);
     assertSpeed("0.77 mph", 1.23456f);
   } finally {
     Settings.setUseMetricUnits(savedMetrics);
   }
 }
コード例 #2
0
 // Make method non-static so that Settings is initialized
 @SuppressWarnings("static-method")
 public void testElevation() {
   final boolean savedMetrics = Settings.isUseMetricUnits();
   try {
     Settings.setUseMetricUnits(true);
     assertElevation("↥ 123 m", 122.782f);
     assertElevation("↥ 123 m", 123.456f);
     assertElevation("↥ 12 m", 12.3456f);
     assertElevation("↥ 1 m", 1.23456f);
     assertElevation("↥ 2 m", 1.6f);
     assertElevation("↥ 0 m", 0.123456f);
     assertElevation("↧ 123 m", -122.782f);
     assertElevation("↧ 123 m", -123.456f);
     assertElevation("↧ 12 m", -12.3456f);
     assertElevation("↧ 1 m", -1.23456f);
     assertElevation("↧ 2 m", -1.6f);
     assertElevation("↧ 0 m", -0.123456f);
     Settings.setUseMetricUnits(false);
     assertElevation("↥ 405 ft", 123.456f);
     assertElevation("↥ 41 ft", 12.3456f);
   } finally {
     Settings.setUseMetricUnits(savedMetrics);
   }
 }