Changeset 14205 in josm for trunk/test/unit


Ignore:
Timestamp:
2018-08-30T23:15:06+02:00 (6 years ago)
Author:
Don-vip
Message:

fix #16681 - Various enhancements for GPX correlation (patch by Bjoeni, modified)

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
1 added
1 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxOffsetTest.java

    r14204 r14205  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.gui.layer.geoimage;
     2package org.openstreetmap.josm.data.gpx;
    33
    44import static org.junit.Assert.assertEquals;
     
    1616
    1717/**
    18  * Unit tests of {@link Offset} class.
     18 * Unit tests of {@link GpxTimeOffset} class.
    1919 */
    20 public class OffsetTest {
     20public class GpxOffsetTest {
    2121
    2222    /**
     
    3636
    3737    /**
    38      * Unit test of {@link Offset#formatOffset}.
     38     * Unit test of {@link GpxTimeOffset#formatOffset}.
    3939     */
    4040    @Test
    4141    public void testFormatOffset() {
    42         assertEquals("0", Offset.seconds(0).formatOffset());
    43         assertEquals("123", Offset.seconds(123).formatOffset());
    44         assertEquals("-4242", Offset.seconds(-4242).formatOffset());
    45         assertEquals("0.1", Offset.milliseconds(100).formatOffset());
    46         assertEquals("0.120", Offset.milliseconds(120).formatOffset());
    47         assertEquals("0.123", Offset.milliseconds(123).formatOffset());
    48         assertEquals("1.2", Offset.milliseconds(1200).formatOffset());
    49         assertEquals("1.234", Offset.milliseconds(1234).formatOffset());
     42        assertEquals("0", GpxTimeOffset.seconds(0).formatOffset());
     43        assertEquals("123", GpxTimeOffset.seconds(123).formatOffset());
     44        assertEquals("-4242", GpxTimeOffset.seconds(-4242).formatOffset());
     45        assertEquals("0.1", GpxTimeOffset.milliseconds(100).formatOffset());
     46        assertEquals("0.120", GpxTimeOffset.milliseconds(120).formatOffset());
     47        assertEquals("0.123", GpxTimeOffset.milliseconds(123).formatOffset());
     48        assertEquals("1.2", GpxTimeOffset.milliseconds(1200).formatOffset());
     49        assertEquals("1.234", GpxTimeOffset.milliseconds(1234).formatOffset());
    5050    }
    5151
    5252    /**
    53      * Unit test of {@link Offset#parseOffset}.
     53     * Unit test of {@link GpxTimeOffset#parseOffset}.
    5454     * @throws ParseException in case of parsing error
    5555     */
    5656    @Test
    5757    public void testParseOffest() throws ParseException {
    58         assertEquals(0, Offset.parseOffset("0").getSeconds());
    59         assertEquals(4242L, Offset.parseOffset("4242").getSeconds());
    60         assertEquals(-4242L, Offset.parseOffset("-4242").getSeconds());
    61         assertEquals(0L, Offset.parseOffset("-0").getSeconds());
    62         assertEquals(100L, Offset.parseOffset("0.1").getMilliseconds());
    63         assertEquals(123L, Offset.parseOffset("0.123").getMilliseconds());
    64         assertEquals(-42420L, Offset.parseOffset("-42.42").getMilliseconds());
     58        assertEquals(0, GpxTimeOffset.parseOffset("0").getSeconds());
     59        assertEquals(4242L, GpxTimeOffset.parseOffset("4242").getSeconds());
     60        assertEquals(-4242L, GpxTimeOffset.parseOffset("-4242").getSeconds());
     61        assertEquals(0L, GpxTimeOffset.parseOffset("-0").getSeconds());
     62        assertEquals(100L, GpxTimeOffset.parseOffset("0.1").getMilliseconds());
     63        assertEquals(123L, GpxTimeOffset.parseOffset("0.123").getMilliseconds());
     64        assertEquals(-42420L, GpxTimeOffset.parseOffset("-42.42").getMilliseconds());
    6565    }
    6666
    6767    /**
    68      * Unit test of {@link Offset#splitOutTimezone}.
     68     * Unit test of {@link GpxTimeOffset#splitOutTimezone}.
    6969     */
    7070    @Test
    7171    public void testSplitOutTimezone() {
    72         assertEquals("+1:00", Offset.seconds(3602).splitOutTimezone().a.formatTimezone());
    73         assertEquals("2", Offset.seconds(3602).splitOutTimezone().b.formatOffset());
    74         assertEquals("-7:00", Offset.seconds(-7 * 3600 + 123).splitOutTimezone().a.formatTimezone());
    75         assertEquals("123", Offset.seconds(-7 * 3600 + 123).splitOutTimezone().b.formatOffset());
    76         assertEquals(1, Offset.seconds(35 * 3600 + 421).getDayOffset());
    77         assertEquals(11 * 3600 + 421, Offset.seconds(35 * 3600 + 421).withoutDayOffset().getSeconds());
    78         assertEquals("+11:00", Offset.seconds(35 * 3600 + 421).splitOutTimezone().a.formatTimezone());
    79         assertEquals(86400 + 421, Offset.seconds(35 * 3600 + 421).splitOutTimezone().b.getSeconds());
    80         assertEquals(421, Offset.seconds(35 * 3600 + 421).withoutDayOffset().splitOutTimezone().b.getSeconds());
    81         assertEquals("+1:00", Offset.milliseconds(3602987).splitOutTimezone().a.formatTimezone());
    82         assertEquals("2.987", Offset.milliseconds(3602987).splitOutTimezone().b.formatOffset());
     72        assertEquals("+1:00", GpxTimeOffset.seconds(3602).splitOutTimezone().a.formatTimezone());
     73        assertEquals("2", GpxTimeOffset.seconds(3602).splitOutTimezone().b.formatOffset());
     74        assertEquals("-7:00", GpxTimeOffset.seconds(-7 * 3600 + 123).splitOutTimezone().a.formatTimezone());
     75        assertEquals("123", GpxTimeOffset.seconds(-7 * 3600 + 123).splitOutTimezone().b.formatOffset());
     76        assertEquals(1, GpxTimeOffset.seconds(35 * 3600 + 421).getDayOffset());
     77        assertEquals(11 * 3600 + 421, GpxTimeOffset.seconds(35 * 3600 + 421).withoutDayOffset().getSeconds());
     78        assertEquals("+11:00", GpxTimeOffset.seconds(35 * 3600 + 421).splitOutTimezone().a.formatTimezone());
     79        assertEquals(86400 + 421, GpxTimeOffset.seconds(35 * 3600 + 421).splitOutTimezone().b.getSeconds());
     80        assertEquals(421, GpxTimeOffset.seconds(35 * 3600 + 421).withoutDayOffset().splitOutTimezone().b.getSeconds());
     81        assertEquals("+1:00", GpxTimeOffset.milliseconds(3602987).splitOutTimezone().a.formatTimezone());
     82        assertEquals("2.987", GpxTimeOffset.milliseconds(3602987).splitOutTimezone().b.formatOffset());
    8383    }
    8484}
  • trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxTimezoneTest.java

    r14204 r14205  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.gui.layer.geoimage;
     2package org.openstreetmap.josm.data.gpx;
    33
    44import static org.junit.Assert.assertEquals;
     
    1616
    1717/**
    18  * Unit tests of {@link Timezone} class.
     18 * Unit tests of {@link GpxTimezone} class.
    1919 */
    20 public class TimezoneTest {
     20public class GpxTimezoneTest {
    2121
    2222    /**
     
    3636
    3737    /**
    38      * Unit test of {@link Timezone#formatTimezone}.
     38     * Unit test of {@link GpxTimezone#formatTimezone}.
    3939     */
    4040    @Test
    4141    public void testFormatTimezone() {
    42         assertEquals("+1:00", new Timezone(1).formatTimezone());
    43         assertEquals("+6:30", new Timezone(6.5).formatTimezone());
    44         assertEquals("-6:30", new Timezone(-6.5).formatTimezone());
    45         assertEquals("+3:08", new Timezone(Math.PI).formatTimezone());
    46         assertEquals("+2:43", new Timezone(Math.E).formatTimezone());
     42        assertEquals("+1:00", new GpxTimezone(1).formatTimezone());
     43        assertEquals("+6:30", new GpxTimezone(6.5).formatTimezone());
     44        assertEquals("-6:30", new GpxTimezone(-6.5).formatTimezone());
     45        assertEquals("+3:08", new GpxTimezone(Math.PI).formatTimezone());
     46        assertEquals("+2:43", new GpxTimezone(Math.E).formatTimezone());
    4747    }
    4848
    4949    /**
    50      * Unit test of {@link Timezone#parseTimezone}.
     50     * Unit test of {@link GpxTimezone#parseTimezone}.
    5151     * @throws ParseException in case of parsing error
    5252     */
    5353    @Test
    5454    public void testParseTimezone() throws ParseException {
    55         assertEquals(1, Timezone.parseTimezone("+01:00").getHours(), 1e-3);
    56         assertEquals(1, Timezone.parseTimezone("+1:00").getHours(), 1e-3);
    57         assertEquals(1.5, Timezone.parseTimezone("+01:30").getHours(), 1e-3);
    58         assertEquals(11.5, Timezone.parseTimezone("+11:30").getHours(), 1e-3);
     55        assertEquals(1, GpxTimezone.parseTimezone("+01:00").getHours(), 1e-3);
     56        assertEquals(1, GpxTimezone.parseTimezone("+1:00").getHours(), 1e-3);
     57        assertEquals(1.5, GpxTimezone.parseTimezone("+01:30").getHours(), 1e-3);
     58        assertEquals(11.5, GpxTimezone.parseTimezone("+11:30").getHours(), 1e-3);
     59        assertEquals(-11.5, GpxTimezone.parseTimezone("-11:30").getHours(), 1e-3);
    5960    }
    6061}
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImagesTest.java

    r14079 r14205  
    33
    44import static org.junit.Assert.assertEquals;
    5 import static org.junit.Assert.assertFalse;
    6 import static org.junit.Assert.assertTrue;
    75
    8 import java.util.Arrays;
    96import java.util.Collections;
    107
     
    129import org.junit.Rule;
    1310import org.junit.Test;
    14 import org.openstreetmap.josm.data.coor.CachedLatLon;
    1511import org.openstreetmap.josm.data.gpx.GpxData;
     12import org.openstreetmap.josm.data.gpx.GpxTimeOffset;
     13import org.openstreetmap.josm.data.gpx.GpxTimezone;
    1614import org.openstreetmap.josm.io.GpxReaderTest;
    1715import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    4341
    4442    /**
    45      * Tests matching of images to a GPX track.
    46      * @throws Exception if the track cannot be parsed
    47      */
    48     @Test
    49     public void testMatchGpxTrack() throws Exception {
    50         final GpxData gpx = GpxReaderTest.parseGpxData("data_nodist/2094047.gpx");
    51         assertEquals(4, gpx.tracks.size());
    52         assertEquals(1, gpx.tracks.iterator().next().getSegments().size());
    53         assertEquals(185, gpx.tracks.iterator().next().getSegments().iterator().next().getWayPoints().size());
    54 
    55         final ImageEntry ib = new ImageEntry();
    56         ib.setExifTime(DateUtils.fromString("2016:01:03 11:54:58")); // 5 minutes before start of GPX
    57         ib.createTmp();
    58         final ImageEntry i0 = new ImageEntry();
    59         i0.setExifTime(DateUtils.fromString("2016:01:03 11:59:54")); // 4 sec before start of GPX
    60         i0.createTmp();
    61         final ImageEntry i1 = new ImageEntry();
    62         i1.setExifTime(DateUtils.fromString("2016:01:03 12:04:01"));
    63         i1.createTmp();
    64         final ImageEntry i2 = new ImageEntry();
    65         i2.setExifTime(DateUtils.fromString("2016:01:03 12:04:57"));
    66         i2.createTmp();
    67         final ImageEntry i3 = new ImageEntry();
    68         i3.setExifTime(DateUtils.fromString("2016:01:03 12:05:05"));
    69         i3.createTmp();
    70 
    71         assertEquals(4, CorrelateGpxWithImages.matchGpxTrack(Arrays.asList(ib, i0, i1, i2, i3), gpx, 0));
    72         assertEquals(new CachedLatLon(47.19286847859621, 8.79732714034617), i0.getPos()); // start of track
    73         assertEquals(new CachedLatLon(47.196979885920882, 8.79541271366179), i1.getPos()); // exact match
    74         assertEquals(new CachedLatLon(47.197319911792874, 8.792139580473304), i3.getPos()); // exact match
    75         assertEquals(new CachedLatLon((47.197131179273129 + 47.197186248376966) / 2, (8.792974585667253 + 8.792809881269932) / 2),
    76                 i2.getPos()); // interpolated
    77         assertFalse(ib.hasNewGpsData());
    78         assertTrue(i0.hasNewGpsData());
    79         assertTrue(i1.hasNewGpsData());
    80         assertTrue(i2.hasNewGpsData());
    81         assertTrue(i3.hasNewGpsData());
    82         // First waypoint has no speed in matchGpxTrack(). Speed is calculated
    83         // and not taken from GPX track.
    84         assertEquals(null, ib.getSpeed());
    85         assertEquals(null, i0.getSpeed());
    86         assertEquals(Double.valueOf(11.675317966018756), i1.getSpeed(), 0.000001);
    87         assertEquals(Double.valueOf(24.992418392716967), i2.getSpeed(), 0.000001);
    88         assertEquals(Double.valueOf(27.307968754679223), i3.getSpeed(), 0.000001);
    89         assertEquals(null, ib.getElevation());
    90         assertEquals(Double.valueOf(471.86), i0.getElevation(), 0.000001);
    91         assertEquals(Double.valueOf(489.29), i1.getElevation(), 0.000001);
    92         assertEquals(Double.valueOf((490.40 + 489.75) / 2), i2.getElevation(), 0.000001);
    93         assertEquals(Double.valueOf(486.368333333), i3.getElevation(), 0.000001);
    94         assertEquals(null, ib.getGpsTime());
    95         assertEquals(DateUtils.fromString("2016:01:03 11:59:54"), i0.getGpsTime()); // original time is kept
    96         assertEquals(DateUtils.fromString("2016:01:03 12:04:01"), i1.getGpsTime());
    97         assertEquals(DateUtils.fromString("2016:01:03 12:04:57"), i2.getGpsTime());
    98         assertEquals(DateUtils.fromString("2016:01:03 12:05:05"), i3.getGpsTime());
    99     }
    100 
    101     /**
    10243     * Tests automatic guessing of timezone/offset
    10344     * @throws Exception if an error occurs
     
    10950        i0.setExifTime(DateUtils.fromString("2016:01:03 11:59:54")); // 4 sec before start of GPX
    11051        i0.createTmp();
    111         assertEquals(Pair.create(Timezone.ZERO, Offset.seconds(-4)),
     52        assertEquals(Pair.create(GpxTimezone.ZERO, GpxTimeOffset.seconds(-4)),
    11253                CorrelateGpxWithImages.autoGuess(Collections.singletonList(i0), gpx));
    11354    }
Note: See TracChangeset for help on using the changeset viewer.