Changeset 9861 in josm for trunk/test/unit


Ignore:
Timestamp:
2016-02-23T21:01:34+01:00 (5 years ago)
Author:
simon04
Message:

Unit test, Javadoc for LatLon

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/coor/LatLonTest.java

    r9810 r9861  
    44import static org.junit.Assert.assertEquals;
    55
     6import java.util.Locale;
     7
     8import org.junit.Before;
    69import org.junit.Test;
     10import org.openstreetmap.josm.Main;
     11import org.openstreetmap.josm.data.projection.Projections;
    712
    813/**
     
    1015 */
    1116public class LatLonTest {
     17
     18    /**
     19     * Setup test.
     20     */
     21    @Before
     22    public void setUp() throws Exception {
     23        Locale.setDefault(Locale.GERMAN);
     24        Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
     25    }
    1226
    1327    private static final double EPSILON = 1e-6;
     
    2640
    2741    /**
    28      * Test of {@link LatLon#roundToOsmPrecisionStrict}
     42     * Test of {@link LatLon#roundToOsmPrecision}
    2943     */
    3044    @Test
    31     public void testRoundToOsmPrecisionStrict() {
     45    public void testRoundToOsmPrecision() {
    3246
    3347        for (double value : SAMPLE_VALUES) {
    34             assertEquals(LatLon.roundToOsmPrecisionStrict(value), value, 0);
     48            assertEquals(LatLon.roundToOsmPrecision(value), value, 0);
    3549        }
    3650
    37         assertEquals(LatLon.roundToOsmPrecisionStrict(0.0), 0.0, 0);
    38         assertEquals(LatLon.roundToOsmPrecisionStrict(-0.0), 0.0, 0);
     51        assertEquals(LatLon.roundToOsmPrecision(0.0), 0.0, 0);
     52        assertEquals(LatLon.roundToOsmPrecision(-0.0), 0.0, 0);
    3953
    40         assertEquals(LatLon.roundToOsmPrecisionStrict(0.12345678),  0.1234568, 0);
    41         assertEquals(LatLon.roundToOsmPrecisionStrict(0.123456789), 0.1234568, 0);
     54        assertEquals(LatLon.roundToOsmPrecision(0.12345678),  0.1234568, 0);
     55        assertEquals(LatLon.roundToOsmPrecision(0.123456789), 0.1234568, 0);
    4256
    43         assertEquals(LatLon.roundToOsmPrecisionStrict(1.12345678),  1.1234568, 0);
    44         assertEquals(LatLon.roundToOsmPrecisionStrict(1.123456789), 1.1234568, 0);
     57        assertEquals(LatLon.roundToOsmPrecision(1.12345678),  1.1234568, 0);
     58        assertEquals(LatLon.roundToOsmPrecision(1.123456789), 1.1234568, 0);
    4559
    46         assertEquals(LatLon.roundToOsmPrecisionStrict(10.12345678),  10.1234568, 0);
    47         assertEquals(LatLon.roundToOsmPrecisionStrict(10.123456789), 10.1234568, 0);
     60        assertEquals(LatLon.roundToOsmPrecision(10.12345678),  10.1234568, 0);
     61        assertEquals(LatLon.roundToOsmPrecision(10.123456789), 10.1234568, 0);
    4862
    49         assertEquals(LatLon.roundToOsmPrecisionStrict(100.12345678),  100.1234568, 0);
    50         assertEquals(LatLon.roundToOsmPrecisionStrict(100.123456789), 100.1234568, 0);
     63        assertEquals(LatLon.roundToOsmPrecision(100.12345678),  100.1234568, 0);
     64        assertEquals(LatLon.roundToOsmPrecision(100.123456789), 100.1234568, 0);
    5165
    52         assertEquals(LatLon.roundToOsmPrecisionStrict(100.00000001),  100.0000000, 0);
    53         assertEquals(LatLon.roundToOsmPrecisionStrict(100.000000001),  100.0000000, 0);
    54         assertEquals(LatLon.roundToOsmPrecisionStrict(100.0000000001),  100.0000000, 0);
    55         assertEquals(LatLon.roundToOsmPrecisionStrict(100.00000000001),  100.0000000, 0);
    56         assertEquals(LatLon.roundToOsmPrecisionStrict(100.000000000001),  100.0000000, 0);
    57         assertEquals(LatLon.roundToOsmPrecisionStrict(100.0000000000001),  100.0000000, 0);
    58         assertEquals(LatLon.roundToOsmPrecisionStrict(100.00000000000001),  100.0000000, 0);
    59         assertEquals(LatLon.roundToOsmPrecisionStrict(100.000000000000001),  100.0000000, 0);
    60         assertEquals(LatLon.roundToOsmPrecisionStrict(100.0000000000000001),  100.0000000, 0);
    61         assertEquals(LatLon.roundToOsmPrecisionStrict(100.00000000000000001),  100.0000000, 0);
    62         assertEquals(LatLon.roundToOsmPrecisionStrict(100.000000000000000001),  100.0000000, 0);
    63         assertEquals(LatLon.roundToOsmPrecisionStrict(100.0000000000000000001),  100.0000000, 0);
    64         assertEquals(LatLon.roundToOsmPrecisionStrict(100.00000000000000000001),  100.0000000, 0);
     66        assertEquals(LatLon.roundToOsmPrecision(100.00000001),  100.0000000, 0);
     67        assertEquals(LatLon.roundToOsmPrecision(100.000000001),  100.0000000, 0);
     68        assertEquals(LatLon.roundToOsmPrecision(100.0000000001),  100.0000000, 0);
     69        assertEquals(LatLon.roundToOsmPrecision(100.00000000001),  100.0000000, 0);
     70        assertEquals(LatLon.roundToOsmPrecision(100.000000000001),  100.0000000, 0);
     71        assertEquals(LatLon.roundToOsmPrecision(100.0000000000001),  100.0000000, 0);
     72        assertEquals(LatLon.roundToOsmPrecision(100.00000000000001),  100.0000000, 0);
     73        assertEquals(LatLon.roundToOsmPrecision(100.000000000000001),  100.0000000, 0);
     74        assertEquals(LatLon.roundToOsmPrecision(100.0000000000000001),  100.0000000, 0);
     75        assertEquals(LatLon.roundToOsmPrecision(100.00000000000000001),  100.0000000, 0);
     76        assertEquals(LatLon.roundToOsmPrecision(100.000000000000000001),  100.0000000, 0);
     77        assertEquals(LatLon.roundToOsmPrecision(100.0000000000000000001),  100.0000000, 0);
     78        assertEquals(LatLon.roundToOsmPrecision(100.00000000000000000001),  100.0000000, 0);
    6579
    66         assertEquals(LatLon.roundToOsmPrecisionStrict(99.999999999999999999999),  100.0000000, 0);
    67         assertEquals(LatLon.roundToOsmPrecisionStrict(99.99999999999999999999),  100.0000000, 0);
    68         assertEquals(LatLon.roundToOsmPrecisionStrict(99.9999999999999999999),  100.0000000, 0);
    69         assertEquals(LatLon.roundToOsmPrecisionStrict(99.999999999999999999),  100.0000000, 0);
    70         assertEquals(LatLon.roundToOsmPrecisionStrict(99.99999999999999999),  100.0000000, 0);
    71         assertEquals(LatLon.roundToOsmPrecisionStrict(99.9999999999999999),  100.0000000, 0);
    72         assertEquals(LatLon.roundToOsmPrecisionStrict(99.999999999999999),  100.0000000, 0);
    73         assertEquals(LatLon.roundToOsmPrecisionStrict(99.99999999999999),  100.0000000, 0);
    74         assertEquals(LatLon.roundToOsmPrecisionStrict(99.9999999999999),  100.0000000, 0);
    75         assertEquals(LatLon.roundToOsmPrecisionStrict(99.999999999999),  100.0000000, 0);
    76         assertEquals(LatLon.roundToOsmPrecisionStrict(99.99999999999),  100.0000000, 0);
    77         assertEquals(LatLon.roundToOsmPrecisionStrict(99.9999999999),  100.0000000, 0);
    78         assertEquals(LatLon.roundToOsmPrecisionStrict(99.999999999),  100.0000000, 0);
    79         assertEquals(LatLon.roundToOsmPrecisionStrict(99.99999999),  100.0000000, 0);
    80         assertEquals(LatLon.roundToOsmPrecisionStrict(99.9999999),  99.9999999, 0);
     80        assertEquals(LatLon.roundToOsmPrecision(99.999999999999999999999),  100.0000000, 0);
     81        assertEquals(LatLon.roundToOsmPrecision(99.99999999999999999999),  100.0000000, 0);
     82        assertEquals(LatLon.roundToOsmPrecision(99.9999999999999999999),  100.0000000, 0);
     83        assertEquals(LatLon.roundToOsmPrecision(99.999999999999999999),  100.0000000, 0);
     84        assertEquals(LatLon.roundToOsmPrecision(99.99999999999999999),  100.0000000, 0);
     85        assertEquals(LatLon.roundToOsmPrecision(99.9999999999999999),  100.0000000, 0);
     86        assertEquals(LatLon.roundToOsmPrecision(99.999999999999999),  100.0000000, 0);
     87        assertEquals(LatLon.roundToOsmPrecision(99.99999999999999),  100.0000000, 0);
     88        assertEquals(LatLon.roundToOsmPrecision(99.9999999999999),  100.0000000, 0);
     89        assertEquals(LatLon.roundToOsmPrecision(99.999999999999),  100.0000000, 0);
     90        assertEquals(LatLon.roundToOsmPrecision(99.99999999999),  100.0000000, 0);
     91        assertEquals(LatLon.roundToOsmPrecision(99.9999999999),  100.0000000, 0);
     92        assertEquals(LatLon.roundToOsmPrecision(99.999999999),  100.0000000, 0);
     93        assertEquals(LatLon.roundToOsmPrecision(99.99999999),  100.0000000, 0);
     94        assertEquals(LatLon.roundToOsmPrecision(99.9999999),  99.9999999, 0);
    8195    }
    8296
     
    143157        assertEquals(270, Math.toDegrees(e.bearing(c)), EPSILON);
    144158    }
     159
     160    /**
     161     * Tests the methods {@link LatLon#latToString(CoordinateFormat)}, {@link LatLon#lonToString(CoordinateFormat)}.
     162     */
     163    @Test
     164    public void testFormatting() {
     165        LatLon c = new LatLon(47.000000, 19.000000);
     166        assertEquals("47.0", c.latToString(CoordinateFormat.DECIMAL_DEGREES));
     167        assertEquals("19.0", c.lonToString(CoordinateFormat.DECIMAL_DEGREES));
     168        assertEquals("47°00'00,0\"N", c.latToString(CoordinateFormat.DEGREES_MINUTES_SECONDS));
     169        assertEquals("19°00'00,0\"E", c.lonToString(CoordinateFormat.DEGREES_MINUTES_SECONDS));
     170        assertEquals("47°00,000'N", c.latToString(CoordinateFormat.NAUTICAL));
     171        assertEquals("19°00,000'E", c.lonToString(CoordinateFormat.NAUTICAL));
     172        assertEquals("5942074.0724311", c.latToString(CoordinateFormat.EAST_NORTH));
     173        assertEquals("2115070.3250722", c.lonToString(CoordinateFormat.EAST_NORTH));
     174    }
    145175}
Note: See TracChangeset for help on using the changeset viewer.