Browse Source

plus de data pour junit

Favary Pierre 2 years ago
parent
commit
442a06e0e8

+ 3
- 3
be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspectorFactory.java View File

@@ -20,7 +20,7 @@ public class ArcInspectorFactory {
20 20
 
21 21
         // Common filters:
22 22
 
23
-        // No filter (all arcs allowed):
23
+        // No filter (all arcs allowed), shortest:
24 24
         filters.add(new ArcInspector() {
25 25
             @Override
26 26
             public boolean isAllowed(Arc arc) {
@@ -78,7 +78,7 @@ public class ArcInspectorFactory {
78 78
             }
79 79
         });
80 80
 
81
-        // Only road allowed for cars and time:
81
+        //   All allowed and time?
82 82
 
83 83
         filters.add(new ArcInspector() {
84 84
             @Override
@@ -107,7 +107,7 @@ public class ArcInspectorFactory {
107 107
             }
108 108
         });
109 109
 
110
-        filters.add(new ArcInspector() {
110
+        filters.add(new ArcInspector() {// *this one* seems to be fastest path with car
111 111
             @Override
112 112
             public boolean isAllowed(Arc arc) {
113 113
                 return arc.getRoadInformation().getAccessRestrictions()

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

@@ -32,10 +32,19 @@ public class DijkstraAlgorithmTest{
32 32
     @SuppressWarnings("unused")
33 33
     private static Arc a2b, a2c, a2e, b2c, c2d_1, c2d_2, c2d_3, c2a, d2a, d2e, e2d;
34 34
 
35
-    // Some paths...
36
-    private static Path emptyPath, singleNodePath, shortPath, longPath, loopPath, longLoopPath,
37
-            invalidPath;
38
-
35
+    private static ShortestPathData dataal, datacl, dataat, datact, datapt, onenodata, emptydata, invalidata;
36
+    
37
+	// permet de savoir quels arcs autoriser(cf l.187 excel ggdoc)
38
+    private static ArcInspector alllen = ArcInspectorFactory.getAllFilters().get(0);
39
+    private static ArcInspector carlen = ArcInspectorFactory.getAllFilters().get(1);
40
+    private static ArcInspector alltime = ArcInspectorFactory.getAllFilters().get(2);
41
+    private static ArcInspector cartime = ArcInspectorFactory.getAllFilters().get(3);
42
+    private static ArcInspector pietime = ArcInspectorFactory.getAllFilters().get(4);
43
+    
44
+	private static DijkstraAlgorithm dijkal, dijkcl, dijkat, dijkct, dijkpt, onenodijk, emptydijk, invalidijk;
45
+	private static BellmanFordAlgorithm bfaal, bfacl, bfaat, bfact, bfapt;
46
+    
47
+    
39 48
     @BeforeClass
40 49
     public static void initAll() throws IOException {
41 50
 
@@ -63,53 +72,39 @@ public class DijkstraAlgorithmTest{
63 72
 
64 73
         graph = new Graph("ID", "", Arrays.asList(nodes), null);
65 74
 
66
-        emptyPath = new Path(graph, new ArrayList<Arc>());
67
-        singleNodePath = new Path(graph, nodes[1]);
68
-        shortPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1 }));
69
-        longPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1, d2e }));
70
-        loopPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1, d2a }));
71
-        longLoopPath = new Path(graph,
72
-                Arrays.asList(new Arc[] { a2b, b2c, c2d_1, d2a, a2c, c2d_3, d2a, a2b, b2c }));
73
-        invalidPath = new Path(graph, Arrays.asList(new Arc[] { a2b, c2d_1, d2e }));
75
+        //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);
81
+        onenodata=new ShortestPathData(graph, nodes[2], nodes[2], pietime);
82
+        emptydata=new ShortestPathData(graph, null, null, pietime);
83
+        invalidata=new ShortestPathData(graph, null, null, pietime);
84
+        
85
+        //initialisation des Dijkstras
86
+        dijkal=new DijkstraAlgorithm(dataal);
87
+        dijkcl=new DijkstraAlgorithm(datacl);
88
+        dijkat=new DijkstraAlgorithm(dataat);
89
+        dijkct=new DijkstraAlgorithm(datact);
90
+        dijkpt=new DijkstraAlgorithm(datapt);
91
+        onenodijk=new DijkstraAlgorithm(onenodata);
92
+        emptydijk=new DijkstraAlgorithm(emptydata);
93
+        invalidijk=new DijkstraAlgorithm(invalidata);
94
+        
95
+        //initialisation des Bellman-Ford pour comparaison
96
+		bfaal=new BellmanFordAlgorithm(dataal);
97
+		bfacl=new BellmanFordAlgorithm(datacl);
98
+		bfaat=new BellmanFordAlgorithm(dataat);
99
+		bfact=new BellmanFordAlgorithm(datact);
100
+		bfapt=new BellmanFordAlgorithm(datapt);
101
+
102
+    }    
74 103
 
75
-    }
76
-    //---fin de la copie de PathTest.java
77
-    
78
-	//regarder LAUNCH.JAVA pour ouvrir une map
79
-    
80
-	private static DijkstraAlgorithm samenode, bikinsatime, bikinsalong, invalinsa;
81
-	private static BellmanFordAlgorithm Bsamenode, Bbikinsatime, Bbikinsalong, Binvalinsa;
82
-	private static ShortestPathData samenodespd, bikinsatimespd, bikinsalongspd, invalinsaspd;
83
-
84
-	// (cf l.187 excel ggdoc) permet de savoir quels arcs autoriser
85
-    private ArcInspector inspecteuruno=ArcInspectorFactory.getAllFilters().get(0);// No filter (all arcs allowed)
86
-    private ArcInspector inspecteurtres=ArcInspectorFactory.getAllFilters().get(2);// Only road allowed for cars and time
87
-	
88
-    
89 104
     //créer plus et avec des maps différentes
90 105
     //faire des test spécifiques pour longs trajets
91
-    
92
-	/*@BeforeClass
93
-    public static void initAllbis() {
94
-//en fait pas sûr que ça marche comme ça, voir avec Launch
95
-		samenodespd=new ShortestPathData(graph, null, null, null);
96
-		bikinsatimespd=new ShortestPathData(graph, null, null, null);
97
-		bikinsalongspd=new ShortestPathData(graph, null, null, null);
98
-		invalinsaspd=new ShortestPathData(graph, null, null, null);
99
-		
100
-		samenode=new DijkstraAlgorithm(samenodespd);
101
-		bikinsatime=new DijkstraAlgorithm(bikinsatimespd);
102
-		bikinsalong=new DijkstraAlgorithm(bikinsalongspd);
103
-		invalinsa=new DijkstraAlgorithm(invalinsaspd);
104
-		//est-ce que c'est vraiment la bonne manière de faire? car alors très long de rajouter des path à tester
105
-		Bsamenode=new BellmanFordAlgorithm(samenodespd);
106
-		Bbikinsatime= new BellmanFordAlgorithm(bikinsatimespd);
107
-		Bbikinsalong=new BellmanFordAlgorithm(bikinsalongspd);
108
-		Binvalinsa=new BellmanFordAlgorithm(invalinsaspd);
109
-	}*/
106
+   
110 107
 	
111
-    //comment trouver les noeuds dans une map? Ne comparer que les grands chemins (qui font ouvrir la map) avec BF
112
-    
113 108
 	/*(Test faits directement via la console et DijkstraAlgorithm.java, actuellement commentés:
114 109
 	-coûts croissants
115 110
 	-nbr successeurs cohérents
@@ -117,44 +112,23 @@ public class DijkstraAlgorithmTest{
117 112
 	
118 113
 	@Test
119 114
 	public void cheminValide() {
120
-		ShortestPathData data1=new ShortestPathData(null, null, null, inspecteuruno);
121
-		ShortestPathData data3=new ShortestPathData(null, null, null, inspecteurtres);
122
-		ShortestPathAlgorithm Dijkstra1=new DijkstraAlgorithm(data1);
123
-		ShortestPathAlgorithm Dijkstra3=new DijkstraAlgorithm(data3);
124
-		assertTrue(Dijkstra1.doRun().getPath().isValid());
125
-		assertTrue(Dijkstra3.doRun().getPath().isValid());
126
-		assertTrue(samenode.doRun().getPath().isValid());
127
-		assertTrue(bikinsatime.doRun().getPath().isValid());
128
-		assertTrue(bikinsalong.doRun().getPath().isValid());
129
-		assertFalse(invalinsa.doRun().getPath().isValid());
115
+		assertTrue(dijkal.doRun().getPath().isValid());
130 116
 	}
131 117
 	
132 118
 	@Test
133 119
 	public void faisable() {
134
-		ShortestPathData data1=new ShortestPathData(null, null, null, inspecteuruno);
135
-		ShortestPathData data3=new ShortestPathData(null, null, null, inspecteurtres);
136
-		ShortestPathAlgorithm Dijkstra1=new DijkstraAlgorithm(data1);
137
-		ShortestPathAlgorithm Dijkstra3=new DijkstraAlgorithm(data3);
138
-		assertTrue(Dijkstra1.doRun().isFeasible());
139
-		assertTrue(Dijkstra3.doRun().isFeasible());
140
-		assertTrue(samenode.doRun().isFeasible());
141
-		assertTrue(bikinsatime.doRun().isFeasible());
142
-		assertTrue(bikinsalong.doRun().isFeasible());
143
-		assertFalse(invalinsa.doRun().isFeasible());		
120
+		assertTrue(dijkal.doRun().isFeasible());	
144 121
 	}
145 122
 	
146 123
 	
147 124
 	//résultat identique à Bellman-Ford (sur les petits scénarios)
148 125
 	@Test
149 126
 	public void sameasBF() {
150
-		assertTrue(samenode.doRun().getPath().equals(Bsamenode.doRun().getPath()));
151
-		assertTrue(bikinsatime.doRun().getPath().equals(Bbikinsatime.doRun().getPath()));
152
-		assertTrue(bikinsalong.doRun().getPath().equals(Bbikinsalong.doRun().getPath()));
153
-		assertTrue(invalinsa.doRun().getPath().equals(Binvalinsa.doRun().getPath()));
127
+		assertTrue(Float.compare(dijkal.doRun().getPath().getLength(),bfaal.doRun().getPath().getLength())==0);
154 128
 	}
155 129
 	
156 130
 	//tests applicables aussi pour des grands scénarios:
157 131
 	//...
158 132
 	
159
-	
133
+	//graph = new BinaryGraphReader(new DataInputStream(new BufferedInputStream(new FileInputStream("a")))).read;
160 134
 }

Loading…
Cancel
Save