use of org.junit.jupiter.params.provider.ValueSource in project graphhopper by graphhopper.
the class GraphHopperTest method testSRTMWithTunnelInterpolation.
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testSRTMWithTunnelInterpolation(boolean withTunnelInterpolation) {
final String profile = "profile";
final String vehicle = "foot";
final String weighting = "shortest";
GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(true);
if (!withTunnelInterpolation) {
hopper.getEncodingManagerBuilder().add(new OSMRoadEnvironmentParser() {
@Override
public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay readerWay, IntsRef relationFlags) {
// do not change RoadEnvironment to avoid triggering tunnel interpolation
return edgeFlags;
}
}).addIfAbsent(new DefaultFlagEncoderFactory(), vehicle);
}
hopper.setElevationProvider(new SRTMProvider(DIR));
hopper.importOrLoad();
GHPoint from = new GHPoint(43.7405647, 7.4299266);
GHPoint to = new GHPoint(43.7378990, 7.4279780);
// make sure we hit tower nodes, because all we really want is test the elevation interpolation
assertEquals(Snap.Position.TOWER, hopper.getLocationIndex().findClosest(from.lat, from.lon, EdgeFilter.ALL_EDGES).getSnappedPosition());
assertEquals(Snap.Position.TOWER, hopper.getLocationIndex().findClosest(to.lat, to.lon, EdgeFilter.ALL_EDGES).getSnappedPosition());
GHResponse rsp = hopper.route(new GHRequest(from, to).setProfile(profile));
ResponsePath res = rsp.getBest();
PointList pointList = res.getPoints();
assertEquals(6, pointList.size());
assertTrue(pointList.is3D());
if (withTunnelInterpolation) {
assertEquals(351.8, res.getDistance(), .1);
assertEquals(17, pointList.getEle(0), .1);
assertEquals(19.04, pointList.getEle(1), .1);
assertEquals(21.67, pointList.getEle(2), .1);
assertEquals(25.03, pointList.getEle(3), .1);
assertEquals(28.65, pointList.getEle(4), .1);
assertEquals(34.00, pointList.getEle(5), .1);
} else {
assertEquals(358.3, res.getDistance(), .1);
assertEquals(17.0, pointList.getEle(0), .1);
assertEquals(23.0, pointList.getEle(1), .1);
assertEquals(23.0, pointList.getEle(2), .1);
assertEquals(41.0, pointList.getEle(3), .1);
assertEquals(19.0, pointList.getEle(4), .1);
assertEquals(34.0, pointList.getEle(5), .1);
}
}
use of org.junit.jupiter.params.provider.ValueSource in project graphhopper by graphhopper.
the class NodeBasedNodeContractorTest method testDirectedGraph.
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testDirectedGraph(boolean reverse) {
// 5 6 7
// \|/
// 4-3_1<-\ 10
// \_|/
// 0___2_11
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 2).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(10, 2).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(11, 2).setDistance(2));
// create a longer one directional edge => no longish one-dir shortcut should be created
final EdgeIteratorState edge2to1bidirected = GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 1).setDistance(2));
final EdgeIteratorState edge2to1directed = GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 1).setDistance(10));
final EdgeIteratorState edge1to3 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 3).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 4).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 5).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 6).setDistance(2));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 7).setDistance(2));
freeze();
setMaxLevelOnAllNodes();
// directed one
if (reverse) {
contractInOrder(1, 0, 11, 10, 4, 5, 6, 7, 3, 2);
checkShortcuts(expectedShortcut(3, 2, edge1to3, edge2to1bidirected, true, true));
} else {
contractInOrder(1, 0, 11, 10, 4, 5, 6, 7, 2, 3);
checkShortcuts(expectedShortcut(2, 3, edge2to1bidirected, edge1to3, true, true));
}
}
use of org.junit.jupiter.params.provider.ValueSource in project graphhopper by graphhopper.
the class NodeBasedNodeContractorTest method testShortcutMergeBug.
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testShortcutMergeBug(boolean reverse) {
// We refer to this real world situation http://www.openstreetmap.org/#map=19/52.71205/-1.77326
// assume the following graph:
//
// ---1---->----2-----3
// \--------/
//
// where there are two roads from 1 to 2 and the directed road has a smaller weight. to get from 2 to 1 we
// have to use the bidirectional edge despite the higher weight and therefore we need an extra shortcut for
// this.
final EdgeIteratorState edge1to2bidirected = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(2));
final EdgeIteratorState edge1to2directed = GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 2).setDistance(1));
final EdgeIteratorState edge2to3 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 3).setDistance(1));
freeze();
setMaxLevelOnAllNodes();
if (reverse) {
contractInOrder(2, 1, 3);
checkShortcuts(expectedShortcut(1, 3, edge1to2directed, edge2to3, true, false), expectedShortcut(1, 3, edge1to2bidirected, edge2to3, false, true));
} else {
contractInOrder(2, 3, 1);
checkShortcuts(expectedShortcut(3, 1, edge2to3, edge1to2bidirected, true, false), expectedShortcut(3, 1, edge2to3, edge1to2directed, false, true));
}
}
use of org.junit.jupiter.params.provider.ValueSource in project graphhopper by graphhopper.
the class LocationIndexTreeTest method closeToTowerNode.
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void closeToTowerNode(boolean snapAtBase) {
// 0 - 1
GraphHopperStorage graph = new GraphBuilder(encodingManager).create();
NodeAccess na = graph.getNodeAccess();
na.setNode(0, 51.985500, 19.254000);
na.setNode(1, 51.986000, 19.255000);
DistancePlaneProjection distCalc = new DistancePlaneProjection();
// we query the location index close to node 0. since the query point is so close to the tower node we expect
// a TOWER snap. this should not depend on whether node 0 is the base or adj node of our edge.
final int snapNode = 0;
final int base = snapAtBase ? 0 : 1;
final int adj = snapAtBase ? 1 : 0;
graph.edge(base, adj).setDistance(distCalc.calcDist(na.getLat(0), na.getLon(0), na.getLat(1), na.getLon(1)));
LocationIndexTree index = new LocationIndexTree(graph, graph.getDirectory());
index.prepareIndex();
GHPoint queryPoint = new GHPoint(51.9855003, 19.2540003);
double distFromTower = distCalc.calcDist(queryPoint.lat, queryPoint.lon, na.getLat(snapNode), na.getLon(snapNode));
assertTrue(distFromTower < 0.1);
Snap snap = index.findClosest(queryPoint.lat, queryPoint.lon, EdgeFilter.ALL_EDGES);
assertEquals(Snap.Position.TOWER, snap.getSnappedPosition());
}
use of org.junit.jupiter.params.provider.ValueSource in project gocd by gocd.
the class ContentTypeNegotiationMessageRendererTest method shouldGenerateJSONResponseMessageForContentType.
@ParameterizedTest
@ValueSource(strings = { MediaType.APPLICATION_JSON_VALUE, "application/vnd.go.cd.v1+json", "application/vnd.go.cd.v2+json", "application/vnd.go.cd.v3+json", "application/vnd.go.cd.v4+json", "application/vnd.go.cd.v5+json", "application/vnd.go.cd.v6+json", "application/vnd.go.cd.v7+json", "application/vnd.go.cd.v8+json", "application/vnd.go.cd.v9+json", "application/vnd.go.cd.v50+json", "application/vnd.go.cd.v99+json" })
void shouldGenerateJSONResponseMessageForContentType(String contentType) {
final MockHttpServletRequest request = HttpRequestBuilder.GET("/").withHeader("Accept", contentType).build();
final ContentTypeAwareResponse response = new ContentTypeNegotiationMessageRenderer().getResponse(request);
assertThat(response.getContentType().toString()).isEqualTo(contentType);
assertThat(response.getFormattedMessage("foo")).isEqualTo("{\n \"message\": \"foo\"\n}");
}
Aggregations