@Test public void testDirectedGraphBug2() { GraphHopperStorage graph = createGHStorage(false); graph.edge(0, 1, 1, false); graph.edge(1, 2, 1, false); graph.edge(2, 3, 1, false); graph.edge(3, 1, 4, true); Path p = createAlgo(graph).calcPath(0, 3); assertEquals(IntArrayList.from(new int[]{0, 1, 2, 3}), p.calcNodes()); }
@Test public void testSetTooBigDistance_435() { graph = createGHStorage(); double maxDist = EdgeAccess.MAX_DIST; EdgeIteratorState edge1 = graph.edge(0, 1, maxDist, true); assertEquals(maxDist, edge1.getDistance(), 1); // max out should NOT lead to infinity as this leads fast to NaN! try { graph.edge(0, 2, maxDist + 1, true); } catch (Exception ex) { assertTrue(ex.getMessage(), ex.getMessage().startsWith("Distance too large")); } }
@Test public void testNodeOrderingRegression() { // 1 -> 2 -> 0 GraphHopperStorage g = createStorage(em); g.edge(1, 2, 1, false); g.edge(2, 0, 1, false); PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(carFlagEncoder)). setMinOneWayNetworkSize(2); int removedEdges = instance.removeDeadEndUnvisitedNetworks(new PrepEdgeFilter(carFlagEncoder)); assertEquals(2, removedEdges); }
@Test public void testSetNodes() { graph = createGHStorage(); NodeAccess na = graph.getNodeAccess(); for (int i = 0; i < defaultSize * 2; i++) { na.setNode(i, 2 * i, 3 * i); } graph.edge(defaultSize + 1, defaultSize + 2, 10, true); graph.edge(defaultSize + 1, defaultSize + 3, 10, true); assertEquals(2, GHUtility.count(carAllExplorer.setBaseNode(defaultSize + 1))); }
@Test public void testContractNode_directed_shortcutRequired() { // 0 --> 1 --> 2 final EdgeIteratorState edge1 = graph.edge(0, 1, 1, false); final EdgeIteratorState edge2 = graph.edge(1, 2, 2, false); graph.freeze(); setMaxLevelOnAllNodes(); createNodeContractor().contractNode(1); checkShortcuts(expectedShortcut(0, 2, edge1, edge2, true, false)); }
@Test public void testContractNode_bidirected_shortcutsRequired() { // 0 -- 1 -- 2 final EdgeIteratorState edge1 = graph.edge(0, 1, 1, true); final EdgeIteratorState edge2 = graph.edge(1, 2, 2, true); graph.freeze(); setMaxLevelOnAllNodes(); createNodeContractor().contractNode(1); checkShortcuts(expectedShortcut(0, 2, edge2, edge1, true, true)); }
@Test public void testContractNode_directed_shortcutRequired_reverse() { // 0 <-- 1 <-- 2 final EdgeIteratorState edge1 = graph.edge(2, 1, 1, false); final EdgeIteratorState edge2 = graph.edge(1, 0, 2, false); graph.freeze(); setMaxLevelOnAllNodes(); createNodeContractor().contractNode(1); checkShortcuts(expectedShortcut(0, 2, edge1, edge2, false, true)); }
@Test public void testCalcShortestPath_sourceEqualsTarget() { GraphHopperStorage graph = createGHStorage(false); graph.edge(0, 1, 1, true); graph.edge(1, 2, 2, true); RoutingAlgorithm algo = createAlgo(graph); Path p = algo.calcPath(0, 0); assertEquals(p.toString(), IntArrayList.from(new int[]{0}), p.calcNodes()); assertEquals(p.toString(), 0, p.getDistance(), 1.e-6); }
@Test public void testEnsureSize() { Directory dir = new RAMDirectory(); graph = newGHStorage(dir, false).create(defaultSize); int roughEdgeRowLength = 4 * 8; int testIndex = dir.find("edges", DAType.RAM_INT).getSegmentSize() * 3 / roughEdgeRowLength; // we need a big node index to trigger multiple segments, but low enough to avoid OOM graph.edge(0, testIndex, 10, true); // test if optimize works without error graph.optimize(); }
@Test public void testNameIndex() { graph = createGHStorage(); EdgeIteratorState iter1 = graph.edge(0, 1, 10, true); iter1.setName("named street1"); EdgeIteratorState iter2 = graph.edge(0, 1, 10, true); iter2.setName("named street2"); assertEquals("named street1", graph.getEdgeIteratorState(iter1.getEdge(), iter1.getAdjNode()).getName()); assertEquals("named street2", graph.getEdgeIteratorState(iter2.getEdge(), iter2.getAdjNode()).getName()); }
@Test public void testFootMix() { graph = createGHStorage(); graph.edge(0, 1).setDistance(10).setFlags(footEncoder.setProperties(10, true, true)); graph.edge(0, 2).setDistance(10).setFlags(carEncoder.setProperties(10, true, true)); graph.edge(0, 3).setDistance(10).setFlags(footEncoder.setProperties(10, true, true) | carEncoder.setProperties(10, true, true)); EdgeExplorer footOutExplorer = graph.createEdgeExplorer(DefaultEdgeFilter.outEdges(footEncoder)); assertEquals(GHUtility.asSet(3, 1), GHUtility.getNeighbors(footOutExplorer.setBaseNode(0))); assertEquals(GHUtility.asSet(3, 2), GHUtility.getNeighbors(carOutExplorer.setBaseNode(0))); }
@Test public void testEdgeReturn() { graph = createGHStorage(); EdgeIteratorState iter = graph.edge(4, 10).setDistance(100).setFlags(carEncoder.setProperties(10, true, false)); assertEquals(4, iter.getBaseNode()); assertEquals(10, iter.getAdjNode()); iter = graph.edge(14, 10).setDistance(100).setFlags(carEncoder.setProperties(10, true, false)); assertEquals(14, iter.getBaseNode()); assertEquals(10, iter.getAdjNode()); }
@Test public void testCheckFirstNode() { graph = createGHStorage(); assertEquals(0, count(carAllExplorer.setBaseNode(1))); graph.edge(0, 1, 12, true); assertEquals(1, count(carAllExplorer.setBaseNode(1))); }
@Test public void testCopyProperties() { graph = createGHStorage(); EdgeIteratorState edge = graph.edge(1, 3, 10, false).setName("testing").setWayGeometry(Helper.createPointList(1, 2)); EdgeIteratorState newEdge = graph.edge(1, 3, 10, false); edge.copyPropertiesTo(newEdge); assertEquals(edge.getName(), newEdge.getName()); assertEquals(edge.getDistance(), newEdge.getDistance(), 1e-7); assertEquals(edge.getFlags(), newEdge.getFlags()); assertEquals(edge.fetchWayGeometry(0), newEdge.fetchWayGeometry(0)); }
@Test public void testSave_and_Freeze() throws IOException { graph = newGHStorage(new RAMDirectory(defaultGraphLoc, true), true).create(defaultSize); graph.edge(1, 0); graph.freeze(); graph.flush(); graph.close(); graph = newGHStorage(new MMapDirectory(defaultGraphLoc), true); assertTrue(graph.loadExisting()); assertEquals(2, graph.getNodes()); assertTrue(graph.isFrozen()); }
@Test public void testRoutingFailsWithInvalidGraph_issue665() { GraphHopperStorage graph = new GraphHopperStorage( new RAMDirectory(), em, true, new GraphExtension.NoOpExtension()); graph.create(100); ReaderWay way = new ReaderWay(0); way.setTag("route", "ferry"); long includeWay = em.acceptWay(way); long relationFlags = 0; long wayFlags = em.handleWayTags(way, includeWay, relationFlags); graph.edge(0, 1).setDistance(247).setFlags(wayFlags); assertTrue(isGraphValid(graph, encoder)); }