From 5de1caec471ad0e48864f6bd2b4aee4e87334fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yanis=20Mah=C3=A9?= Date: Tue, 12 May 2026 15:45:53 +0200 Subject: [PATCH] Finished ShortestPathTest for Bellman and Dijkstra --- .../algorithm/utils/ShortestPathTest.java | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/ShortestPathTest.java b/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/ShortestPathTest.java index 747f415..8ca1d79 100644 --- a/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/ShortestPathTest.java +++ b/be-graphes-algos/src/test/java/org/insa/graphs/algorithm/utils/ShortestPathTest.java @@ -31,12 +31,14 @@ public class ShortestPathTest { final static String midiPyreneesFile = "/mnt/commetud/3emeAnneeMIC/Graphes-et-Algorithmes/Maps/midi-pyrenees.mapgr"; final static String hauteGaronneFile = "/mnt/commetud/3emeAnneeMIC/Graphes-et-Algorithmes/Maps/haute-garonne.mapgr"; final static String insaFile = "/mnt/commetud/3emeAnneeMIC/Graphes-et-Algorithmes/Maps/insa.mapgr"; + final static String belgiqueFile = "/mnt/commetud/3emeAnneeMIC/Graphes-et-Algorithmes/Maps/belgium.mapgr"; final static String insaBikiniCanalPathFile = "/mnt/commetud/3emeAnneeMIC/Graphes-et-Algorithmes/Paths/path_fr31_insa_bikini_canal.path"; static Graph midiPyrenees; static Graph hauteGaronne; static Graph insa; + static Graph belgique; static Path insaBikiniCanal; @@ -59,6 +61,10 @@ public class ShortestPathTest { new BufferedInputStream(new FileInputStream(insaFile))))) { insa = reader.read(); } + try (final GraphReader reader = new BinaryGraphReader(new DataInputStream( + new BufferedInputStream(new FileInputStream(belgiqueFile))))) { + belgique = reader.read(); + } try (final PathReader pathReader = new BinaryPathReader(new DataInputStream( new BufferedInputStream(new FileInputStream(insaBikiniCanalPathFile))))) { @@ -73,7 +79,7 @@ public class ShortestPathTest { @Test - public void testCheminInsaBikiniCanal() { + public void testCheminInsaBikiniCanal() { // En comparant avec un fichier path ShortestPathData insaBikiniCanalPathData = new ShortestPathData(hauteGaronne, insaBikiniCanal.getOrigin(), insaBikiniCanal.getDestination(), noFilterByLengthArcInspector); // System.out.println("" + insaBikiniCanal.getOrigin().getId() +" "+ insaBikiniCanal.getDestination().getId()); ShortestPathAlgorithm bellmanFord = new BellmanFordAlgorithm(insaBikiniCanalPathData); @@ -82,6 +88,9 @@ public class ShortestPathTest { ShortestPathSolution solutionBellmanFord = bellmanFord.run(); ShortestPathSolution solutionDijkstra = dijkstra.run(); + assertEquals(Status.OPTIMAL, solutionBellmanFord.getStatus()); + assertEquals(Status.OPTIMAL, solutionDijkstra.getStatus()); + assertEquals(insaBikiniCanal.getLength(), solutionBellmanFord.getPath().getLength(),1.0); assertEquals(insaBikiniCanal.getLength(), solutionDijkstra.getPath().getLength(), 1.0); @@ -102,4 +111,33 @@ public class ShortestPathTest { assertEquals(Status.INFEASIBLE, solutionDijkstra.getStatus()); } + @Test + public void testCheminLongueurNulle() { + ShortestPathData cheminInexistant = new ShortestPathData(insa, insa.get(940), insa.get(940), noFilterByLengthArcInspector); + ShortestPathAlgorithm bellmanFord = new BellmanFordAlgorithm(cheminInexistant); + ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(cheminInexistant); + + ShortestPathSolution solutionBellmanFord = bellmanFord.run(); + ShortestPathSolution solutionDijkstra = dijkstra.run(); + + assertEquals(Status.INFEASIBLE, solutionBellmanFord.getStatus()); + assertEquals(Status.INFEASIBLE, solutionDijkstra.getStatus()); + + assertNull(solutionBellmanFord.getPath()); + assertNull(solutionDijkstra.getPath()); + } + + @Test + public void testCheminLong() { // En comparant les deux algos + ShortestPathData cheminInexistant = new ShortestPathData(belgique, belgique.get(956754), belgique.get(842938), noFilterByLengthArcInspector); + ShortestPathAlgorithm bellmanFord = new BellmanFordAlgorithm(cheminInexistant); + ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(cheminInexistant); + + ShortestPathSolution solutionBellmanFord = bellmanFord.run(); + ShortestPathSolution solutionDijkstra = dijkstra.run(); + + assertEquals(solutionBellmanFord.getStatus(), solutionDijkstra.getStatus()); + assertEquals(solutionBellmanFord.getPath().getLength(), solutionDijkstra.getPath().getLength(), 1.0); + assertEquals(solutionBellmanFord.getPath().getTravelTime(120), solutionDijkstra.getPath().getTravelTime(120), 1.0); + } }