45
45
public abstract class AbstractLocation2IDIndexTester
46
46
{
47
47
String location = "./target/tmp/" ;
48
+ LocationIndex idx ;
48
49
49
50
public abstract LocationIndex createIndex ( Graph g , int resolution );
50
51
@@ -56,6 +57,8 @@ public boolean hasEdgeSupport()
56
57
@ Before
57
58
public void setUp ()
58
59
{
60
+ if (idx != null )
61
+ idx .close ();
59
62
Helper .removeDir (new File (location ));
60
63
}
61
64
@@ -71,7 +74,7 @@ public void testSimpleGraph()
71
74
Graph g = createGraph (new EncodingManager ("CAR" ));
72
75
initSimpleGraph (g );
73
76
74
- LocationIndex idx = createIndex (g , 8 );
77
+ idx = createIndex (g , 8 );
75
78
assertEquals (4 , idx .findID (5 , 2 ));
76
79
assertEquals (3 , idx .findID (1.5 , 2 ));
77
80
assertEquals (0 , idx .findID (-1 , -1 ));
@@ -123,7 +126,7 @@ public void testSimpleGraph2()
123
126
Graph g = createGraph (new EncodingManager ("CAR" ));
124
127
initSimpleGraph (g );
125
128
126
- LocationIndex idx = createIndex (g , 28 );
129
+ idx = createIndex (g , 28 );
127
130
assertEquals (4 , idx .findID (5 , 2 ));
128
131
assertEquals (3 , idx .findID (1.5 , 2 ));
129
132
assertEquals (0 , idx .findID (-1 , -1 ));
@@ -147,16 +150,15 @@ public void testGrid()
147
150
Graph g = createSampleGraph (new EncodingManager ("CAR" ));
148
151
int locs = g .getNodes ();
149
152
150
- LocationIndex index = createIndex (g , 120 );
153
+ idx = createIndex (g , 120 );
151
154
// if we would use less array entries then some points gets the same key so avoid that for this test
152
155
// e.g. for 16 we get "expected 6 but was 9" i.e 6 was overwritten by node j9 which is a bit closer to the grid center
153
156
// go through every point of the graph if all points are reachable
154
157
for (int i = 0 ; i < locs ; i ++)
155
158
{
156
159
double lat = g .getLatitude (i );
157
160
double lon = g .getLongitude (i );
158
- assertEquals ("nodeId:" + i + " " + (float ) lat + "," + (float ) lon ,
159
- i , index .findID (lat , lon ));
161
+ assertEquals ("nodeId:" + i + " " + (float ) lat + "," + (float ) lon , i , idx .findID (lat , lon ));
160
162
}
161
163
162
164
// hit random lat,lon and compare result to full index
@@ -176,7 +178,7 @@ public void testGrid()
176
178
double fullLat = g .getLatitude (fullId );
177
179
double fullLon = g .getLongitude (fullId );
178
180
float fullDist = (float ) dist .calcDist (lat , lon , fullLat , fullLon );
179
- int newId = index .findID (lat , lon );
181
+ int newId = idx .findID (lat , lon );
180
182
double newLat = g .getLatitude (newId );
181
183
double newLon = g .getLongitude (newId );
182
184
float newDist = (float ) dist .calcDist (lat , lon , newLat , newLon );
@@ -191,6 +193,7 @@ public void testGrid()
191
193
+ " found:" + newLat + "," + newLon + " foundDist:" + newDist ,
192
194
Math .abs (fullDist - newDist ) < 50000 );
193
195
}
196
+ fullIndex .close ();
194
197
}
195
198
196
199
// our simple index has only one node per tile => problems if multiple subnetworks
@@ -203,7 +206,7 @@ boolean testGridIgnore( int i )
203
206
public void testSinglePoints120 ()
204
207
{
205
208
Graph g = createSampleGraph (new EncodingManager ("CAR" ));
206
- LocationIndex idx = createIndex (g , 120 );
209
+ idx = createIndex (g , 120 );
207
210
208
211
assertEquals (1 , idx .findID (1.637 , 2.23 ));
209
212
assertEquals (10 , idx .findID (3.649 , 1.375 ));
@@ -218,7 +221,7 @@ public void testSinglePoints120()
218
221
public void testSinglePoints32 ()
219
222
{
220
223
Graph g = createSampleGraph (new EncodingManager ("CAR" ));
221
- LocationIndex idx = createIndex (g , 32 );
224
+ idx = createIndex (g , 32 );
222
225
223
226
// 10 or 6
224
227
assertEquals (10 , idx .findID (3.649 , 1.375 ));
@@ -244,7 +247,8 @@ public void testNoErrorOnEdgeCase_lastIndex()
244
247
{
245
248
g .setNode (i , (float ) rand .nextDouble () * 10 + 10 , (float ) rand .nextDouble () * 10 + 10 );
246
249
}
247
- createIndex (g , 200 );
250
+ LocationIndex idx = createIndex (g , 200 );
251
+ idx .close ();
248
252
Helper .removeDir (new File (location ));
249
253
}
250
254
@@ -343,7 +347,7 @@ public void testDifferentVehicles()
343
347
final EncodingManager encodingManager = new EncodingManager ("CAR,FOOT" );
344
348
Graph g = createGraph (encodingManager );
345
349
initSimpleGraph (g );
346
- LocationIndex idx = createIndex (g , 32 );
350
+ idx = createIndex (g , 32 );
347
351
assertEquals (1 , idx .findID (1 , -1 ));
348
352
349
353
// now make all edges from node 1 accessible for CAR only
@@ -353,7 +357,8 @@ public void testDifferentVehicles()
353
357
{
354
358
iter .setFlags (carEncoder .setProperties (50 , true , true ));
355
359
}
356
-
360
+ idx .close ();
361
+
357
362
idx = createIndex (g , 32 );
358
363
FootFlagEncoder footEncoder = (FootFlagEncoder ) encodingManager .getEncoder ("FOOT" );
359
364
assertEquals (2 , idx .findClosest (1 , -1 , new DefaultEdgeFilter (footEncoder )).getClosestNode ());
0 commit comments