Changeset 14205 in josm for trunk/test
- Timestamp:
- 2018-08-30T23:15:06+02:00 (6 years ago)
- Location:
- trunk/test
- Files:
-
- 2 added
- 1 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxOffsetTest.java
r14204 r14205 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm. gui.layer.geoimage;2 package org.openstreetmap.josm.data.gpx; 3 3 4 4 import static org.junit.Assert.assertEquals; … … 16 16 17 17 /** 18 * Unit tests of {@link Offset} class.18 * Unit tests of {@link GpxTimeOffset} class. 19 19 */ 20 public class OffsetTest {20 public class GpxOffsetTest { 21 21 22 22 /** … … 36 36 37 37 /** 38 * Unit test of {@link Offset#formatOffset}.38 * Unit test of {@link GpxTimeOffset#formatOffset}. 39 39 */ 40 40 @Test 41 41 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()); 50 50 } 51 51 52 52 /** 53 * Unit test of {@link Offset#parseOffset}.53 * Unit test of {@link GpxTimeOffset#parseOffset}. 54 54 * @throws ParseException in case of parsing error 55 55 */ 56 56 @Test 57 57 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()); 65 65 } 66 66 67 67 /** 68 * Unit test of {@link Offset#splitOutTimezone}.68 * Unit test of {@link GpxTimeOffset#splitOutTimezone}. 69 69 */ 70 70 @Test 71 71 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()); 83 83 } 84 84 } -
trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxTimezoneTest.java
r14204 r14205 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm. gui.layer.geoimage;2 package org.openstreetmap.josm.data.gpx; 3 3 4 4 import static org.junit.Assert.assertEquals; … … 16 16 17 17 /** 18 * Unit tests of {@link Timezone} class.18 * Unit tests of {@link GpxTimezone} class. 19 19 */ 20 public class TimezoneTest {20 public class GpxTimezoneTest { 21 21 22 22 /** … … 36 36 37 37 /** 38 * Unit test of {@link Timezone#formatTimezone}.38 * Unit test of {@link GpxTimezone#formatTimezone}. 39 39 */ 40 40 @Test 41 41 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()); 47 47 } 48 48 49 49 /** 50 * Unit test of {@link Timezone#parseTimezone}.50 * Unit test of {@link GpxTimezone#parseTimezone}. 51 51 * @throws ParseException in case of parsing error 52 52 */ 53 53 @Test 54 54 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); 59 60 } 60 61 } -
trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImagesTest.java
r14079 r14205 3 3 4 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertFalse;6 import static org.junit.Assert.assertTrue;7 5 8 import java.util.Arrays;9 6 import java.util.Collections; 10 7 … … 12 9 import org.junit.Rule; 13 10 import org.junit.Test; 14 import org.openstreetmap.josm.data.coor.CachedLatLon;15 11 import org.openstreetmap.josm.data.gpx.GpxData; 12 import org.openstreetmap.josm.data.gpx.GpxTimeOffset; 13 import org.openstreetmap.josm.data.gpx.GpxTimezone; 16 14 import org.openstreetmap.josm.io.GpxReaderTest; 17 15 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 43 41 44 42 /** 45 * Tests matching of images to a GPX track.46 * @throws Exception if the track cannot be parsed47 */48 @Test49 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 GPX57 ib.createTmp();58 final ImageEntry i0 = new ImageEntry();59 i0.setExifTime(DateUtils.fromString("2016:01:03 11:59:54")); // 4 sec before start of GPX60 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 track73 assertEquals(new CachedLatLon(47.196979885920882, 8.79541271366179), i1.getPos()); // exact match74 assertEquals(new CachedLatLon(47.197319911792874, 8.792139580473304), i3.getPos()); // exact match75 assertEquals(new CachedLatLon((47.197131179273129 + 47.197186248376966) / 2, (8.792974585667253 + 8.792809881269932) / 2),76 i2.getPos()); // interpolated77 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 calculated83 // 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 kept96 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 /**102 43 * Tests automatic guessing of timezone/offset 103 44 * @throws Exception if an error occurs … … 109 50 i0.setExifTime(DateUtils.fromString("2016:01:03 11:59:54")); // 4 sec before start of GPX 110 51 i0.createTmp(); 111 assertEquals(Pair.create( Timezone.ZERO,Offset.seconds(-4)),52 assertEquals(Pair.create(GpxTimezone.ZERO, GpxTimeOffset.seconds(-4)), 112 53 CorrelateGpxWithImages.autoGuess(Collections.singletonList(i0), gpx)); 113 54 }
Note:
See TracChangeset
for help on using the changeset viewer.