Skip to content

Commit aa97389

Browse files
committed
Extract setTurnCost/Restriction in test
1 parent 08f0f57 commit aa97389

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

core/src/test/java/com/graphhopper/routing/DirectedBidirectionalDijkstraTest.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,11 @@ public void directedRouting() {
248248
int leftNorth = graph.edge(9, 0, 1, true).getEdge();
249249

250250
// make paths fully deterministic by applying some turn costs at junction node 2
251-
turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, 7, 2).getEdge(), 2, GHUtility.getEdge(graph, 2, 3).getEdge(), 1);
252-
turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, 7, 2).getEdge(), 2, GHUtility.getEdge(graph, 2, 6).getEdge(), 3);
253-
turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, 1, 2).getEdge(), 2, GHUtility.getEdge(graph, 2, 3).getEdge(), 5);
254-
turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, 1, 2).getEdge(), 2, GHUtility.getEdge(graph, 2, 6).getEdge(), 7);
255-
turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, 1, 2).getEdge(), 2, GHUtility.getEdge(graph, 2, 7).getEdge(), 9);
251+
setTurnCost(7, 2, 3, 1);
252+
setTurnCost(7, 2, 6, 3);
253+
setTurnCost(1, 2, 3, 5);
254+
setTurnCost(1, 2, 6, 7);
255+
setTurnCost(1, 2, 7, 9);
256256

257257
final double unitEdgeWeight = 0.06;
258258
assertPath(calcPath(9, 9, leftNorth, leftSouth),
@@ -322,8 +322,8 @@ public void worksWithTurnCosts() {
322322
graph.edge(4, 5, 1, true);
323323
graph.edge(5, 2, 1, true);
324324

325-
turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, 0, 3).getEdge(), 3, GHUtility.getEdge(graph, 3, 4).getEdge(), Double.POSITIVE_INFINITY);
326-
turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, 4, 5).getEdge(), 5, GHUtility.getEdge(graph, 5, 2).getEdge(), 6);
325+
setRestriction(0, 3, 4);
326+
setTurnCost(4, 5, 2, 6);
327327

328328
// due to the restrictions we have to take the expensive path with turn costs
329329
assertPath(calcPath(0, 2, 0, 6), 6.24, 4, 6240, nodes(0, 1, 4, 5, 2));
@@ -356,8 +356,8 @@ public void finiteUTurnCosts() {
356356
int right6 = graph.edge(9, 6, 10, true).getEdge();
357357

358358
// enforce p-turn (using the loop in clockwise direction)
359-
turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, 0, 1).getEdge(), 1, GHUtility.getEdge(graph, 1, 6).getEdge(), Double.POSITIVE_INFINITY);
360-
turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, 5, 4).getEdge(), 4, GHUtility.getEdge(graph, 4, 3).getEdge(), Double.POSITIVE_INFINITY);
359+
setRestriction(0, 1, 6);
360+
setRestriction(5, 4, 3);
361361

362362
assertPath(calcPath(0, 6, right0, left6), 64.2, 1070, 64200, nodes(0, 1, 2, 3, 4, 5, 2, 1, 6));
363363
// if the u-turn cost is finite it depends on its value if we rather do the p-turn or do an immediate u-turn at node 2
@@ -535,4 +535,12 @@ private void assertNotFound(Path path) {
535535
assertEquals(0, path.getTime());
536536
assertEquals(nodes(), path.calcNodes());
537537
}
538+
539+
private void setRestriction(int fromNode, int node, int toNode) {
540+
setTurnCost(fromNode, node, toNode, Double.POSITIVE_INFINITY);
541+
}
542+
543+
private void setTurnCost(int fromNode, int node, int toNode, double turnCost) {
544+
turnCostStorage.set(turnCostEnc, GHUtility.getEdge(graph, fromNode, node).getEdge(), node, GHUtility.getEdge(graph, node, toNode).getEdge(), turnCost);
545+
}
538546
}

0 commit comments

Comments
 (0)