use of org.junit.jupiter.params.provider.ValueSource in project graphhopper by graphhopper.
the class CHTurnCostTest method test_issue1593_full.
@ParameterizedTest
@ValueSource(strings = { DIJKSTRA_BI, ASTAR_BI })
public void test_issue1593_full(String algo) {
// 6 5
// 1<-x-4-x-3
// || |
// |x7 x8
// || /
// 2---
NodeAccess na = graph.getNodeAccess();
na.setNode(0, 49.407117, 9.701306);
na.setNode(1, 49.406914, 9.703393);
na.setNode(2, 49.404004, 9.709110);
na.setNode(3, 49.400160, 9.708787);
na.setNode(4, 49.400883, 9.706347);
EdgeIteratorState edge0 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(4, 3).setDistance(194.063000));
EdgeIteratorState edge1 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(525.106000));
EdgeIteratorState edge2 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(525.106000));
EdgeIteratorState edge3 = GHUtility.setSpeed(60, true, false, encoder, graph.edge(4, 1).setDistance(703.778000));
EdgeIteratorState edge4 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 4).setDistance(400.509000));
// cannot go 4-2-1 and 1-2-4 (at least when using edge1, there is still edge2!)
setRestriction(edge4, edge1, 2);
setRestriction(edge1, edge4, 2);
// cannot go 3-4-1
setRestriction(edge0, edge3, 4);
graph.freeze();
LocationIndexTree index = new LocationIndexTree(graph, new RAMDirectory());
index.prepareIndex();
List<GHPoint> points = Arrays.asList(// 8 (on edge4)
new GHPoint(49.401669187194116, 9.706821649608745), // 5 (on edge0)
new GHPoint(49.40056349818417, 9.70767186472369), // 7 (on edge2)
new GHPoint(49.406580835146556, 9.704665738628218), // 6 (on edge3)
new GHPoint(49.40107534698834, 9.702248694088528));
List<Snap> snaps = new ArrayList<>(points.size());
for (GHPoint point : points) {
snaps.add(index.findClosest(point.getLat(), point.getLon(), EdgeFilter.ALL_EDGES));
}
automaticPrepareCH();
QueryGraph queryGraph = QueryGraph.create(chGraph.getBaseGraph(), snaps);
RoutingAlgorithm chAlgo = new CHRoutingAlgorithmFactory(chGraph, queryGraph).createAlgo(new PMap().putObject(ALGORITHM, algo));
Path path = chAlgo.calcPath(5, 6);
// there should not be a path from 5 to 6, because first we cannot go directly 5-4-6, so we need to go left
// to 8. then at 2 we cannot go on edge 1 because of another turn restriction, but we can go on edge 2 so we
// travel via the virtual node 7 to node 1. From there we cannot go to 6 because of the one-way so we go back
// to node 2 (no u-turn because of the duplicate edge) on edge1. And this is were the journey ends: we cannot
// go to 8 because of the turn restriction from edge1 to edge4 -> there should not be a path!
assertFalse(path.isFound(), "there should not be a path, but found: " + path.calcNodes());
}
use of org.junit.jupiter.params.provider.ValueSource in project graphhopper by graphhopper.
the class CHTurnCostTest method testFiniteUTurnCost_virtualViaNode.
@ParameterizedTest
@ValueSource(strings = { DIJKSTRA_BI, ASTAR_BI })
public void testFiniteUTurnCost_virtualViaNode(String algo) {
// if there is an extra virtual node it can be possible to do a u-turn that otherwise would not be possible
// and so there can be a difference between CH and non-CH... therefore u-turns at virtual nodes are forbidden
// 4->3->2->1-x-0
// |
// 5->6
GHUtility.setSpeed(60, true, false, encoder, graph.edge(4, 3).setDistance(0));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 2).setDistance(0));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 1).setDistance(0));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 0).setDistance(0));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 5).setDistance(0));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(5, 6).setDistance(0));
updateDistancesFor(graph, 4, 0.1, 0.0);
updateDistancesFor(graph, 3, 0.1, 0.1);
updateDistancesFor(graph, 2, 0.1, 0.2);
updateDistancesFor(graph, 1, 0.1, 0.3);
updateDistancesFor(graph, 0, 0.1, 0.4);
updateDistancesFor(graph, 5, 0.0, 0.3);
updateDistancesFor(graph, 6, 0.0, 0.4);
// not allowed to turn right at node 1 -> we have to take a u-turn at node 0 (or at the virtual node...)
setRestriction(2, 1, 5);
graph.freeze();
chConfig = chConfigs.get(1);
prepareCH(0, 1, 2, 3, 4, 5, 6);
LocationIndexTree index = new LocationIndexTree(graph, new RAMDirectory());
index.prepareIndex();
GHPoint virtualPoint = new GHPoint(0.1, 0.35);
Snap snap = index.findClosest(virtualPoint.lat, virtualPoint.lon, EdgeFilter.ALL_EDGES);
QueryGraph chQueryGraph = QueryGraph.create(graph, snap);
assertEquals(3, snap.getClosestEdge().getEdge());
QueryRoutingCHGraph routingCHGraph = new QueryRoutingCHGraph(chGraph, chQueryGraph);
RoutingAlgorithm chAlgo = new CHRoutingAlgorithmFactory(routingCHGraph).createAlgo(new PMap().putObject(ALGORITHM, algo));
Path path = chAlgo.calcPath(4, 6);
assertTrue(path.isFound());
assertEquals(IntArrayList.from(4, 3, 2, 1, 0, 1, 5, 6), path.calcNodes());
Snap snap2 = index.findClosest(virtualPoint.lat, virtualPoint.lon, EdgeFilter.ALL_EDGES);
QueryGraph queryGraph = QueryGraph.create(graph, snap2);
assertEquals(3, snap2.getClosestEdge().getEdge());
Weighting w = queryGraph.wrapWeighting(chConfig.getWeighting());
Dijkstra dijkstra = new Dijkstra(queryGraph, w, TraversalMode.EDGE_BASED);
Path dijkstraPath = dijkstra.calcPath(4, 6);
assertEquals(IntArrayList.from(4, 3, 2, 1, 7, 0, 7, 1, 5, 6), dijkstraPath.calcNodes());
assertEquals(dijkstraPath.getWeight(), path.getWeight(), 1.e-2);
assertEquals(dijkstraPath.getDistance(), path.getDistance(), 1.e-2);
assertEquals(dijkstraPath.getTime(), path.getTime());
}
use of org.junit.jupiter.params.provider.ValueSource in project zookeeper by apache.
the class RemoveWatchesTest method testRemoveAllChildWatchesOnAPath.
/**
* Test verifies WatcherType.Children - removes only the configured child
* watcher function
*/
@ParameterizedTest
@ValueSource(booleans = { true, false })
@Timeout(value = 90)
public void testRemoveAllChildWatchesOnAPath(boolean useAsync) throws Exception {
zk1.create("/node1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
final CountDownLatch cWatchCount = new CountDownLatch(2);
final CountDownLatch rmWatchCount = new CountDownLatch(2);
Watcher w1 = event -> {
switch(event.getType()) {
case ChildWatchRemoved:
rmWatchCount.countDown();
break;
case NodeChildrenChanged:
cWatchCount.countDown();
break;
default:
break;
}
};
Watcher w2 = event -> {
switch(event.getType()) {
case ChildWatchRemoved:
rmWatchCount.countDown();
break;
case NodeChildrenChanged:
cWatchCount.countDown();
break;
default:
break;
}
};
// Add multiple child watches
LOG.info("Adding child watcher {} on path {}", w1, "/node1");
assertEquals(0, zk2.getChildren("/node1", w1).size(), "Didn't set child watches");
LOG.info("Adding child watcher {} on path {}", w2, "/node1");
assertEquals(0, zk2.getChildren("/node1", w2).size(), "Didn't set child watches");
assertTrue(isServerSessionWatcher(zk2.getSessionId(), "/node1", WatcherType.Children), "Server session is not a watcher");
removeAllWatches(zk2, "/node1", WatcherType.Children, false, Code.OK, useAsync);
assertTrue(rmWatchCount.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS), "Didn't remove child watcher");
assertFalse(isServerSessionWatcher(zk2.getSessionId(), "/node1", WatcherType.Children), "Server session is still a watcher after removal");
}
use of org.junit.jupiter.params.provider.ValueSource in project zookeeper by apache.
the class SecretUtilsTest method testReadSecret.
@ParameterizedTest
@ValueSource(strings = { "test secret", "" })
public void testReadSecret(final String secretTxt) throws Exception {
final Path secretFile = createSecretFile(secretTxt);
final char[] secret = SecretUtils.readSecret(secretFile.toString());
assertEquals(secretTxt, String.valueOf(secret));
}
use of org.junit.jupiter.params.provider.ValueSource in project VocabHunter by VocabHunter.
the class FormatHandlingTest method testSupportedVersion.
@ParameterizedTest
@ValueSource(strings = { FORMAT_1, FORMAT_2, FORMAT_3, FORMAT_4, FORMAT_5, FORMAT_UNEXPECTED_FIELD })
public void testSupportedVersion(final String filename) throws Exception {
Path file = getResourceFile(filename);
EnrichedSessionState expected = new EnrichedSessionState(EXPECTED_STATE, file);
assertAll(() -> validateMarkedWords(file, expected), () -> validateState(file, expected));
}
Aggregations