trying to test
This commit is contained in:
parent
b45ff5d930
commit
e728c77982
1 changed files with 41 additions and 31 deletions
|
@ -1,41 +1,21 @@
|
||||||
package org.insa.graphs.algorithm.shortestpath;
|
package org.insa.graphs.algorithm.shortestpath;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
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.BufferedInputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
import org.insa.graphs.algorithm.ArcInspector;
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
|
|
||||||
import org.insa.graphs.model.Graph;
|
import org.insa.graphs.model.Graph;
|
||||||
import org.insa.graphs.model.Path;
|
import org.insa.graphs.model.Path;
|
||||||
import org.insa.graphs.model.io.BinaryGraphReader;
|
import org.insa.graphs.model.io.BinaryGraphReader;
|
||||||
import org.insa.graphs.model.io.BinaryPathReader;
|
import org.insa.graphs.model.io.BinaryPathReader;
|
||||||
import org.insa.graphs.model.io.GraphReader;
|
import org.insa.graphs.model.io.GraphReader;
|
||||||
import org.insa.graphs.model.io.PathReader;
|
import org.insa.graphs.model.io.PathReader;
|
||||||
import java.io.IOException;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class DijkstraAlgorithmTest {
|
public class DijkstraAlgorithmTest {
|
||||||
|
|
||||||
|
@ -45,11 +25,12 @@ public class DijkstraAlgorithmTest {
|
||||||
public PathReader pathReader;
|
public PathReader pathReader;
|
||||||
public Path path;
|
public Path path;
|
||||||
|
|
||||||
@Before
|
|
||||||
|
//@Before
|
||||||
public void init() {
|
public void init() {
|
||||||
// Visit these directory to see the list of available files on Commetud.
|
// Visit these directory to see the list of available files on Commetud.
|
||||||
// When running with VSC, paths are relative to the BE_Graphes directory.
|
// 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";
|
final String pathName = "./Paths/path_fr31insa_rangueil_r2.path";
|
||||||
System.out.println("Working Directory = " + System.getProperty("user.dir"));
|
System.out.println("Working Directory = " + System.getProperty("user.dir"));
|
||||||
// Create a graph reader.
|
// Create a graph reader.
|
||||||
|
@ -58,15 +39,22 @@ public class DijkstraAlgorithmTest {
|
||||||
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))));
|
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))));
|
||||||
|
|
||||||
// Read the graph. X
|
// Read the graph. X
|
||||||
final Graph graph = reader.read();
|
this.graph = reader.read();
|
||||||
|
|
||||||
// Create a PathReader.
|
// Create a PathReader.
|
||||||
final PathReader pathReader = new BinaryPathReader(new DataInputStream(new BufferedInputStream(new FileInputStream(pathName))));
|
final PathReader pathReader = new BinaryPathReader(new DataInputStream(new BufferedInputStream(new FileInputStream(pathName))));
|
||||||
|
|
||||||
// Read the path.
|
// 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
|
@Test
|
||||||
|
@ -74,7 +62,29 @@ public class DijkstraAlgorithmTest {
|
||||||
// fonction pour code au dessus
|
// fonction pour code au dessus
|
||||||
// appeler constructeur dijkstra
|
// appeler constructeur dijkstra
|
||||||
// donner le path à afficher en renvoyant le path de dijkstra dans path.
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue