Skip to content

Commit

Permalink
Added the DistanceUnit.NAUTICALMILES enumeration
Browse files Browse the repository at this point in the history
label with the corresponding *NM* and *nmi* unit
suffixes. Update the docs to match.

Closes #5085
  • Loading branch information
Brian Yoder authored and chilling committed Feb 14, 2014
1 parent ac9e2cd commit 41dba68
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/reference/api-conventions.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Kilometer:: `km` or `kilometers`
Meter:: `m` or `meters`
Centimeter:: `cm` or `centimeters`
Millimeter:: `mm` or `millimeters`

Nautical mile:: `NM`, `nmi` or `nauticalmiles`

[[fuzziness]]
[float]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ public enum DistanceUnit {
INCH(0.0254, "in", "inch"),
YARD(0.9144, "yd", "yards"),
FEET(0.3048, "ft", "feet"),
MILES(1609.344, "mi", "miles"),
KILOMETERS(1000.0, "km", "kilometers"),
NAUTICALMILES(1852.0, "NM", "nmi", "nauticalmiles"),
MILLIMETERS(0.001, "mm", "millimeters"),
CENTIMETERS(0.01, "cm", "centimeters"),

// 'm' is a suffix of 'nmi' so it must follow 'nmi'
MILES(1609.344, "mi", "miles"),

// since 'm' is suffix of other unit
// it must be the last entry of unit
// names ending with 'm'. otherwise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void testSimpleDistanceUnit() {
assertThat(DistanceUnit.KILOMETERS.convert(10, DistanceUnit.MILES), closeTo(16.09344, 0.001));
assertThat(DistanceUnit.MILES.convert(10, DistanceUnit.MILES), closeTo(10, 0.001));
assertThat(DistanceUnit.MILES.convert(10, DistanceUnit.KILOMETERS), closeTo(6.21371192, 0.001));
assertThat(DistanceUnit.NAUTICALMILES.convert(10, DistanceUnit.MILES), closeTo(8.689762, 0.001));
assertThat(DistanceUnit.KILOMETERS.convert(10, DistanceUnit.KILOMETERS), closeTo(10, 0.001));
assertThat(DistanceUnit.KILOMETERS.convert(10, DistanceUnit.METERS), closeTo(0.01, 0.00001));
assertThat(DistanceUnit.KILOMETERS.convert(1000,DistanceUnit.METERS), closeTo(1, 0.001));
Expand All @@ -46,6 +47,8 @@ public void testDistanceUnitParsing() {
assertThat(DistanceUnit.Distance.parseDistance("50km").unit, equalTo(DistanceUnit.KILOMETERS));
assertThat(DistanceUnit.Distance.parseDistance("500m").unit, equalTo(DistanceUnit.METERS));
assertThat(DistanceUnit.Distance.parseDistance("51mi").unit, equalTo(DistanceUnit.MILES));
assertThat(DistanceUnit.Distance.parseDistance("53nmi").unit, equalTo(DistanceUnit.NAUTICALMILES));
assertThat(DistanceUnit.Distance.parseDistance("53NM").unit, equalTo(DistanceUnit.NAUTICALMILES));
assertThat(DistanceUnit.Distance.parseDistance("52yd").unit, equalTo(DistanceUnit.YARD));
assertThat(DistanceUnit.Distance.parseDistance("12in").unit, equalTo(DistanceUnit.INCH));
assertThat(DistanceUnit.Distance.parseDistance("23mm").unit, equalTo(DistanceUnit.MILLIMETERS));
Expand Down

0 comments on commit 41dba68

Please sign in to comment.