Ignore:
Timestamp:
2016-10-07T03:10:00+02:00 (8 years ago)
Author:
Don-vip
Message:

increase test coverage

File:
1 edited

Legend:

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

    r11045 r11086  
    33
    44import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertFalse;
     6import static org.junit.Assert.assertTrue;
    57
    68import java.text.DecimalFormat;
     
    810import org.junit.Rule;
    911import org.junit.Test;
     12import org.openstreetmap.josm.data.Bounds;
    1013import org.openstreetmap.josm.testutils.JOSMTestRules;
    1114
     
    2326    @Rule
    2427    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    25     public JOSMTestRules test = new JOSMTestRules();
     28    public JOSMTestRules test = new JOSMTestRules().projection();
    2629
    2730    private static final double EPSILON = 1e-6;
     
    101104
    102105    /**
     106     * Test {@link LatLon#toIntervalLat}
     107     */
     108    @Test
     109    public void testToIntervalLat() {
     110        assertEquals(-90.0, LatLon.toIntervalLat(-90.0), 0);
     111        assertEquals(0.0, LatLon.toIntervalLat(0.0), 0);
     112        assertEquals(90.0, LatLon.toIntervalLat(90.0), 0);
     113
     114        assertEquals(-90.0, LatLon.toIntervalLat(-91.0), 0);
     115        assertEquals(90.0, LatLon.toIntervalLat(91.0), 0);
     116    }
     117
     118    /**
    103119     * Test of {@link LatLon#toIntervalLon}
    104120     */
     
    133149            .withPrefabValues(DecimalFormat.class, new DecimalFormat("00.0"), new DecimalFormat("00.000"))
    134150            .verify();
     151    }
     152
     153    /**
     154     * Unit test of {@link LatLon#LatLon(LatLon)}.
     155     */
     156    @Test
     157    public void testCopyConstructor() {
     158        assertEquals(LatLon.NORTH_POLE, new LatLon(LatLon.NORTH_POLE));
     159        assertEquals(LatLon.SOUTH_POLE, new LatLon(LatLon.SOUTH_POLE));
     160        assertEquals(new LatLon(1, 2), new LatLon(new LatLon(1, 2)));
    135161    }
    136162
     
    150176
    151177    /**
    152      * Tests the methods {@link LatLon#latToString(CoordinateFormat)}, {@link LatLon#lonToString(CoordinateFormat)}.
     178     * Test of {@link LatLon#distance}
     179     */
     180    @Test
     181    public void testDistance() {
     182        assertEquals(0.0, LatLon.ZERO.distance(LatLon.ZERO), 0);
     183        assertEquals(90.0, LatLon.ZERO.distance(LatLon.NORTH_POLE), 0);
     184        assertEquals(180.0, LatLon.SOUTH_POLE.distance(LatLon.NORTH_POLE), 0);
     185    }
     186
     187    /**
     188     * Test of {@link LatLon#distanceSq}
     189     */
     190    @Test
     191    public void testDistanceSq() {
     192        assertEquals(0.0, LatLon.ZERO.distanceSq(LatLon.ZERO), 0);
     193        assertEquals(90d*90d, LatLon.ZERO.distanceSq(LatLon.NORTH_POLE), 0);
     194        assertEquals(180d*180d, LatLon.SOUTH_POLE.distanceSq(LatLon.NORTH_POLE), 0);
     195    }
     196
     197    /**
     198     * Tests the methods {@link LatLon#latToString}, {@link LatLon#lonToString}, {@link LatLon#toStringCSV}.
    153199     */
    154200    @Test
    155201    public void testFormatting() {
    156202        LatLon c = new LatLon(47.000000, 19.000000);
     203        assertEquals("47.0;19.0", c.toStringCSV(";"));
    157204        assertEquals("47.0", c.latToString(CoordinateFormat.DECIMAL_DEGREES));
    158205        assertEquals("19.0", c.lonToString(CoordinateFormat.DECIMAL_DEGREES));
     
    163210        assertEquals("5942074.0724311", c.latToString(CoordinateFormat.EAST_NORTH));
    164211        assertEquals("2115070.3250722", c.lonToString(CoordinateFormat.EAST_NORTH));
     212        c = new LatLon(-47.000000, -19.000000);
     213        assertEquals("47°00'00.0\"S", c.latToString(CoordinateFormat.DEGREES_MINUTES_SECONDS));
     214        assertEquals("19°00'00.0\"W", c.lonToString(CoordinateFormat.DEGREES_MINUTES_SECONDS));
     215        assertEquals("47°00.000'S", c.latToString(CoordinateFormat.NAUTICAL));
     216        assertEquals("19°00.000'W", c.lonToString(CoordinateFormat.NAUTICAL));
    165217    }
    166218
    167219    /**
    168220     * Test {@link LatLon#interpolate(LatLon, double)}
    169      * @since 10915
    170221     */
    171222    @Test
     
    187238
    188239    /**
     240     * Test {@link LatLon#isOutSideWorld}
     241     */
     242    @Test
     243    public void testIsOutSideWorld() {
     244        assertFalse(LatLon.ZERO.isOutSideWorld());
     245        assertTrue(LatLon.NORTH_POLE.isOutSideWorld());
     246        assertTrue(LatLon.SOUTH_POLE.isOutSideWorld());
     247        assertTrue(new LatLon(-181, 0).isOutSideWorld());
     248        assertTrue(new LatLon(181, 0).isOutSideWorld());
     249    }
     250
     251    /**
     252     * Test {@link LatLon#isValid}
     253     */
     254    @Test
     255    public void testIsValid() {
     256        assertTrue(LatLon.ZERO.isValid());
     257        assertTrue(LatLon.NORTH_POLE.isValid());
     258        assertTrue(LatLon.SOUTH_POLE.isValid());
     259
     260        assertFalse(new LatLon(-91, 0).isValid());
     261        assertFalse(new LatLon(91, 0).isValid());
     262        assertFalse(new LatLon(0, -181).isValid());
     263        assertFalse(new LatLon(0, 181).isValid());
     264    }
     265
     266    /**
     267     * Test {@link LatLon#isWithin}
     268     */
     269    @Test
     270    public void testIsWithin() {
     271        assertTrue(LatLon.ZERO.isWithin(new Bounds(LatLon.ZERO)));
     272        assertFalse(LatLon.ZERO.isWithin(new Bounds(LatLon.NORTH_POLE)));
     273    }
     274
     275    /**
    189276     * Test {@link LatLon#getCenter(LatLon)}
    190      * @since 10915
    191277     */
    192278    @Test
Note: See TracChangeset for help on using the changeset viewer.