7 |
|
* @test |
8 |
|
* @synopsis Times and checks basic set operations |
9 |
|
*/ |
10 |
– |
import java.util.*; |
10 |
|
import java.io.*; |
11 |
+ |
import java.util.*; |
12 |
|
|
13 |
|
public class NavigableSetCheck { |
14 |
|
|
25 |
|
} |
26 |
|
|
27 |
|
public static void main(String[] args) throws Exception { |
28 |
< |
Class setClass = null; |
28 |
> |
Class<?> setClass = null; |
29 |
|
int numTests = 50; |
30 |
|
int size = 50000; |
31 |
|
|
37 |
|
} |
38 |
|
} |
39 |
|
|
40 |
– |
|
40 |
|
if (args.length > 1) |
41 |
|
numTests = Integer.parseInt(args[1]); |
42 |
|
|
45 |
|
|
46 |
|
System.out.println("Testing " + setClass.getName() + " trials: " + numTests + " size: " + size); |
47 |
|
|
49 |
– |
|
48 |
|
absentSize = 8; |
49 |
|
while (absentSize < size) absentSize <<= 1; |
50 |
|
absentMask = absentSize - 1; |
57 |
|
for (int i = 0; i < size; ++i) |
58 |
|
key[i] = new Integer(i * 2 + 1); |
59 |
|
|
62 |
– |
|
60 |
|
for (int rep = 0; rep < numTests; ++rep) { |
61 |
|
runTest(newSet(setClass), key); |
62 |
|
} |
63 |
|
|
64 |
|
TestTimer.printStats(); |
68 |
– |
|
65 |
|
} |
66 |
|
|
67 |
< |
static NavigableSet newSet(Class cl) { |
67 |
> |
static NavigableSet newSet(Class<?> cl) { |
68 |
|
try { |
69 |
< |
NavigableSet m = (NavigableSet) cl.newInstance(); |
74 |
< |
return m; |
69 |
> |
return (NavigableSet) cl.getConstructor().newInstance(); |
70 |
|
} catch (Exception e) { |
71 |
|
throw new RuntimeException("Can't instantiate " + cl + ": " + e); |
72 |
|
} |
73 |
|
} |
74 |
|
|
80 |
– |
|
75 |
|
static void runTest(NavigableSet s, Integer[] key) { |
76 |
|
shuffle(key); |
77 |
|
int size = key.length; |
165 |
|
reallyAssert(sum == expect); |
166 |
|
} |
167 |
|
|
174 |
– |
|
168 |
|
static void higherTest(NavigableSet s) { |
169 |
|
int sum = 0; |
170 |
|
int iters = s.size(); |
219 |
|
reallyAssert(sum == iters-1); |
220 |
|
} |
221 |
|
|
229 |
– |
|
222 |
|
static void ktest(NavigableSet s, int size, Integer[] key) { |
223 |
|
timer.start("Contains ", size); |
224 |
|
int sum = 0; |
229 |
|
reallyAssert(sum == size); |
230 |
|
} |
231 |
|
|
240 |
– |
|
232 |
|
static void ittest1(NavigableSet s, int size) { |
233 |
|
int sum = 0; |
234 |
|
timer.start("Iter Key ", size); |
259 |
|
rittest1(s, size); |
260 |
|
} |
261 |
|
|
271 |
– |
|
262 |
|
static void rtest(NavigableSet s, int size) { |
263 |
|
timer.start("Remove (iterator) ", size); |
264 |
|
for (Iterator it = s.iterator(); it.hasNext(); ) { |
268 |
|
timer.finish(); |
269 |
|
} |
270 |
|
|
281 |
– |
|
282 |
– |
|
271 |
|
static void dtest(NavigableSet s, int size, Integer[] key) { |
272 |
|
timer.start("Add (addAll) ", size * 2); |
273 |
< |
NavigableSet s2 = null; |
273 |
> |
final NavigableSet s2; |
274 |
|
try { |
275 |
< |
s2 = (NavigableSet) (s.getClass().newInstance()); |
275 |
> |
s2 = (NavigableSet) s.getClass().getConstructor().newInstance(); |
276 |
|
s2.addAll(s); |
277 |
|
} |
278 |
|
catch (Exception e) { e.printStackTrace(); return; } |
317 |
|
reallyAssert(s2.isEmpty() && s.isEmpty()); |
318 |
|
} |
319 |
|
|
332 |
– |
|
333 |
– |
|
320 |
|
static void test(NavigableSet s, Integer[] key) { |
321 |
|
int size = key.length; |
322 |
|
|
377 |
|
startTime = System.currentTimeMillis(); |
378 |
|
} |
379 |
|
|
394 |
– |
|
380 |
|
String classify() { |
381 |
|
if (name.startsWith("Contains")) |
382 |
|
return "Contains "; |