24
24
import de .jetsli .graph .storage .Graph ;
25
25
import de .jetsli .graph .storage .Location2IDIndex ;
26
26
import de .jetsli .graph .storage .Location2IDQuadtree ;
27
- import de .jetsli .graph .util .CmdArgs ;
28
- import de .jetsli .graph .util .Helper ;
29
27
import de .jetsli .graph .util .StopWatch ;
30
- import java .io .File ;
31
28
import java .util .ArrayList ;
32
29
import java .util .List ;
33
30
import java .util .Random ;
@@ -46,34 +43,7 @@ public RoutingAlgorithmIntegrationTests(Graph graph) {
46
43
}
47
44
48
45
public void start () {
49
- Collector testCollector = new Collector ();
50
-
51
- //
52
- List <OneRun > list = new ArrayList <OneRun >();
53
- list .add (new OneRun (43.727687 , 7.418737 , 43.730729 , 7.421288 , 1.532 , 88 ));
54
- list .add (new OneRun (43.727687 , 7.418737 , 43.74958 , 7.436566 , 3.448 , 136 ));
55
- runAlgo (testCollector , "files/monaco.osm.gz" , "target/graph-monaco" , list );
56
-
57
- //
58
- list = new ArrayList <OneRun >();
59
- list .add (new OneRun (42.56819 , 1.603231 , 42.571034 , 1.520662 , 16.378 , 636 ));
60
- list .add (new OneRun (42.529176 , 1.571302 , 42.571034 , 1.520662 , 12.429 , 397 ));
61
- runAlgo (testCollector , "files/andorra.osm.gz" , "target/graph-andorra" , list );
62
-
63
- //
64
- testUnterfranken (testCollector );
65
-
66
- if (testCollector .list .size () > 0 ) {
67
- System .out .println ("\n -------------------------------\n " );
68
- System .out .println ("FOUND " + testCollector .list .size () + " ERRORS" );
69
- for (String s : testCollector .list ) {
70
- System .out .println (s );
71
- }
72
- } else
73
- System .out .println ("SUCCESS!" );
74
- }
75
-
76
- private void testUnterfranken (Collector testCollector ) {
46
+ TestAlgoCollector testCollector = new TestAlgoCollector ();
77
47
RoutingAlgorithm [] algos = createAlgos (unterfrankenGraph );
78
48
for (RoutingAlgorithm algo : algos ) {
79
49
int failed = testCollector .list .size ();
@@ -95,26 +65,32 @@ private void testUnterfranken(Collector testCollector) {
95
65
System .out .println ("unterfranken " + algo .getClass ().getSimpleName ()
96
66
+ ": " + (testCollector .list .size () - failed ) + " failed" );
97
67
}
68
+
69
+ if (testCollector .list .size () > 0 ) {
70
+ System .out .println ("\n -------------------------------\n " );
71
+ System .out .println (testCollector );
72
+ } else
73
+ System .out .println ("SUCCESS!" );
98
74
}
99
75
100
- RoutingAlgorithm [] createAlgos (Graph g ) {
76
+ public static RoutingAlgorithm [] createAlgos (Graph g ) {
101
77
return new RoutingAlgorithm []{new AStar (g ), new DijkstraBidirectionRef (g ),
102
78
new DijkstraBidirection (g ), new DijkstraSimple (g )};
103
79
}
104
80
105
- public static class Collector {
81
+ public static class TestAlgoCollector {
106
82
107
- List <String > list = new ArrayList <String >();
83
+ public List <String > list = new ArrayList <String >();
108
84
109
- public Collector assertNull (RoutingAlgorithm algo , int from , int to ) {
85
+ public TestAlgoCollector assertNull (RoutingAlgorithm algo , int from , int to ) {
110
86
Path p = algo .clear ().calcShortestPath (from , to );
111
87
if (p != null )
112
88
list .add (algo .getClass ().getSimpleName () + " returns value where null is expected. "
113
89
+ "from:" + from + ", to:" + to );
114
90
return this ;
115
91
}
116
92
117
- public Collector assertDistance (RoutingAlgorithm algo , int from , int to , double distance , int locations ) {
93
+ public TestAlgoCollector assertDistance (RoutingAlgorithm algo , int from , int to , double distance , int locations ) {
118
94
Path p = algo .clear ().calcShortestPath (from , to );
119
95
if (p == null ) {
120
96
list .add (algo .getClass ().getSimpleName () + " returns no path for "
@@ -135,49 +111,15 @@ public Collector assertDistance(RoutingAlgorithm algo, int from, int to, double
135
111
+ "from:" + from + ", to:" + to );
136
112
return this ;
137
113
}
138
- }
139
-
140
- class OneRun {
141
-
142
- double fromLat , fromLon ;
143
- double toLat , toLon ;
144
- double dist ;
145
- int locs ;
146
-
147
- public OneRun (double fromLat , double fromLon , double toLat , double toLon , double dist , int locs ) {
148
- this .fromLat = fromLat ;
149
- this .fromLon = fromLon ;
150
- this .toLat = toLat ;
151
- this .toLon = toLon ;
152
- this .dist = dist ;
153
- this .locs = locs ;
154
- }
155
- }
156
114
157
- void runAlgo (Collector testCollector , String osmFile , String graphFile , List <OneRun > forEveryAlgo ) {
158
- try {
159
- // make sure we are using the latest file format
160
- Helper .deleteDir (new File (graphFile ));
161
- Graph g = OSMReader .osm2Graph (new CmdArgs ().put ("osm" , osmFile ).put ("graph" , graphFile ));
162
- System .out .println (osmFile + " - all locations " + g .getNodes ());
163
- Location2IDIndex idx = new Location2IDQuadtree (g ).prepareIndex (2000 );
164
- RoutingAlgorithm [] algos = createAlgos (g );
165
- for (RoutingAlgorithm algo : algos ) {
166
- int failed = testCollector .list .size ();
167
-
168
- for (OneRun or : forEveryAlgo ) {
169
- int from = idx .findID (or .fromLat , or .fromLon );
170
- int to = idx .findID (or .toLat , or .toLon );
171
- testCollector .assertDistance (algo , from , to , or .dist , or .locs );
172
- }
173
-
174
- System .out .println (osmFile + " " + algo .getClass ().getSimpleName ()
175
- + ": " + (testCollector .list .size () - failed ) + " failed" );
115
+ @ Override
116
+ public String toString () {
117
+ String str = "" ;
118
+ str += "FOUND " + list .size () + " ERRORS\n " ;
119
+ for (String s : list ) {
120
+ str += s + "\n " ;
176
121
}
177
- } catch (Exception ex ) {
178
- throw new RuntimeException ("cannot handle osm file " + osmFile , ex );
179
- } finally {
180
- Helper .deleteDir (new File (graphFile ));
122
+ return str ;
181
123
}
182
124
}
183
125
private Logger logger = LoggerFactory .getLogger (getClass ());
0 commit comments