début de junit pour Dijkstra
This commit is contained in:
parent
ce16e03284
commit
e847e06b8d
1 changed files with 95 additions and 0 deletions
|
@ -0,0 +1,95 @@
|
||||||
|
package org.insa.graphs.algorithm.shortestpath;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.insa.graphs.algorithm.shortestpath.*;
|
||||||
|
import org.insa.graphs.model.Arc;
|
||||||
|
import org.insa.graphs.model.Graph;
|
||||||
|
import org.insa.graphs.model.Node;
|
||||||
|
import org.insa.graphs.model.Path;
|
||||||
|
import org.insa.graphs.model.RoadInformation;
|
||||||
|
import org.insa.graphs.model.RoadInformation.RoadType;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class DijkstraAlgorithmTest {
|
||||||
|
|
||||||
|
private static DijkstraAlgorithm samenode, bikinsatime, bikinsalong, invalinsa;
|
||||||
|
private static BellmanFordAlgorithm Bsamenode, Bbikinsatime, Bbikinsalong, Binvalinsa;
|
||||||
|
private static ShortestPathData samenodespd, bikinsatimespd, bikinsalongspd, invalinsaspd;
|
||||||
|
|
||||||
|
private static Graph graph;
|
||||||
|
private static Node origine;//trouver ces nodes
|
||||||
|
private static Node bikini;
|
||||||
|
private static Node inaccessible;
|
||||||
|
//en créer plus et avec des maps différentes
|
||||||
|
//faire des test spécifiques pour longs trajets
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void initAll() {
|
||||||
|
|
||||||
|
samenodespd=new ShortestPathData(graph, null, null, null);
|
||||||
|
bikinsatimespd=new ShortestPathData(graph, null, null, null);
|
||||||
|
bikinsalongspd=new ShortestPathData(graph, null, null, null);
|
||||||
|
invalinsaspd=new ShortestPathData(graph, null, null, null);
|
||||||
|
|
||||||
|
samenode=new DijkstraAlgorithm(samenodespd);
|
||||||
|
bikinsatime=new DijkstraAlgorithm(bikinsatimespd);
|
||||||
|
bikinsalong=new DijkstraAlgorithm(bikinsalongspd);
|
||||||
|
invalinsa=new DijkstraAlgorithm(invalinsaspd);
|
||||||
|
//est-ce que c'est vraiment la bonne manière de faire? car alors très long de rajouter des path à tester
|
||||||
|
Bsamenode=new BellmanFordAlgorithm(samenodespd);
|
||||||
|
Bbikinsatime= new BellmanFordAlgorithm(bikinsatimespd);
|
||||||
|
Bbikinsalong=new BellmanFordAlgorithm(bikinsalongspd);
|
||||||
|
Binvalinsa=new BellmanFordAlgorithm(invalinsaspd);
|
||||||
|
}
|
||||||
|
|
||||||
|
//test faits directement via la console et DijkstraAlgorithm.java:
|
||||||
|
//(coûts croissants)
|
||||||
|
//(nbr successeurs cohérents)
|
||||||
|
//(tas valide)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void cheminValide() {
|
||||||
|
assertTrue(samenode.doRun().getPath().isValid());
|
||||||
|
assertTrue(bikinsatime.doRun().getPath().isValid());
|
||||||
|
assertTrue(bikinsalong.doRun().getPath().isValid());
|
||||||
|
assertFalse(invalinsa.doRun().getPath().isValid());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void faisable() {
|
||||||
|
assertTrue(samenode.doRun().isFeasible());
|
||||||
|
assertTrue(bikinsatime.doRun().isFeasible());
|
||||||
|
assertTrue(bikinsalong.doRun().isFeasible());
|
||||||
|
assertFalse(invalinsa.doRun().isFeasible());
|
||||||
|
}
|
||||||
|
|
||||||
|
//cout calculé par Dijkstra identique à celui calculé par Path (comparaison pas avec ==)
|
||||||
|
//comment ça? Dijkstra ne renvoie pas le cout du path dans ShortestPathSolution, obligé d'utiliser getPath.getCout
|
||||||
|
//sans doute à voir avec comment demander un cout en temps ou en longueur
|
||||||
|
@Test
|
||||||
|
public void sameasPath() {
|
||||||
|
assertTrue(samenode.doRun().getPath().isValid());//à faire
|
||||||
|
assertTrue(bikinsatime.doRun().getPath().isValid());
|
||||||
|
assertTrue(bikinsalong.doRun().getPath().isValid());
|
||||||
|
assertTrue(invalinsa.doRun().getPath().isValid());
|
||||||
|
}
|
||||||
|
|
||||||
|
//résultat identique à Bellman-Ford (sur les petits scénarios)
|
||||||
|
@Test
|
||||||
|
public void sameasBF() {
|
||||||
|
assertTrue(samenode.doRun().getPath().equals(Bsamenode.doRun().getPath()));
|
||||||
|
assertTrue(bikinsatime.doRun().getPath().equals(Bbikinsatime.doRun().getPath()));
|
||||||
|
assertTrue(bikinsalong.doRun().getPath().equals(Bbikinsalong.doRun().getPath()));
|
||||||
|
assertTrue(invalinsa.doRun().getPath().equals(Binvalinsa.doRun().getPath()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//tests applicables aussi pour des grands scénarios
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue