diff --git a/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/DijkstraTest.java b/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/DijkstraTest.java index e3205de..87ba2cb 100644 --- a/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/DijkstraTest.java +++ b/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/DijkstraTest.java @@ -15,43 +15,45 @@ import java.io.IOException; import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.assertEquals; +import java.util.Random; public class DijkstraTest { - private static String mapName; - private static GraphReader reader; - private static Graph graph; - private static Node origin; - private static Node destination; - private static DijkstraAlgorithm dijkstra; - private static BellmanFordAlgorithm bellman; - private static ShortestPathSolution solDijkstra; - private static ShortestPathSolution solBellman; + private static String mapName1; + private static GraphReader reader1; + private static Graph graph1; + private static Node origin1; + private static Node destination1; + private static DijkstraAlgorithm dijkstra1; + private static BellmanFordAlgorithm bellman1; + private static ShortestPathSolution solDijkstra1; + private static ShortestPathSolution solBellman1; + private static Random random1 = new Random(); @BeforeClass public static void initAll() throws IOException{ - mapName = "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr"; + mapName1 = "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr"; // Create a graph reader. - reader = new BinaryGraphReader( - new DataInputStream(new BufferedInputStream(new FileInputStream(mapName)))); + reader1 = new BinaryGraphReader( + new DataInputStream(new BufferedInputStream(new FileInputStream(mapName1)))); // Read the graph. - graph = reader.read(); - //final int numNodes = graph.size(); - origin = graph.get(0); - destination = graph.get(6); - dijkstra = new DijkstraAlgorithm(new ShortestPathData(graph,origin,destination,ArcInspectorFactory.getAllFilters().get(0))); - bellman = new BellmanFordAlgorithm(new ShortestPathData(graph,origin,destination,ArcInspectorFactory.getAllFilters().get(0))); - solDijkstra = dijkstra.run(); - solBellman = bellman.run(); + graph1 = reader1.read(); + final int numNodes1 = graph1.size(); + origin1 = graph1.get(random1.nextInt(numNodes1)); + destination1 = graph1.get(random1.nextInt(numNodes1)); + dijkstra1 = new DijkstraAlgorithm(new ShortestPathData(graph1,origin1,destination1,ArcInspectorFactory.getAllFilters().get(0))); + bellman1 = new BellmanFordAlgorithm(new ShortestPathData(graph1,origin1,destination1,ArcInspectorFactory.getAllFilters().get(0))); + solDijkstra1 = dijkstra1.run(); + solBellman1 = bellman1.run(); } @Test - public void testDijkstra(){ - assertEquals(solDijkstra.getPath().getLength(),solBellman.getPath().getLength(),0.00001); + public void testDijkstra1(){ + assertEquals(solDijkstra1.getPath().getLength(),solBellman1.getPath().getLength(),0.00001); }