plus de data pour junit
This commit is contained in:
parent
d1acc6cdf5
commit
442a06e0e8
2 changed files with 48 additions and 74 deletions
|
@ -20,7 +20,7 @@ public class ArcInspectorFactory {
|
|||
|
||||
// Common filters:
|
||||
|
||||
// No filter (all arcs allowed):
|
||||
// No filter (all arcs allowed), shortest:
|
||||
filters.add(new ArcInspector() {
|
||||
@Override
|
||||
public boolean isAllowed(Arc arc) {
|
||||
|
@ -78,7 +78,7 @@ public class ArcInspectorFactory {
|
|||
}
|
||||
});
|
||||
|
||||
// Only road allowed for cars and time:
|
||||
// All allowed and time?
|
||||
|
||||
filters.add(new ArcInspector() {
|
||||
@Override
|
||||
|
@ -107,7 +107,7 @@ public class ArcInspectorFactory {
|
|||
}
|
||||
});
|
||||
|
||||
filters.add(new ArcInspector() {
|
||||
filters.add(new ArcInspector() {// *this one* seems to be fastest path with car
|
||||
@Override
|
||||
public boolean isAllowed(Arc arc) {
|
||||
return arc.getRoadInformation().getAccessRestrictions()
|
||||
|
|
|
@ -32,10 +32,19 @@ public class DijkstraAlgorithmTest{
|
|||
@SuppressWarnings("unused")
|
||||
private static Arc a2b, a2c, a2e, b2c, c2d_1, c2d_2, c2d_3, c2a, d2a, d2e, e2d;
|
||||
|
||||
// Some paths...
|
||||
private static Path emptyPath, singleNodePath, shortPath, longPath, loopPath, longLoopPath,
|
||||
invalidPath;
|
||||
|
||||
private static ShortestPathData dataal, datacl, dataat, datact, datapt, onenodata, emptydata, invalidata;
|
||||
|
||||
// permet de savoir quels arcs autoriser(cf l.187 excel ggdoc)
|
||||
private static ArcInspector alllen = ArcInspectorFactory.getAllFilters().get(0);
|
||||
private static ArcInspector carlen = ArcInspectorFactory.getAllFilters().get(1);
|
||||
private static ArcInspector alltime = ArcInspectorFactory.getAllFilters().get(2);
|
||||
private static ArcInspector cartime = ArcInspectorFactory.getAllFilters().get(3);
|
||||
private static ArcInspector pietime = ArcInspectorFactory.getAllFilters().get(4);
|
||||
|
||||
private static DijkstraAlgorithm dijkal, dijkcl, dijkat, dijkct, dijkpt, onenodijk, emptydijk, invalidijk;
|
||||
private static BellmanFordAlgorithm bfaal, bfacl, bfaat, bfact, bfapt;
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void initAll() throws IOException {
|
||||
|
||||
|
@ -63,53 +72,39 @@ public class DijkstraAlgorithmTest{
|
|||
|
||||
graph = new Graph("ID", "", Arrays.asList(nodes), null);
|
||||
|
||||
emptyPath = new Path(graph, new ArrayList<Arc>());
|
||||
singleNodePath = new Path(graph, nodes[1]);
|
||||
shortPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1 }));
|
||||
longPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1, d2e }));
|
||||
loopPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1, d2a }));
|
||||
longLoopPath = new Path(graph,
|
||||
Arrays.asList(new Arc[] { a2b, b2c, c2d_1, d2a, a2c, c2d_3, d2a, a2b, b2c }));
|
||||
invalidPath = new Path(graph, Arrays.asList(new Arc[] { a2b, c2d_1, d2e }));
|
||||
//initialisation des datas
|
||||
dataal= new ShortestPathData(graph, null, null, alllen);
|
||||
datacl= new ShortestPathData(graph, null, null, carlen);
|
||||
dataat= new ShortestPathData(graph, null, null, alltime);
|
||||
datact= new ShortestPathData(graph, null, null, cartime);
|
||||
datapt= new ShortestPathData(graph, null, null, pietime);
|
||||
onenodata=new ShortestPathData(graph, nodes[2], nodes[2], pietime);
|
||||
emptydata=new ShortestPathData(graph, null, null, pietime);
|
||||
invalidata=new ShortestPathData(graph, null, null, pietime);
|
||||
|
||||
//initialisation des Dijkstras
|
||||
dijkal=new DijkstraAlgorithm(dataal);
|
||||
dijkcl=new DijkstraAlgorithm(datacl);
|
||||
dijkat=new DijkstraAlgorithm(dataat);
|
||||
dijkct=new DijkstraAlgorithm(datact);
|
||||
dijkpt=new DijkstraAlgorithm(datapt);
|
||||
onenodijk=new DijkstraAlgorithm(onenodata);
|
||||
emptydijk=new DijkstraAlgorithm(emptydata);
|
||||
invalidijk=new DijkstraAlgorithm(invalidata);
|
||||
|
||||
//initialisation des Bellman-Ford pour comparaison
|
||||
bfaal=new BellmanFordAlgorithm(dataal);
|
||||
bfacl=new BellmanFordAlgorithm(datacl);
|
||||
bfaat=new BellmanFordAlgorithm(dataat);
|
||||
bfact=new BellmanFordAlgorithm(datact);
|
||||
bfapt=new BellmanFordAlgorithm(datapt);
|
||||
|
||||
}
|
||||
//---fin de la copie de PathTest.java
|
||||
|
||||
//regarder LAUNCH.JAVA pour ouvrir une map
|
||||
|
||||
private static DijkstraAlgorithm samenode, bikinsatime, bikinsalong, invalinsa;
|
||||
private static BellmanFordAlgorithm Bsamenode, Bbikinsatime, Bbikinsalong, Binvalinsa;
|
||||
private static ShortestPathData samenodespd, bikinsatimespd, bikinsalongspd, invalinsaspd;
|
||||
}
|
||||
|
||||
// (cf l.187 excel ggdoc) permet de savoir quels arcs autoriser
|
||||
private ArcInspector inspecteuruno=ArcInspectorFactory.getAllFilters().get(0);// No filter (all arcs allowed)
|
||||
private ArcInspector inspecteurtres=ArcInspectorFactory.getAllFilters().get(2);// Only road allowed for cars and time
|
||||
|
||||
|
||||
//créer plus et avec des maps différentes
|
||||
//faire des test spécifiques pour longs trajets
|
||||
|
||||
/*@BeforeClass
|
||||
public static void initAllbis() {
|
||||
//en fait pas sûr que ça marche comme ça, voir avec Launch
|
||||
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);
|
||||
}*/
|
||||
|
||||
|
||||
//comment trouver les noeuds dans une map? Ne comparer que les grands chemins (qui font ouvrir la map) avec BF
|
||||
|
||||
/*(Test faits directement via la console et DijkstraAlgorithm.java, actuellement commentés:
|
||||
-coûts croissants
|
||||
-nbr successeurs cohérents
|
||||
|
@ -117,44 +112,23 @@ public class DijkstraAlgorithmTest{
|
|||
|
||||
@Test
|
||||
public void cheminValide() {
|
||||
ShortestPathData data1=new ShortestPathData(null, null, null, inspecteuruno);
|
||||
ShortestPathData data3=new ShortestPathData(null, null, null, inspecteurtres);
|
||||
ShortestPathAlgorithm Dijkstra1=new DijkstraAlgorithm(data1);
|
||||
ShortestPathAlgorithm Dijkstra3=new DijkstraAlgorithm(data3);
|
||||
assertTrue(Dijkstra1.doRun().getPath().isValid());
|
||||
assertTrue(Dijkstra3.doRun().getPath().isValid());
|
||||
assertTrue(samenode.doRun().getPath().isValid());
|
||||
assertTrue(bikinsatime.doRun().getPath().isValid());
|
||||
assertTrue(bikinsalong.doRun().getPath().isValid());
|
||||
assertFalse(invalinsa.doRun().getPath().isValid());
|
||||
assertTrue(dijkal.doRun().getPath().isValid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void faisable() {
|
||||
ShortestPathData data1=new ShortestPathData(null, null, null, inspecteuruno);
|
||||
ShortestPathData data3=new ShortestPathData(null, null, null, inspecteurtres);
|
||||
ShortestPathAlgorithm Dijkstra1=new DijkstraAlgorithm(data1);
|
||||
ShortestPathAlgorithm Dijkstra3=new DijkstraAlgorithm(data3);
|
||||
assertTrue(Dijkstra1.doRun().isFeasible());
|
||||
assertTrue(Dijkstra3.doRun().isFeasible());
|
||||
assertTrue(samenode.doRun().isFeasible());
|
||||
assertTrue(bikinsatime.doRun().isFeasible());
|
||||
assertTrue(bikinsalong.doRun().isFeasible());
|
||||
assertFalse(invalinsa.doRun().isFeasible());
|
||||
assertTrue(dijkal.doRun().isFeasible());
|
||||
}
|
||||
|
||||
|
||||
//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()));
|
||||
assertTrue(Float.compare(dijkal.doRun().getPath().getLength(),bfaal.doRun().getPath().getLength())==0);
|
||||
}
|
||||
|
||||
//tests applicables aussi pour des grands scénarios:
|
||||
//...
|
||||
|
||||
|
||||
//graph = new BinaryGraphReader(new DataInputStream(new BufferedInputStream(new FileInputStream("a")))).read;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue