Browse Source

bonne avancée junit

Favary Pierre 6 months ago
parent
commit
49c759bb50

+ 68
- 29
be-graphes-algos/src/test/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithmTest.java View File

@@ -7,15 +7,16 @@ import org.insa.graphs.*;//voir si on ne peut pas importer launch autrement
7 7
 import java.io.BufferedInputStream;
8 8
 import java.io.DataInputStream;
9 9
 import java.io.FileInputStream;
10
+import java.io.FileNotFoundException;
10 11
 import java.io.IOException;
11
-import java.util.ArrayList;
12 12
 import java.util.Arrays;
13 13
 
14 14
 import org.insa.graphs.algorithm.ArcInspector;
15 15
 import org.insa.graphs.algorithm.ArcInspectorFactory;
16
-import org.insa.graphs.algorithm.shortestpath.*;
17 16
 import org.insa.graphs.model.*;
18 17
 import org.insa.graphs.model.RoadInformation.RoadType;
18
+import org.insa.graphs.model.io.BinaryGraphReader;
19
+import org.insa.graphs.model.io.BinaryPathReader;
19 20
 import org.junit.BeforeClass;
20 21
 import org.junit.Test;
21 22
 
@@ -30,7 +31,7 @@ public class DijkstraAlgorithmTest{
30 31
 
31 32
     // List of arcs in the graph, a2b is the arc from node A (0) to B (1).
32 33
     @SuppressWarnings("unused")
33
-    private static Arc a2b, a2c, a2e, b2c, c2d_1, c2d_2, c2d_3, c2a, d2a, d2e, e2d;
34
+    private static Arc ab, ac, ad, bf, bd, cd, cg, df, de, de2, dh, ef, eg, eh, fg, gh;
34 35
 
35 36
     private static ShortestPathData dataal, datacl, dataat, datact, datapt, onenodata, emptydata, invalidata;
36 37
     
@@ -48,39 +49,47 @@ public class DijkstraAlgorithmTest{
48 49
     @BeforeClass
49 50
     public static void initAll() throws IOException {
50 51
 
51
-        // 10 and 20 meters per seconds
52 52
         RoadInformation speed10 = new RoadInformation(RoadType.MOTORWAY, null, true, 36, ""),
53
-                speed20 = new RoadInformation(RoadType.MOTORWAY, null, true, 72, "");
53
+                speed20 = new RoadInformation(RoadType.MOTORWAY, null, true, 72, ""),
54
+                pietonable = new RoadInformation(RoadType.PEDESTRIAN, null, true, 5, "");
55
+        //cyclable = new RoadInformation(RoadType.CYCLEWAY, null, true, 20, ""),
54 56
 
55 57
         // Create nodes
56
-        nodes = new Node[5];
58
+        nodes = new Node[8];
57 59
         for (int i = 0; i < nodes.length; ++i) {
58 60
             nodes[i] = new Node(i, null);
59 61
         }
60 62
 
61
-        // Add arcs...
62
-        a2b = Node.linkNodes(nodes[0], nodes[1], 10, speed10, null);
63
-        a2c = Node.linkNodes(nodes[0], nodes[2], 15, speed10, null);
64
-        a2e = Node.linkNodes(nodes[0], nodes[4], 15, speed20, null);
65
-        b2c = Node.linkNodes(nodes[1], nodes[2], 10, speed10, null);
66
-        c2d_1 = Node.linkNodes(nodes[2], nodes[3], 20, speed10, null);
67
-        c2d_2 = Node.linkNodes(nodes[2], nodes[3], 10, speed10, null);
68
-        c2d_3 = Node.linkNodes(nodes[2], nodes[3], 15, speed20, null);
69
-        d2a = Node.linkNodes(nodes[3], nodes[0], 15, speed10, null);
70
-        d2e = Node.linkNodes(nodes[3], nodes[4], 22.8f, speed20, null);
71
-        e2d = Node.linkNodes(nodes[4], nodes[0], 10, speed10, null);
72
-
63
+        // définition des arcs
64
+        ab = Node.linkNodes(nodes[0], nodes[1], 10, speed10, null);
65
+        ac = Node.linkNodes(nodes[0], nodes[2], 50, speed20, null);
66
+        ad = Node.linkNodes(nodes[0], nodes[3], 15, speed10, null);
67
+        bd = Node.linkNodes(nodes[1], nodes[3], 15, speed20, null);
68
+        bf = Node.linkNodes(nodes[1], nodes[5], 20, speed10, null);
69
+        cd = Node.linkNodes(nodes[2], nodes[3], 10, speed20, null);
70
+        cg = Node.linkNodes(nodes[2], nodes[6], 15, speed10, null);
71
+        de = Node.linkNodes(nodes[3], nodes[4], 15, speed20, null);
72
+        de2= Node.linkNodes(nodes[3], nodes[4], 25, pietonable, null);
73
+        df = Node.linkNodes(nodes[3], nodes[5], 8, pietonable, null);
74
+        dh = Node.linkNodes(nodes[3], nodes[7], 12, pietonable, null);
75
+        ef = Node.linkNodes(nodes[4], nodes[5], 10, speed10, null);
76
+        eg = Node.linkNodes(nodes[4], nodes[6], 10, speed20, null);
77
+        eh = Node.linkNodes(nodes[4], nodes[7], 5, pietonable, null);
78
+        fg = Node.linkNodes(nodes[5], nodes[6], 10, pietonable, null);
79
+        gh = Node.linkNodes(nodes[6], nodes[7], 12, pietonable, null);       
80
+        
81
+        
73 82
         graph = new Graph("ID", "", Arrays.asList(nodes), null);
74 83
 
75 84
         //initialisation des datas
76
-        dataal= new ShortestPathData(graph, null, null, alllen);
77
-        datacl= new ShortestPathData(graph, null, null, carlen);
78
-        dataat= new ShortestPathData(graph, null, null, alltime);
79
-        datact= new ShortestPathData(graph, null, null, cartime);
80
-        datapt= new ShortestPathData(graph, null, null, pietime);
85
+        dataal= new ShortestPathData(graph, nodes[0], nodes[4], alllen);//a->e
86
+        datacl= new ShortestPathData(graph, nodes[0], nodes[0], carlen);//b->g
87
+        dataat= new ShortestPathData(graph, nodes[0], nodes[0], alltime);//h->b
88
+        datact= new ShortestPathData(graph, nodes[0], nodes[0], cartime);//c->b
89
+        datapt= new ShortestPathData(graph, nodes[5], nodes[0], pietime);//f->e
81 90
         onenodata=new ShortestPathData(graph, nodes[2], nodes[2], pietime);
82 91
         emptydata=new ShortestPathData(graph, null, null, pietime);
83
-        invalidata=new ShortestPathData(graph, null, null, pietime);
92
+        invalidata=new ShortestPathData(graph, nodes[0], nodes[7], carlen);//h accessible uniquement aux piétons
84 93
         
85 94
         //initialisation des Dijkstras
86 95
         dijkal=new DijkstraAlgorithm(dataal);
@@ -113,22 +122,52 @@ public class DijkstraAlgorithmTest{
113 122
 	@Test
114 123
 	public void cheminValide() {
115 124
 		assertTrue(dijkal.doRun().getPath().isValid());
125
+		assertTrue(dijkcl.doRun().getPath().isValid());
126
+		assertTrue(dijkat.doRun().getPath().isValid());
127
+		assertTrue(dijkct.doRun().getPath().isValid());
128
+		assertTrue(dijkpt.doRun().getPath().isValid());
129
+		assertTrue(onenodijk.doRun().getPath().isValid());
130
+		assertTrue(emptydijk.doRun().getPath().isValid());//pas sûr
131
+		assertFalse(invalidijk.doRun().getPath().isValid());
116 132
 	}
117 133
 	
118 134
 	@Test
119 135
 	public void faisable() {
120
-		assertTrue(dijkal.doRun().isFeasible());	
136
+		assertTrue(dijkal.doRun().isFeasible());
137
+		assertTrue(dijkcl.doRun().isFeasible());
138
+		assertTrue(dijkat.doRun().isFeasible());
139
+		assertTrue(dijkct.doRun().isFeasible());
140
+		assertTrue(dijkpt.doRun().isFeasible());
141
+		assertTrue(onenodijk.doRun().isFeasible());
142
+		assertFalse(emptydijk.doRun().isFeasible());//pas sûr
143
+		assertFalse(invalidijk.doRun().isFeasible());	
121 144
 	}
122 145
 	
123 146
 	
124 147
 	//résultat identique à Bellman-Ford (sur les petits scénarios)
125 148
 	@Test
126
-	public void sameasBF() {
149
+	public void sameasBF() {//peut-être faut-il donner directement par exemple à dijkal dijkal.doRun() pour éviter de la surexécution
150
+		//voir alors comment gérer les erreurs (pas encore gérées ici)
127 151
 		assertTrue(Float.compare(dijkal.doRun().getPath().getLength(),bfaal.doRun().getPath().getLength())==0);
152
+		assertTrue(Float.compare(dijkcl.doRun().getPath().getLength(),bfacl.doRun().getPath().getLength())==0);
153
+		assertTrue(Double.compare(dijkat.doRun().getPath().getMinimumTravelTime(),bfaat.doRun().getPath().getMinimumTravelTime())==0);
154
+		assertTrue(Double.compare(dijkct.doRun().getPath().getMinimumTravelTime(),bfact.doRun().getPath().getMinimumTravelTime())==0);
155
+		assertTrue(Double.compare(dijkpt.doRun().getPath().getMinimumTravelTime(),bfapt.doRun().getPath().getMinimumTravelTime())==0);
128 156
 	}
129 157
 	
130
-	//tests applicables aussi pour des grands scénarios:
131
-	//...
158
+	//grands scénarios:	
159
+	public void testmap() throws FileNotFoundException, IOException{//A FAIRE
160
+		
161
+		String mapaddr = "/home/favary/Bureau/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/haute-garonne.mapgr";
162
+		String pathaddr ="/home/favary/Bureau/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31_insa_aeroport_length.path";
163
+				
164
+		Graph graphmap = (new BinaryGraphReader(new DataInputStream(new BufferedInputStream(new FileInputStream(mapaddr))))).read();
165
+		Path pathmap = (new BinaryPathReader(new DataInputStream(new BufferedInputStream(new FileInputStream(pathaddr))))).readPath(graphmap);
166
+		//quel inspector prendre? Le path est en longueur mais voitures seulement ou tout autorisé?
167
+		
168
+		DijkstraAlgorithm dijkmap = new DijkstraAlgorithm(new ShortestPathData(graphmap, pathmap.getOrigin(), pathmap.getDestination(), alllen));
132 169
 	
133
-	//graph = new BinaryGraphReader(new DataInputStream(new BufferedInputStream(new FileInputStream("a")))).read;
170
+		assertTrue(dijkmap.doRun().getPath().getLength()==pathmap.getLength());
171
+		//comparaison de la longueur
172
+	}
134 173
 }

Loading…
Cancel
Save