trying to test

This commit is contained in:
Clement Lacau 2024-05-04 23:39:00 +02:00
parent b45ff5d930
commit e728c77982

View file

@ -1,41 +1,21 @@
package org.insa.graphs.algorithm.shortestpath;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.IntStream;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import org.insa.graphs.algorithm.ArcInspector;
import org.insa.graphs.model.Graph;
import org.insa.graphs.model.Path;
import org.insa.graphs.model.io.BinaryGraphReader;
import org.insa.graphs.model.io.BinaryPathReader;
import org.insa.graphs.model.io.GraphReader;
import org.insa.graphs.model.io.PathReader;
import java.io.IOException;
import org.junit.Test;
public class DijkstraAlgorithmTest {
@ -44,12 +24,13 @@ public class DijkstraAlgorithmTest {
public Graph graph;
public PathReader pathReader;
public Path path;
@Before
//@Before
public void init() {
// Visit these directory to see the list of available files on Commetud.
// When running with VSC, paths are relative to the BE_Graphes directory.
final String mapName = "../../../../../../../../../Maps/insa.mapgr";
final String mapName = "./Maps/insa.mapgr";
final String pathName = "./Paths/path_fr31insa_rangueil_r2.path";
System.out.println("Working Directory = " + System.getProperty("user.dir"));
// Create a graph reader.
@ -58,15 +39,22 @@ public class DijkstraAlgorithmTest {
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))));
// Read the graph. X
final Graph graph = reader.read();
this.graph = reader.read();
// Create a PathReader.
final PathReader pathReader = new BinaryPathReader(new DataInputStream(new BufferedInputStream(new FileInputStream(pathName))));
// Read the path.
final Path path = pathReader.readPath(graph);
this.path = pathReader.readPath(graph);
}
catch (FileNotFoundException e) {
System.err.println("File not found: " + e.getMessage());
fail("File not found: " + e.getMessage());
}
catch (IOException e ) {
System.err.println("Error reading file: " + e.getMessage());
fail("Error reading file: " + e.getMessage());
}
catch (IOException e ) {}
}
@Test
@ -74,7 +62,29 @@ public class DijkstraAlgorithmTest {
// fonction pour code au dessus
// appeler constructeur dijkstra
// donner le path à afficher en renvoyant le path de dijkstra dans path.
public void Test_Dijkstra() {
// Chemin court => Bellman OK et vérifié. On compare les résultats obtenus par les 2 algos
public void Test_Toulouse_court_chemin() {
ArcInspector arcInspector;
ShortestPathData data = new ShortestPathData(this.graph, this.path.getOrigin(), this.path.getDestination(), null);
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
ShortestPathSolution dijk_path = dijkstra.doRun();
BellmanFordAlgorithm bellman = new BellmanFordAlgorithm(data);
ShortestPathSolution bell_path = bellman.doRun();
assert(dijk_path.getPath() == bell_path.getPath());
}
// Long chemin => Bellman trop long, on compare dijkstra au chemin récupéré directement
public void Test_Toulouse_long_chemin() {
init();
ArcInspector arcInspector;
ShortestPathData data = new ShortestPathData(this.graph, this.path.getOrigin(), this.path.getDestination(), null);
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
ShortestPathSolution dijk_path = dijkstra.doRun();
assert(dijk_path.getPath() == this.path);
}
}