From 1ea75653b174598aa4711a276f6759c92d9f5363 Mon Sep 17 00:00:00 2001 From: Stefan Holder Date: Mon, 12 Dec 2016 07:45:54 +0100 Subject: [PATCH] Fix unit tests (#70) --- .../com/graphhopper/matching/MapMatching.java | 4 +- .../graphhopper/matching/MapMatchingTest.java | 42 ++++++++++++++----- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/matching-core/src/main/java/com/graphhopper/matching/MapMatching.java b/matching-core/src/main/java/com/graphhopper/matching/MapMatching.java index 42c72c9c..9fb346fd 100644 --- a/matching-core/src/main/java/com/graphhopper/matching/MapMatching.java +++ b/matching-core/src/main/java/com/graphhopper/matching/MapMatching.java @@ -178,7 +178,7 @@ public MatchResult doWork(List gpxList) { + " filtered GPX entries (from " + gpxList.size() + "), but two or more are needed"); } - + // now find each of the entries in the graph: final EdgeFilter edgeFilter = new DefaultEdgeFilter(algoOptions.getWeighting().getFlagEncoder()); @@ -259,6 +259,8 @@ private List filterGPXEntries(List gpxList) { gpxEntry.getLat(), gpxEntry.getLon()) > 2 * measurementErrorSigma) { filtered.add(gpxEntry); prevEntry = gpxEntry; + } else { + logger.debug("Filter out GPX entry: {}", i + 1); } } return filtered; diff --git a/matching-core/src/test/java/com/graphhopper/matching/MapMatchingTest.java b/matching-core/src/test/java/com/graphhopper/matching/MapMatchingTest.java index 02521cbc..b398596f 100644 --- a/matching-core/src/test/java/com/graphhopper/matching/MapMatchingTest.java +++ b/matching-core/src/test/java/com/graphhopper/matching/MapMatchingTest.java @@ -61,17 +61,13 @@ public class MapMatchingTest { public final static TranslationMap SINGLETON = new TranslationMap().doImport(); + // non-CH / CH test parameters + private final String parameterName; private final TestGraphHopper hopper; private final AlgorithmOptions algoOptions; - public MapMatchingTest(String name, TestGraphHopper hopper, AlgorithmOptions algoOption) { - this.algoOptions = algoOption; - this.hopper = hopper; - } - @Parameterized.Parameters(name = "{0}") public static Collection algoOptions() { - // create hopper instance with CH enabled CarFlagEncoder encoder = new CarFlagEncoder(); TestGraphHopper hopper = new TestGraphHopper(); @@ -87,10 +83,10 @@ public static Collection algoOptions() { .build(); // flexible should fall back to defaults - AlgorithmOptions flexibleOpts = AlgorithmOptions.start(). + AlgorithmOptions flexibleOpts = AlgorithmOptions.start() // TODO: fewer nodes than for CH are possible (short routes & different finish condition & higher degree graph) - // maxVisitedNodes(20). - build(); + // .maxVisitedNodes(20) + .build(); return Arrays.asList(new Object[][]{ {"non-CH", hopper, flexibleOpts}, @@ -98,6 +94,13 @@ public static Collection algoOptions() { }); } + public MapMatchingTest(String parameterName, TestGraphHopper hopper, + AlgorithmOptions algoOption) { + this.parameterName = parameterName; + this.algoOptions = algoOption; + this.hopper = hopper; + } + /** * TODO: split this test up into smaller units with better names? */ @@ -179,8 +182,9 @@ public void testDistantPoints() { new GHPoint(51.23, 12.18), new GHPoint(51.45, 12.59)); MatchResult mr = mapMatching.doWork(inputGPXEntries); - assertEquals(mr.getMatchLength(), 57653, 1); - assertEquals(mr.getMatchMillis(), 2748186, 1); + + assertEquals(57650, mr.getMatchLength(), 1); + assertEquals(2747796, mr.getMatchMillis(), 1); // not OK when we only allow a small number of visited nodes: AlgorithmOptions opts = AlgorithmOptions.start(algoOptions).maxVisitedNodes(1).build(); @@ -219,6 +223,10 @@ public void testSmallSeparatedSearchDistance() { @Test public void testLoop() { MapMatching mapMatching = new MapMatching(hopper, algoOptions); + + // Need to reduce GPS accuracy because too many GPX are filtered out otherwise. + mapMatching.setMeasurementErrorSigma(40); + List inputGPXEntries = new GPXFile() .doImport("./src/test/resources/tour2-with-loop.gpx").getEntries(); MatchResult mr = mapMatching.doWork(inputGPXEntries); @@ -258,6 +266,16 @@ public void testLoop2() { */ @Test public void testUTurns() { + // This test requires changing the default heading penalty, which does not work for CH. + if (parameterName.equals("CH")) { + return; + } + + final AlgorithmOptions algoOptions = AlgorithmOptions.start() + // Reduce penalty to allow U-turns + .hints(new PMap().put(Parameters.Routing.HEADING_PENALTY, 50)) + .build(); + MapMatching mapMatching = new MapMatching(hopper, algoOptions); List inputGPXEntries = new GPXFile() .doImport("./src/test/resources/tour4-with-uturn.gpx").getEntries(); @@ -265,12 +283,14 @@ public void testUTurns() { // with large measurement error, we expect no U-turn mapMatching.setMeasurementErrorSigma(50); MatchResult mr = mapMatching.doWork(inputGPXEntries); + assertEquals(Arrays.asList("Gustav-Adolf-Straße", "Gustav-Adolf-Straße", "Funkenburgstraße", "Funkenburgstraße"), fetchStreets(mr.getEdgeMatches())); // with small measurement error, we expect the U-turn mapMatching.setMeasurementErrorSigma(10); mr = mapMatching.doWork(inputGPXEntries); + assertEquals( Arrays.asList("Gustav-Adolf-Straße", "Gustav-Adolf-Straße", "Funkenburgstraße", "Funkenburgstraße", "Funkenburgstraße", "Funkenburgstraße"),