Changeset 10906 in josm for trunk


Ignore:
Timestamp:
2016-08-27T17:23:05+02:00 (8 years ago)
Author:
Don-vip
Message:

add more non-regression NMEA unit tests

Location:
trunk
Files:
16 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java

    r10680 r10906  
    482482        return DataSource.getDataSourceBounds(dataSources);
    483483    }
     484
     485    @Override
     486    public int hashCode() {
     487        final int prime = 31;
     488        int result = 1;
     489        result = prime * result + ((dataSources == null) ? 0 : dataSources.hashCode());
     490        result = prime * result + ((routes == null) ? 0 : routes.hashCode());
     491        result = prime * result + ((tracks == null) ? 0 : tracks.hashCode());
     492        result = prime * result + ((waypoints == null) ? 0 : waypoints.hashCode());
     493        return result;
     494    }
     495
     496    @Override
     497    public boolean equals(Object obj) {
     498        if (this == obj)
     499            return true;
     500        if (obj == null)
     501            return false;
     502        if (getClass() != obj.getClass())
     503            return false;
     504        GpxData other = (GpxData) obj;
     505        if (dataSources == null) {
     506            if (other.dataSources != null)
     507                return false;
     508        } else if (!dataSources.equals(other.dataSources))
     509            return false;
     510        if (routes == null) {
     511            if (other.routes != null)
     512                return false;
     513        } else if (!routes.equals(other.routes))
     514            return false;
     515        if (tracks == null) {
     516            if (other.tracks != null)
     517                return false;
     518        } else if (!tracks.equals(other.tracks))
     519            return false;
     520        if (waypoints == null) {
     521            if (other.waypoints != null)
     522                return false;
     523        } else if (!waypoints.equals(other.waypoints))
     524            return false;
     525        return true;
     526    }
    484527}
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxRoute.java

    r7005 r10906  
    77public class GpxRoute extends WithAttributes {
    88    public Collection<WayPoint> routePoints = new LinkedList<>();
     9
     10    @Override
     11    public int hashCode() {
     12        return 31 * super.hashCode() + ((routePoints == null) ? 0 : routePoints.hashCode());
     13    }
     14
     15    @Override
     16    public boolean equals(Object obj) {
     17        if (this == obj)
     18            return true;
     19        if (!super.equals(obj))
     20            return false;
     21        if (getClass() != obj.getClass())
     22            return false;
     23        GpxRoute other = (GpxRoute) obj;
     24        if (routePoints == null) {
     25            if (other.routePoints != null)
     26                return false;
     27        } else if (!routePoints.equals(other.routePoints))
     28            return false;
     29        return true;
     30    }
    931}
  • trunk/src/org/openstreetmap/josm/data/gpx/ImmutableGpxTrack.java

    r9949 r10906  
    1717public class ImmutableGpxTrack extends WithAttributes implements GpxTrack {
    1818
    19     private final Collection<GpxTrackSegment> segments;
     19    private final List<GpxTrackSegment> segments;
    2020    private final double length;
    2121    private final Bounds bounds;
     
    3434        }
    3535        this.attr = Collections.unmodifiableMap(new HashMap<>(attributes));
    36         this.segments = Collections.unmodifiableCollection(newSegments);
     36        this.segments = Collections.unmodifiableList(newSegments);
    3737        this.length = calculateLength();
    3838        this.bounds = calculateBounds();
     
    9090        return 0;
    9191    }
     92
     93    @Override
     94    public int hashCode() {
     95        return 31 * super.hashCode() + ((segments == null) ? 0 : segments.hashCode());
     96    }
     97
     98    @Override
     99    public boolean equals(Object obj) {
     100        if (this == obj)
     101            return true;
     102        if (!super.equals(obj))
     103            return false;
     104        if (getClass() != obj.getClass())
     105            return false;
     106        ImmutableGpxTrack other = (ImmutableGpxTrack) obj;
     107        if (segments == null) {
     108            if (other.segments != null)
     109                return false;
     110        } else if (!segments.equals(other.segments))
     111            return false;
     112        return true;
     113    }
    92114}
  • trunk/src/org/openstreetmap/josm/data/gpx/ImmutableGpxTrackSegment.java

    r8510 r10906  
    55import java.util.Collection;
    66import java.util.Collections;
     7import java.util.List;
    78
    89import org.openstreetmap.josm.data.Bounds;
     
    1011public class ImmutableGpxTrackSegment implements GpxTrackSegment {
    1112
    12     private final Collection<WayPoint> wayPoints;
     13    private final List<WayPoint> wayPoints;
    1314    private final Bounds bounds;
    1415    private final double length;
    1516
     17    /**
     18     * Constructs a new {@code ImmutableGpxTrackSegment}.
     19     * @param wayPoints list of waypoints
     20     */
    1621    public ImmutableGpxTrackSegment(Collection<WayPoint> wayPoints) {
    17         this.wayPoints = Collections.unmodifiableCollection(new ArrayList<>(wayPoints));
     22        this.wayPoints = Collections.unmodifiableList(new ArrayList<>(wayPoints));
    1823        this.bounds = calculateBounds();
    1924        this.length = calculateLength();
     
    7075    }
    7176
     77    @Override
     78    public int hashCode() {
     79        return 31 + ((wayPoints == null) ? 0 : wayPoints.hashCode());
     80    }
     81
     82    @Override
     83    public boolean equals(Object obj) {
     84        if (this == obj)
     85            return true;
     86        if (obj == null)
     87            return false;
     88        if (getClass() != obj.getClass())
     89            return false;
     90        ImmutableGpxTrackSegment other = (ImmutableGpxTrackSegment) obj;
     91        if (wayPoints == null) {
     92            if (other.wayPoints != null)
     93                return false;
     94        } else if (!wayPoints.equals(other.wayPoints))
     95            return false;
     96        return true;
     97    }
    7298}
  • trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java

    r10467 r10906  
    159159        return new ArrayList<>(attr.keySet());
    160160    }
     161
     162    @Override
     163    public int hashCode() {
     164        final int prime = 31;
     165        int result = super.hashCode();
     166        long temp = Double.doubleToLongBits(lat);
     167        result = prime * result + (int) (temp ^ (temp >>> 32));
     168        temp = Double.doubleToLongBits(lon);
     169        result = prime * result + (int) (temp ^ (temp >>> 32));
     170        temp = Double.doubleToLongBits(time);
     171        result = prime * result + (int) (temp ^ (temp >>> 32));
     172        return result;
     173    }
     174
     175    @Override
     176    public boolean equals(Object obj) {
     177        if (this == obj)
     178            return true;
     179        if (!super.equals(obj))
     180            return false;
     181        if (getClass() != obj.getClass())
     182            return false;
     183        WayPoint other = (WayPoint) obj;
     184        if (Double.doubleToLongBits(lat) != Double.doubleToLongBits(other.lat))
     185            return false;
     186        if (Double.doubleToLongBits(lon) != Double.doubleToLongBits(other.lon))
     187            return false;
     188        if (Double.doubleToLongBits(time) != Double.doubleToLongBits(other.time))
     189            return false;
     190        return true;
     191    }
    161192}
  • trunk/src/org/openstreetmap/josm/data/gpx/WithAttributes.java

    r8510 r10906  
    9090        ext.put(key, value);
    9191    }
     92
     93    @Override
     94    public int hashCode() {
     95        return 31 + ((attr == null) ? 0 : attr.hashCode());
     96    }
     97
     98    @Override
     99    public boolean equals(Object obj) {
     100        if (this == obj)
     101            return true;
     102        if (obj == null)
     103            return false;
     104        if (getClass() != obj.getClass())
     105            return false;
     106        WithAttributes other = (WithAttributes) obj;
     107        if (attr == null) {
     108            if (other.attr != null)
     109                return false;
     110        } else if (!attr.equals(other.attr))
     111            return false;
     112        return true;
     113    }
    92114}
  • trunk/src/org/openstreetmap/josm/io/NmeaReader.java

    r10632 r10906  
    2929 */
    3030public class NmeaReader {
    31 
    32     /** Handler for the different types that NMEA speaks. */
    33     public enum NMEA_TYPE {
    34 
    35         /** RMC = recommended minimum sentence C. */
    36         GPRMC("$GPRMC"),
    37         /** GPS positions. */
    38         GPGGA("$GPGGA"),
    39         /** SA = satellites active. */
    40         GPGSA("$GPGSA"),
    41         /** Course over ground and ground speed */
    42         GPVTG("$GPVTG");
    43 
    44         private final String type;
    45 
    46         NMEA_TYPE(String type) {
    47             this.type = type;
    48         }
    49 
    50         public String getType() {
    51             return this.type;
    52         }
    53     }
    5431
    5532    // GPVTG
  • trunk/test/unit/org/openstreetmap/josm/io/NmeaReaderTest.java

    r10758 r10906  
    55
    66import java.io.FileInputStream;
     7import java.io.IOException;
    78import java.text.SimpleDateFormat;
    89import java.util.ArrayList;
     
    1213import org.junit.Rule;
    1314import org.junit.Test;
     15import org.openstreetmap.josm.TestUtils;
    1416import org.openstreetmap.josm.data.coor.LatLon;
    1517import org.openstreetmap.josm.data.gpx.GpxConstants;
     18import org.openstreetmap.josm.data.gpx.GpxData;
     19import org.openstreetmap.josm.data.gpx.GpxTrack;
     20import org.openstreetmap.josm.data.gpx.GpxTrackSegment;
    1621import org.openstreetmap.josm.data.gpx.WayPoint;
    17 import org.openstreetmap.josm.io.NmeaReader.NMEA_TYPE;
    1822import org.openstreetmap.josm.testutils.JOSMTestRules;
     23import org.xml.sax.SAXException;
    1924
    2025import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    21 import nl.jqno.equalsverifier.EqualsVerifier;
    2226
    2327/**
     
    3135    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    3236    public JOSMTestRules test = new JOSMTestRules();
    33 
    34     /**
    35      * Unit test of methods {@link NMEA_TYPE#equals} and {@link NMEA_TYPE#hashCode}.
    36      */
    37     @Test
    38     public void testEqualsContract() {
    39         EqualsVerifier.forClass(NMEA_TYPE.class).verify();
    40     }
    4137
    4238    /**
     
    6965        assertEquals(null, wayPoints.get(0).get(GpxConstants.PT_PDOP));
    7066    }
     67
     68    private static void compareWithReference(int ticket, String filename, int numCoor) throws IOException, SAXException {
     69        GpxData gpx = GpxReaderTest.parseGpxData(TestUtils.getRegressionDataFile(ticket, filename+".gpx"));
     70        NmeaReader in = new NmeaReader(new FileInputStream(TestUtils.getRegressionDataFile(ticket, filename+".nmea")));
     71        assertEquals(numCoor, in.getNumberOfCoordinates());
     72        assertEquals(0, in.getParserMalformed());
     73        assertEquals(in.data.dataSources, gpx.dataSources);
     74        assertEquals(1, gpx.tracks.size());
     75        assertEquals(1, in.data.tracks.size());
     76        GpxTrack gpxTrack = gpx.tracks.iterator().next();
     77        GpxTrack nmeaTrack = in.data.tracks.iterator().next();
     78        assertEquals(gpxTrack.getBounds(), nmeaTrack.getBounds());
     79        assertEquals(1, gpxTrack.getSegments().size());
     80        assertEquals(1, nmeaTrack.getSegments().size());
     81        GpxTrackSegment gpxSeg = gpxTrack.getSegments().iterator().next();
     82        GpxTrackSegment nmeaSeg = nmeaTrack.getSegments().iterator().next();
     83        assertEquals(gpxSeg.getBounds(), nmeaSeg.getBounds());
     84        assertEquals(numCoor, gpxSeg.getWayPoints().size());
     85        assertEquals(numCoor, nmeaSeg.getWayPoints().size());
     86        WayPoint gpxWpt = gpxSeg.getWayPoints().iterator().next();
     87        WayPoint nmeaWpt = nmeaSeg.getWayPoints().iterator().next();
     88        assertEquals(gpxWpt.getCoor().getRoundedToOsmPrecision(), nmeaWpt.getCoor().getRoundedToOsmPrecision());
     89    }
     90
     91    /**
     92     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/1433">Bug #1433</a>.
     93     * @throws Exception if an error occurs
     94     */
     95    @Test
     96    public void testTicket1433() throws Exception {
     97        compareWithReference(1433, "2008-08-14-16-04-58", 1241);
     98    }
     99
     100    /**
     101     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/1853">Bug #1853</a>.
     102     * @throws Exception if an error occurs
     103     */
     104    @Test
     105    public void testTicket1853() throws Exception {
     106        compareWithReference(1853, "PosData-20081216-115434", 1285);
     107    }
     108
     109    /**
     110     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/2147">Bug #2147</a>.
     111     * @throws Exception if an error occurs
     112     */
     113    @Test
     114    public void testTicket2147() throws Exception {
     115        compareWithReference(2147, "WG20080203171807.log", 487);
     116    }
    71117}
Note: See TracChangeset for help on using the changeset viewer.