protected GraphStorage createGraph() { GraphStorage g = createGraph(defaultGraphLoc, false); carOutExplorer = g.createEdgeExplorer(carOutFilter); carInExplorer = g.createEdgeExplorer(carInFilter); carAllExplorer = g.createEdgeExplorer(); return g; }
@Test public void testDetachEdge() { graph = createGraph(); graph.edge(0, 1, 2, true); long flags = carEncoder.setProperties(10, true, false); graph.edge(0, 2, 2, true).setWayGeometry(Helper.createPointList(1, 2, 3, 4)).setFlags(flags); graph.edge(1, 2, 2, true); EdgeIterator iter = graph.createEdgeExplorer().setBaseNode(0); try { // currently not possible to detach without next, without introducing a new property inside // EdgeIterable iter.detach(false); assertTrue(false); } catch (Exception ex) { } iter.next(); EdgeIteratorState edgeState2 = iter.detach(false); assertEquals(2, iter.getAdjNode()); assertEquals(1, edgeState2.fetchWayGeometry(0).getLatitude(0), 1e-1); assertEquals(2, edgeState2.getAdjNode()); assertTrue(carEncoder.isBool(edgeState2.getFlags(), FlagEncoder.K_FORWARD)); EdgeIteratorState edgeState3 = iter.detach(true); assertEquals(0, edgeState3.getAdjNode()); assertEquals(2, edgeState3.getBaseNode()); assertEquals(3, edgeState3.fetchWayGeometry(0).getLatitude(0), 1e-1); assertFalse(carEncoder.isBool(edgeState3.getFlags(), FlagEncoder.K_FORWARD)); assertEquals(GHUtility.getEdge(graph, 0, 2).getFlags(), edgeState2.getFlags()); assertEquals(GHUtility.getEdge(graph, 2, 0).getFlags(), edgeState3.getFlags()); iter.next(); assertEquals(1, iter.getAdjNode()); assertEquals(2, edgeState2.getAdjNode()); assertEquals(2, edgeState3.getBaseNode()); assertEquals(0, iter.fetchWayGeometry(0).size()); assertEquals(1, edgeState2.fetchWayGeometry(0).getLatitude(0), 1e-1); assertEquals(3, edgeState3.fetchWayGeometry(0).getLatitude(0), 1e-1); // #162 a directed self referencing edge should be able to reverse its state too graph.edge(3, 3, 2, true).setFlags(flags); EdgeIterator iter2 = graph.createEdgeExplorer().setBaseNode(3); iter2.next(); assertEquals(edgeState2.getFlags(), iter2.detach(false).getFlags()); assertEquals(edgeState3.getFlags(), iter2.detach(true).getFlags()); }
@Test public void testFootMix() { graph = createGraph(); 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(new DefaultEdgeFilter(footEncoder, false, true)); assertEquals(GHUtility.asSet(3, 1), GHUtility.getNeighbors(footOutExplorer.setBaseNode(0))); assertEquals(GHUtility.asSet(3, 2), GHUtility.getNeighbors(carOutExplorer.setBaseNode(0))); }