|
@@ -0,0 +1,95 @@
|
|
1
|
+package org.insa.graphs.algorithm.shortestpath;
|
|
2
|
+
|
|
3
|
+import static org.junit.Assert.*;
|
|
4
|
+
|
|
5
|
+import java.io.IOException;
|
|
6
|
+import java.util.ArrayList;
|
|
7
|
+import java.util.Arrays;
|
|
8
|
+
|
|
9
|
+import org.insa.graphs.algorithm.shortestpath.*;
|
|
10
|
+import org.insa.graphs.model.Arc;
|
|
11
|
+import org.insa.graphs.model.Graph;
|
|
12
|
+import org.insa.graphs.model.Node;
|
|
13
|
+import org.insa.graphs.model.Path;
|
|
14
|
+import org.insa.graphs.model.RoadInformation;
|
|
15
|
+import org.insa.graphs.model.RoadInformation.RoadType;
|
|
16
|
+import org.junit.BeforeClass;
|
|
17
|
+import org.junit.Test;
|
|
18
|
+
|
|
19
|
+public class DijkstraAlgorithmTest {
|
|
20
|
+
|
|
21
|
+ private static DijkstraAlgorithm samenode, bikinsatime, bikinsalong, invalinsa;
|
|
22
|
+ private static BellmanFordAlgorithm Bsamenode, Bbikinsatime, Bbikinsalong, Binvalinsa;
|
|
23
|
+ private static ShortestPathData samenodespd, bikinsatimespd, bikinsalongspd, invalinsaspd;
|
|
24
|
+
|
|
25
|
+ private static Graph graph;
|
|
26
|
+ private static Node origine;//trouver ces nodes
|
|
27
|
+ private static Node bikini;
|
|
28
|
+ private static Node inaccessible;
|
|
29
|
+ //en créer plus et avec des maps différentes
|
|
30
|
+ //faire des test spécifiques pour longs trajets
|
|
31
|
+
|
|
32
|
+ @BeforeClass
|
|
33
|
+ public static void initAll() {
|
|
34
|
+
|
|
35
|
+ samenodespd=new ShortestPathData(graph, null, null, null);
|
|
36
|
+ bikinsatimespd=new ShortestPathData(graph, null, null, null);
|
|
37
|
+ bikinsalongspd=new ShortestPathData(graph, null, null, null);
|
|
38
|
+ invalinsaspd=new ShortestPathData(graph, null, null, null);
|
|
39
|
+
|
|
40
|
+ samenode=new DijkstraAlgorithm(samenodespd);
|
|
41
|
+ bikinsatime=new DijkstraAlgorithm(bikinsatimespd);
|
|
42
|
+ bikinsalong=new DijkstraAlgorithm(bikinsalongspd);
|
|
43
|
+ invalinsa=new DijkstraAlgorithm(invalinsaspd);
|
|
44
|
+ //est-ce que c'est vraiment la bonne manière de faire? car alors très long de rajouter des path à tester
|
|
45
|
+ Bsamenode=new BellmanFordAlgorithm(samenodespd);
|
|
46
|
+ Bbikinsatime= new BellmanFordAlgorithm(bikinsatimespd);
|
|
47
|
+ Bbikinsalong=new BellmanFordAlgorithm(bikinsalongspd);
|
|
48
|
+ Binvalinsa=new BellmanFordAlgorithm(invalinsaspd);
|
|
49
|
+ }
|
|
50
|
+
|
|
51
|
+ //test faits directement via la console et DijkstraAlgorithm.java:
|
|
52
|
+ //(coûts croissants)
|
|
53
|
+ //(nbr successeurs cohérents)
|
|
54
|
+ //(tas valide)
|
|
55
|
+
|
|
56
|
+ @Test
|
|
57
|
+ public void cheminValide() {
|
|
58
|
+ assertTrue(samenode.doRun().getPath().isValid());
|
|
59
|
+ assertTrue(bikinsatime.doRun().getPath().isValid());
|
|
60
|
+ assertTrue(bikinsalong.doRun().getPath().isValid());
|
|
61
|
+ assertFalse(invalinsa.doRun().getPath().isValid());
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ @Test
|
|
65
|
+ public void faisable() {
|
|
66
|
+ assertTrue(samenode.doRun().isFeasible());
|
|
67
|
+ assertTrue(bikinsatime.doRun().isFeasible());
|
|
68
|
+ assertTrue(bikinsalong.doRun().isFeasible());
|
|
69
|
+ assertFalse(invalinsa.doRun().isFeasible());
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ //cout calculé par Dijkstra identique à celui calculé par Path (comparaison pas avec ==)
|
|
73
|
+ //comment ça? Dijkstra ne renvoie pas le cout du path dans ShortestPathSolution, obligé d'utiliser getPath.getCout
|
|
74
|
+ //sans doute à voir avec comment demander un cout en temps ou en longueur
|
|
75
|
+ @Test
|
|
76
|
+ public void sameasPath() {
|
|
77
|
+ assertTrue(samenode.doRun().getPath().isValid());//à faire
|
|
78
|
+ assertTrue(bikinsatime.doRun().getPath().isValid());
|
|
79
|
+ assertTrue(bikinsalong.doRun().getPath().isValid());
|
|
80
|
+ assertTrue(invalinsa.doRun().getPath().isValid());
|
|
81
|
+ }
|
|
82
|
+
|
|
83
|
+ //résultat identique à Bellman-Ford (sur les petits scénarios)
|
|
84
|
+ @Test
|
|
85
|
+ public void sameasBF() {
|
|
86
|
+ assertTrue(samenode.doRun().getPath().equals(Bsamenode.doRun().getPath()));
|
|
87
|
+ assertTrue(bikinsatime.doRun().getPath().equals(Bbikinsatime.doRun().getPath()));
|
|
88
|
+ assertTrue(bikinsalong.doRun().getPath().equals(Bbikinsalong.doRun().getPath()));
|
|
89
|
+ assertTrue(invalinsa.doRun().getPath().equals(Binvalinsa.doRun().getPath()));
|
|
90
|
+ }
|
|
91
|
+
|
|
92
|
+ //tests applicables aussi pour des grands scénarios
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+}
|