@@ -70,7 +70,7 @@ public class DataStructures {
70
70
71
71
private static final int NUMBER_OF_TESTS = 3 ;
72
72
private static final Random RANDOM = new Random ();
73
- private static final int ARRAY_SIZE = 100000 ;
73
+ private static final int ARRAY_SIZE = 1000 ;
74
74
private static final int RANDOM_SIZE = 1000 * ARRAY_SIZE ;
75
75
private static final Integer INVALID = RANDOM_SIZE + 10 ;
76
76
private static final DecimalFormat FORMAT = new DecimalFormat ("0.##" );
@@ -82,21 +82,13 @@ public class DataStructures {
82
82
private static int debug = 1 ; // Debug level. 0=None, 1=Time and Memory (if enabled), 2=Time, Memory, data structure debug
83
83
private static boolean debugTime = true ; // How much time to: add all, remove all, add all items in reverse order, remove all
84
84
private static boolean debugMemory = true ; // How much memory is used by the data structure
85
- private static boolean validateStructure = false ; // Is the data structure valid (passed invariants) and proper size
86
- private static boolean validateContents = false ; // Was the item added/removed really added/removed from the structure
87
- private static boolean validateIterator = false ; // Does the iterator(s) work
85
+ private static boolean validateStructure = true ; // Is the data structure valid (passed invariants) and proper size
86
+ private static boolean validateContents = true ; // Was the item added/removed really added/removed from the structure
87
+ private static boolean validateIterator = true ; // Does the iterator(s) work
88
88
89
89
private static final int TESTS = 38 ; // Max number of dynamic data structures to test
90
90
private static final String [] testNames = new String [TESTS ]; // Array to hold the test names
91
91
private static final long [][] testResults = new long [TESTS ][]; // Array to hold the test results
92
- private static final long [] minResults = new long [TESTS ]; // Array to hold the min results
93
- private static final long [] maxResults = new long [TESTS ]; // Array to hold the max results
94
- static {
95
- for (int i =0 ; i <TESTS ; i ++) {
96
- minResults [i ] = Long .MAX_VALUE ;
97
- maxResults [i ] = Long .MIN_VALUE ;
98
- }
99
- }
100
92
private static int testIndex = 0 ; // Index into the tests
101
93
private static int testNumber = 0 ; // Number of aggregate tests which have been run
102
94
@@ -118,10 +110,7 @@ public static void main(String[] args) {
118
110
else System .err .println ("Tests finished. Detected a failure." );
119
111
}
120
112
121
- private static boolean runTests () {
122
- testIndex = 0 ;
123
- testNumber ++;
124
-
113
+ private static void generateData () {
125
114
System .out .println ("Generating data." );
126
115
StringBuilder builder = new StringBuilder ();
127
116
builder .append ("Array=" );
@@ -153,6 +142,13 @@ private static boolean runTests() {
153
142
Arrays .sort (sorted );
154
143
155
144
System .out .println ("Generated data." );
145
+ }
146
+
147
+ private static boolean runTests () {
148
+ testIndex = 0 ;
149
+ testNumber ++;
150
+
151
+ generateData ();
156
152
157
153
boolean passed = true ;
158
154
@@ -567,8 +563,7 @@ private static boolean testGraph() {
567
563
if (debug > 1 ) System .out .println (getPathMapString (start , map1 ));
568
564
569
565
Graph .Vertex <Integer > end = v5 ;
570
- if (debug > 1 ) System .out .println ("Dijstra's shortest path of the undirected graph from " + start .getValue () + " to "
571
- + end .getValue ());
566
+ if (debug > 1 ) System .out .println ("Dijstra's shortest path of the undirected graph from " + start .getValue () + " to " + end .getValue ());
572
567
Graph .CostPathPair <Integer > pair1 = Dijkstra .getShortestPath (undirected , start , end );
573
568
if (debug > 1 ) {
574
569
if (pair1 != null ) System .out .println (pair1 .toString ());
@@ -1281,7 +1276,7 @@ private static boolean testQuadTree() {
1281
1276
}
1282
1277
afterInsert = System .nanoTime ();
1283
1278
insertTime = afterInsert - beforeInsert ;
1284
- System .out .println ("PointRegionQuadTree insertTime=" +insertTime );
1279
+ System .out .println ("PointRegionQuadTree insertTime=" +insertTime / 100000d + " ms" );
1285
1280
}
1286
1281
afterMemory = DataStructures .getMemoryUse ();
1287
1282
treeMemory = afterMemory - beforeMemory ;
@@ -1303,15 +1298,15 @@ private static boolean testQuadTree() {
1303
1298
}
1304
1299
afterQuery = System .nanoTime ();
1305
1300
queryTime = afterQuery - beforeQuery ;
1306
- System .out .println ("PointRegionQuadTree queryTime=" +queryTime );
1301
+ System .out .println ("PointRegionQuadTree queryTime=" +queryTime / 100000d + " ms" );
1307
1302
}
1308
1303
1309
1304
// Result set should not contain duplicates
1310
1305
beforeTreeQuery = System .nanoTime ();
1311
1306
java .util .List <QuadTree .XYPoint > result = tree .queryRange (0 , 0 , size , size );
1312
1307
afterTreeQuery = System .nanoTime ();
1313
1308
treeQuery = afterTreeQuery - beforeTreeQuery ;
1314
- System .out .println ("PointRegionQuadTree wholeTreeQuery=" +treeQuery );
1309
+ System .out .println ("PointRegionQuadTree wholeTreeQuery=" +treeQuery / 100000d + " ms" );
1315
1310
Collections .sort (result );
1316
1311
QuadTree .XYPoint prev = null ;
1317
1312
for (QuadTree .XYPoint p : result ) {
@@ -1329,7 +1324,7 @@ private static boolean testQuadTree() {
1329
1324
}
1330
1325
afterRemove = System .nanoTime ();
1331
1326
removeTime = afterRemove - beforeRemove ;
1332
- System .out .println ("PointRegionQuadTree removeTime=" +removeTime );
1327
+ System .out .println ("PointRegionQuadTree removeTime=" +removeTime / 100000d + " ms" );
1333
1328
}
1334
1329
}
1335
1330
@@ -1343,7 +1338,7 @@ private static boolean testQuadTree() {
1343
1338
}
1344
1339
afterInsert = System .nanoTime ();
1345
1340
insertTime = afterInsert - beforeInsert ;
1346
- System .out .println ("MxCifQuadTree insertTime=" +insertTime );
1341
+ System .out .println ("MxCifQuadTree insertTime=" +insertTime / 100000d + " ms" );
1347
1342
}
1348
1343
afterMemory = DataStructures .getMemoryUse ();
1349
1344
treeMemory = afterMemory - beforeMemory ;
@@ -1364,15 +1359,15 @@ private static boolean testQuadTree() {
1364
1359
}
1365
1360
afterQuery = System .nanoTime ();
1366
1361
queryTime = afterQuery - beforeQuery ;
1367
- System .out .println ("MxCifQuadTree queryTime=" +queryTime );
1362
+ System .out .println ("MxCifQuadTree queryTime=" +queryTime / 100000d + " ms" );
1368
1363
}
1369
1364
1370
1365
// Result set should not contain duplicates
1371
1366
beforeTreeQuery = System .nanoTime ();
1372
1367
java .util .List <QuadTree .AxisAlignedBoundingBox > result = tree .queryRange (0 , 0 , size , size );
1373
1368
afterTreeQuery = System .nanoTime ();
1374
1369
treeQuery = afterTreeQuery - beforeTreeQuery ;
1375
- System .out .println ("MxCifQuadTree wholeTreeQuery=" +treeQuery );
1370
+ System .out .println ("MxCifQuadTree wholeTreeQuery=" +treeQuery / 100000d + " ms" );
1376
1371
Collections .sort (result );
1377
1372
QuadTree .AxisAlignedBoundingBox prev = null ;
1378
1373
for (QuadTree .AxisAlignedBoundingBox p : result ) {
@@ -1392,7 +1387,7 @@ private static boolean testQuadTree() {
1392
1387
}
1393
1388
afterRemove = System .nanoTime ();
1394
1389
removeTime = afterRemove - beforeRemove ;
1395
- System .out .println ("MxCifQuadTree removeTime=" +removeTime );
1390
+ System .out .println ("MxCifQuadTree removeTime=" +removeTime / 100000d + " ms" );
1396
1391
}
1397
1392
}
1398
1393
@@ -1815,7 +1810,7 @@ private static <K,V> boolean testMap(IMap<K,V> map, Type keyType, String name) {
1815
1810
handleError (map );
1816
1811
return false ;
1817
1812
}
1818
- if (validateContents && (added = =null || !map .contains (k ))) {
1813
+ if (validateContents && (added ! =null || !map .contains (k ))) {
1819
1814
System .err .println (name +" YIKES!! " + item + " doesn't exists." );
1820
1815
handleError (map );
1821
1816
return false ;
@@ -1877,7 +1872,7 @@ private static <K,V> boolean testMap(IMap<K,V> map, Type keyType, String name) {
1877
1872
handleError (map );
1878
1873
return false ;
1879
1874
}
1880
- if (validateContents && (added = =null || !map .contains (k ))) {
1875
+ if (validateContents && (added ! =null || !map .contains (k ))) {
1881
1876
System .err .println (name +" YIKES!! " + item + " doesn't exists." );
1882
1877
handleError (map );
1883
1878
return false ;
@@ -1920,7 +1915,7 @@ private static <K,V> boolean testMap(IMap<K,V> map, Type keyType, String name) {
1920
1915
handleError (map );
1921
1916
return false ;
1922
1917
}
1923
- if (validateContents && (added = =null || !map .contains (k ))) {
1918
+ if (validateContents && (added ! =null || !map .contains (k ))) {
1924
1919
System .err .println (name +" YIKES!! " + item + " doesn't exists." );
1925
1920
handleError (map );
1926
1921
return false ;
@@ -4085,6 +4080,7 @@ private static final long getMemoryUse() {
4085
4080
private static final void putOutTheGarbage () {
4086
4081
collectGarbage ();
4087
4082
collectGarbage ();
4083
+ collectGarbage ();
4088
4084
}
4089
4085
4090
4086
private static final long fSLEEP_INTERVAL = 100 ;
0 commit comments