Skip to content

Commit

Permalink
Fix unit tests (graphhopper#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanholder committed Dec 20, 2016
1 parent cec230b commit 58417cd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public MatchResult doWork(List<GPXEntry> 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());

Expand Down Expand Up @@ -261,6 +261,8 @@ private List<GPXEntry> filterGPXEntries(List<GPXEntry> gpxList) {
gpxEntry.getLat(), gpxEntry.getLon()) > 2 * measurementErrorSigma) {
filtered.add(gpxEntry);
prevEntry = gpxEntry;
} else {
logger.debug("Filter out GPX entry: {}", i + 1);
}
}
return filtered;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object[]> algoOptions() {

// create hopper instance with CH enabled
CarFlagEncoder encoder = new CarFlagEncoder();
TestGraphHopper hopper = new TestGraphHopper();
Expand All @@ -87,17 +83,24 @@ public static Collection<Object[]> 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},
{"CH", hopper, chOpts}
});
}

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?
*/
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<GPXEntry> inputGPXEntries = new GPXFile()
.doImport("./src/test/resources/tour2-with-loop.gpx").getEntries();
MatchResult mr = mapMatching.doWork(inputGPXEntries);
Expand Down Expand Up @@ -258,19 +266,31 @@ 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<GPXEntry> inputGPXEntries = new GPXFile()
.doImport("./src/test/resources/tour4-with-uturn.gpx").getEntries();

// 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"),
Expand Down

0 comments on commit 58417cd

Please sign in to comment.