/** /--2--A--7--B--2--\ S E \----7---C---7----/ */ public void testDijstraTraverserMeeting() { graph.makeEdge("s", "c", "cost", (double) 7); graph.makeEdge("c", "e", "cost", (double) 7); graph.makeEdge("s", "a", "cost", (double) 2); graph.makeEdge("a", "b", "cost", (double) 7); graph.makeEdge("b", "e", "cost", (double) 2); Dijkstra<Double> dijkstra = getDijkstra(graph, 0.0, "s", "e"); assertTrue(dijkstra.getCost() == 11.0); assertTrue(dijkstra.getPathAsNodes() != null); assertTrue(dijkstra.getPathAsNodes().size() == 4); assertTrue(dijkstra.getPathsAsNodes().size() == 1); }
public void testDijkstraChain() { graph.makeEdge("a", "b", "cost", (double) 1); graph.makeEdge("b", "c", "cost", (double) 2); graph.makeEdge("c", "d", "cost", (double) 3); Dijkstra<Double> dijkstra = getDijkstra(graph, 0.0, "a", "d"); assertTrue(dijkstra.getCost() == 6.0); assertTrue(dijkstra.getPathAsNodes() != null); assertTrue(dijkstra.getPathAsNodes().size() == 4); assertTrue(dijkstra.getPathsAsNodes().size() == 1); dijkstra = getDijkstra(graph, 0.0, "d", "a"); assertTrue(dijkstra.getCost() == 6.0); assertTrue(dijkstra.getPathAsNodes().size() == 4); dijkstra = getDijkstra(graph, 0.0, "d", "b"); assertTrue(dijkstra.getCost() == 5.0); assertTrue(dijkstra.getPathAsNodes().size() == 3); assertTrue(dijkstra.getPathAsRelationships().size() == 2); assertTrue(dijkstra.getPath().size() == 5); }
/** Test case for just a single node (path length zero) */ public void testDijkstraMinimal() { graph.makeNode("lonely"); Dijkstra<Double> dijkstra = getDijkstra(graph, 0.0, "lonely", "lonely"); assertTrue(dijkstra.getCost() == 0.0); assertTrue(dijkstra.getPathAsNodes().size() == 1); dijkstra = getDijkstra(graph, 3.0, "lonely", "lonely"); assertTrue(dijkstra.getCost() == 6.0); assertTrue(dijkstra.getPathAsNodes().size() == 1); assertTrue(dijkstra.getPathsAsNodes().size() == 1); }
/** Test case for a path of length zero, with some surrounding nodes */ public void testDijkstraMinimal2() { 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", "f", "cost", (double) 1); Dijkstra<Double> dijkstra = getDijkstra(graph, 0.0, "a", "a"); assertTrue(dijkstra.getCost() == 0.0); assertTrue(dijkstra.getPathAsNodes().size() == 1); dijkstra = getDijkstra(graph, 3.0, "a", "a"); assertTrue(dijkstra.getCost() == 6.0); assertTrue(dijkstra.getPathAsNodes().size() == 1); assertTrue(dijkstra.getPathAsRelationships().size() == 0); assertTrue(dijkstra.getPath().size() == 1); assertTrue(dijkstra.getPathsAsNodes().size() == 1); }