source: josm/trunk/test/unit/org/openstreetmap/josm/data/coor/LatLonTest.java@ 4541

Last change on this file since 4541 was 4541, checked in by Don-vip, 13 years ago

Fixed rounding error in LatLon.roundToOsmPrecision()

File size: 1.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.coor;
3
4import static org.junit.Assert.assertEquals;
5
6import org.junit.Test;
7
8/**
9 * @author Vincent
10 *
11 */
12public class LatLonTest {
13
14 @Test
15 public void roundingTests() {
16
17 for (double value : new double[]{
18 -180.0, -179.9, -179.6, -179.5, -179.4, -179.1, -179.0, -100.0, -99.9, -10.0, -9.9, -1.0, -0.1,
19 180.0, 179.9, 179.6, 179.5, 179.4, 179.1, 179.0, 100.0, 99.9, 10.0, 9.9, 1.0, 0.1,
20 0.12, 0.123, 0.1234, 0.12345, 0.123456, 0.1234567,
21 1.12, 1.123, 1.1234, 1.12345, 1.123456, 1.1234567,
22 10.12, 10.123, 10.1234, 10.12345, 10.123456, 10.1234567,
23 100.12, 100.123, 100.1234, 100.12345, 100.123456, 100.1234567
24 }) {
25 assertEquals(LatLon.roundToOsmPrecision(value), value, 0);
26 }
27
28 assertEquals(LatLon.roundToOsmPrecision(0.0), 0.0, 0);
29 assertEquals(LatLon.roundToOsmPrecision(-0.0), 0.0, 0);
30
31 assertEquals(LatLon.roundToOsmPrecision(0.12345678), 0.1234568, 0);
32 assertEquals(LatLon.roundToOsmPrecision(0.123456789), 0.1234568, 0);
33
34 assertEquals(LatLon.roundToOsmPrecision(1.12345678), 1.1234568, 0);
35 assertEquals(LatLon.roundToOsmPrecision(1.123456789), 1.1234568, 0);
36
37 assertEquals(LatLon.roundToOsmPrecision(10.12345678), 10.1234568, 0);
38 assertEquals(LatLon.roundToOsmPrecision(10.123456789), 10.1234568, 0);
39
40 assertEquals(LatLon.roundToOsmPrecision(100.12345678), 100.1234568, 0);
41 assertEquals(LatLon.roundToOsmPrecision(100.123456789), 100.1234568, 0);
42 }
43}
Note: See TracBrowser for help on using the repository browser.