Skip to content

Commit

Permalink
Refactor AbstractRoutingAlgorithmTester
Browse files Browse the repository at this point in the history
- remove subclasses or at least no longer use inheritance
- remove TurnWeighting (without turn costs there are no u-turns anyway)
- various clean-ups, add some docs
  • Loading branch information
easbar committed Dec 17, 2019
1 parent fc26dd1 commit e214148
Show file tree
Hide file tree
Showing 12 changed files with 1,341 additions and 1,505 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,68 +17,39 @@
*/
package com.graphhopper.routing;

import com.graphhopper.routing.util.EncodingManager;
import com.graphhopper.routing.util.FlagEncoder;
import com.graphhopper.routing.util.TraversalMode;
import com.graphhopper.routing.weighting.ShortestWeighting;
import com.graphhopper.routing.weighting.TurnWeighting;
import com.graphhopper.routing.weighting.Weighting;
import com.graphhopper.storage.Graph;
import com.graphhopper.storage.GraphHopperStorage;
import com.graphhopper.storage.GraphBuilder;
import com.graphhopper.storage.SPTEntry;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import java.util.Arrays;
import java.util.Collection;
import java.util.concurrent.atomic.AtomicReference;

import static com.graphhopper.util.GHUtility.updateDistancesFor;
import static org.junit.Assert.assertEquals;

/**
* Run some tests specific for {@link AStarBidirection}
*
* @author Peter Karich
* @see RoutingAlgorithmTest for test cases covering standard node- and edge-based routing with this algorithm
* @see EdgeBasedRoutingAlgorithmTest for test cases covering routing with turn costs with this algorithm
*/
@RunWith(Parameterized.class)
public class AStarBidirectionTest extends AbstractRoutingAlgorithmTester {
private final TraversalMode traversalMode;
private final boolean allowUTurns;

public AStarBidirectionTest(TraversalMode tMode, boolean allowUTurns) {
this.traversalMode = tMode;
this.allowUTurns = allowUTurns;
}

/**
* Runs the same test with each of the supported traversal modes
*/
@Parameters(name = "{0} {1}")
public static Collection<Object[]> configs() {
return Arrays.asList(new Object[][]{
{TraversalMode.NODE_BASED, false},
{TraversalMode.EDGE_BASED, false},
{TraversalMode.EDGE_BASED, true}
});
}

@Override
public RoutingAlgorithmFactory createFactory(GraphHopperStorage prepareGraph, AlgorithmOptions prepareOpts) {
return new RoutingAlgorithmFactory() {
@Override
public RoutingAlgorithm createAlgo(Graph g, AlgorithmOptions opts) {
Weighting w = opts.getWeighting();
if (traversalMode.isEdgeBased()) {
double uTurnCost = allowUTurns ? 40 : Double.POSITIVE_INFINITY;
w = new TurnWeighting(w, g.getTurnCostStorage(), uTurnCost);
}
return new AStarBidirection(g, w, traversalMode);
}
};
}
public class AStarBidirectionTest {
private final EncodingManager encodingManager = EncodingManager.create("car");
private final FlagEncoder carEncoder = encodingManager.getEncoder("car");

@Test
public void testInitFromAndTo() {
Graph g = createGHStorage(false);
doTestInitFromAndTo(TraversalMode.NODE_BASED);
doTestInitFromAndTo(TraversalMode.EDGE_BASED);
}

private void doTestInitFromAndTo(final TraversalMode traversalMode) {
Graph g = new GraphBuilder(encodingManager).create();
g.edge(0, 1, 1, true);
updateDistancesFor(g, 0, 0.00, 0.00);
updateDistancesFor(g, 1, 0.01, 0.01);
Expand Down
72 changes: 0 additions & 72 deletions core/src/test/java/com/graphhopper/routing/AStarTest.java

This file was deleted.

Loading

0 comments on commit e214148

Please sign in to comment.