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 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); }