Ignore:
Timestamp:
2018-08-04T19:25:42+02:00 (6 years ago)
Author:
Don-vip
Message:

fix #16554 - read NMEA speeds in km/h

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/io/nmea/NmeaReaderTest.java

    r14079 r14083  
    160160    }
    161161
    162     private static Date readDate(String nmeaLine) throws IOException, SAXException {
     162    private static GpxData read(String nmeaLine) throws IOException, SAXException {
    163163        NmeaReader in = new NmeaReader(new ByteArrayInputStream(nmeaLine.getBytes(StandardCharsets.UTF_8)));
    164164        in.parse(true);
    165         return in.data.tracks.iterator().next().getSegments().iterator().next().getWayPoints().iterator().next().getTime();
     165        return in.data;
     166    }
     167
     168    private static WayPoint readWayPoint(String nmeaLine) throws IOException, SAXException {
     169        return read(nmeaLine).tracks.iterator().next().getSegments().iterator().next().getWayPoints().iterator().next();
     170    }
     171
     172    private static Date readDate(String nmeaLine) throws IOException, SAXException {
     173        return readWayPoint(nmeaLine).getTime();
     174    }
     175
     176    private static double readSpeed(String nmeaLine) throws IOException, SAXException {
     177        return Double.parseDouble(readWayPoint(nmeaLine).getString("speed"));
    166178    }
    167179
     
    179191                readDate("$GNRMC,162859.4,A,4543.03388,N,00058.19870,W,45.252,209.07,300518,,,D,V*13")));
    180192    }
     193
     194    /**
     195     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/16554">Bug #16554</a>.
     196     * @throws Exception if an error occurs
     197     */
     198    @Test
     199    public void testTicket16554() throws Exception {
     200        assertEquals(63.2420959, readSpeed(
     201                  "$GNRMC,141448.80,A,4659.05514,N,00130.44695,W,34.148,289.80,300718,,,D,V*26"), 1e-7);
     202        assertEquals(63.2430000, readSpeed(
     203                  "$GNRMC,141448.80,A,4659.05514,N,00130.44695,W,34.148,289.80,300718,,,D,V*26"
     204                + "$GNVTG,289.80,T,,M,34.148,N,63.243,K,D*27"), 1e-7);
     205    }
    181206}
Note: See TracChangeset for help on using the changeset viewer.