Convert { @NonNull public static String distance3(double m) { if (Double.isNaN(m)) { return ""; } else if (Double.isInfinite(m)) { return Double.toString(m); } else { if (metric) { if (m >= 1000) { return Math.round(m * 0.001) + " km"; } else { return Math.round(m) + " m"; } } else { if (m >= MILE) { final double miles = Math.max(1, m * 0.000621371192); return Math.round(miles) + " mi"; } else { return Math.round(m * 3.2808399) + " ft"; } } } }  static double kts2mps(double knots); @NonNull static String altitude(double m); @NonNull static String distance(double m); @NonNull static String distance(double m, int precision, boolean units); @NonNull static String distance2(double m, int precision); @NonNull static String distance3(double m); @NonNull static String speed(double mps); @NonNull static String speed(double mps, int precision, boolean units); @NonNull static String glide(double glideRatio, int precision, boolean units); @NonNull static String glide(double groundSpeed, double climb, int precision, boolean units); @NonNull static String glide2(double groundSpeed, double climb, int precision, boolean units); @NonNull static String pressure(double hPa); @NonNull static String angle(double degrees); @NonNull static String angle2(double degrees); @NonNull static String bearing2(double degrees); static boolean metric; static final double FT; static final double MPH; static final double KPH; static final float MPHf; static final float KPHf; static final String GLIDE_STATIONARY; static final String GLIDE_LEVEL; static final String GLIDE_VERTICAL; }
@Test public void convertDistance3() { Convert.metric = false; assertEquals("3 ft", Convert.distance3(1)); assertEquals("3281 ft", Convert.distance3(1000)); assertEquals("1 mi", Convert.distance3(1609.34)); assertEquals("10 mi", Convert.distance3(16093.4)); assertEquals("", Convert.distance3(Double.NaN)); assertEquals("Infinity", Convert.distance3(Double.POSITIVE_INFINITY)); assertEquals("-Infinity", Convert.distance3(Double.NEGATIVE_INFINITY)); }
@Test public void convertDistance3Metric() { Convert.metric = true; assertEquals("1 m", Convert.distance3(1)); assertEquals("1 km", Convert.distance3(1000)); assertEquals("2 km", Convert.distance3(1609.34)); assertEquals("16 km", Convert.distance3(16093.4)); }