/** Test case for extracting paths */ @Test public void testPath() { graph.makeEdge("a", "b", "cost", (double) 1); graph.makeEdge("b", "c", "cost", (double) 1); graph.makeEdge("c", "d", "cost", (double) 1); graph.makeEdge("d", "e", "cost", (double) 1); graph.makeEdge("e", "f", "cost", (double) 1); FloydWarshall<Double> floydWarshall = new FloydWarshall<Double>( 0.0, Double.MAX_VALUE, Direction.OUTGOING, CommonEvaluators.doubleCostEvaluator("cost"), new org.neo4j.graphalgo.impl.util.DoubleAdder(), new org.neo4j.graphalgo.impl.util.DoubleComparator(), graph.getAllNodes(), graph.getAllEdges()); List<Node> path = floydWarshall.getPath(graph.getNode("a"), graph.getNode("f")); assertTrue(path.size() == 6); assertTrue(path.get(0).equals(graph.getNode("a"))); assertTrue(path.get(1).equals(graph.getNode("b"))); assertTrue(path.get(2).equals(graph.getNode("c"))); assertTrue(path.get(3).equals(graph.getNode("d"))); assertTrue(path.get(4).equals(graph.getNode("e"))); assertTrue(path.get(5).equals(graph.getNode("f"))); }
/** Test case for paths of length 0 and 1, and an impossible path */ @Test public void testMinimal() { graph.makeEdge("a", "b", "cost", (double) 1); graph.makeEdge("a", "c", "cost", (double) 1); graph.makeEdge("a", "d", "cost", (double) 1); graph.makeEdge("a", "e", "cost", (double) 1); graph.makeEdge("b", "c", "cost", (double) 1); graph.makeEdge("c", "d", "cost", (double) 1); graph.makeEdge("d", "e", "cost", (double) 1); graph.makeEdge("e", "b", "cost", (double) 1); FloydWarshall<Double> floydWarshall = new FloydWarshall<Double>( 0.0, Double.MAX_VALUE, Direction.OUTGOING, CommonEvaluators.doubleCostEvaluator("cost"), new org.neo4j.graphalgo.impl.util.DoubleAdder(), new org.neo4j.graphalgo.impl.util.DoubleComparator(), graph.getAllNodes(), graph.getAllEdges()); assertTrue(floydWarshall.getCost(graph.getNode("a"), graph.getNode("a")) == 0.0); assertTrue(floydWarshall.getCost(graph.getNode("a"), graph.getNode("b")) == 1.0); assertTrue(floydWarshall.getCost(graph.getNode("b"), graph.getNode("a")) == Double.MAX_VALUE); }