1 |
|
/* |
2 |
< |
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. |
2 |
> |
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved. |
3 |
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
|
* |
5 |
|
* This code is free software; you can redistribute it and/or modify it |
34 |
|
|
35 |
|
@SuppressWarnings("unchecked") |
36 |
|
public class BiggernYours { |
37 |
< |
static final Random rnd = new Random(); |
37 |
> |
static final Random rnd = new Random(18675309); |
38 |
|
|
39 |
|
static void compareCollections(Collection c1, Collection c2) { |
40 |
< |
arrayEqual(c1.toArray(), |
41 |
< |
c2.toArray()); |
42 |
< |
arrayEqual(c1.toArray(new Object[0]), |
43 |
< |
c2.toArray(new Object[0])); |
44 |
< |
arrayEqual(c1.toArray(new Object[5]), |
45 |
< |
c2.toArray(new Object[5])); |
40 |
> |
Object[] c1Array = c1.toArray(); |
41 |
> |
Object[] c2Array = c2.toArray(); |
42 |
> |
|
43 |
> |
check(c1Array.length == c2Array.length); |
44 |
> |
for (Object aC1 : c1Array) { |
45 |
> |
boolean found = false; |
46 |
> |
for (Object aC2 : c2Array) { |
47 |
> |
if (Objects.equals(aC1, aC2)) { |
48 |
> |
found = true; |
49 |
> |
break; |
50 |
> |
} |
51 |
> |
} |
52 |
> |
|
53 |
> |
if (!found) |
54 |
> |
fail(aC1 + " not found in " + Arrays.toString(c2Array)); |
55 |
> |
} |
56 |
|
} |
57 |
|
|
58 |
|
static void compareMaps(Map m1, Map m2) { |
236 |
|
try {realMain(args);} catch (Throwable t) {unexpected(t);} |
237 |
|
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); |
238 |
|
if (failed > 0) throw new AssertionError("Some tests failed");} |
229 |
– |
private abstract static class Fun {abstract void f() throws Throwable;} |
230 |
– |
static void THROWS(Class<? extends Throwable> k, Fun... fs) { |
231 |
– |
for (Fun f : fs) |
232 |
– |
try { f.f(); fail("Expected " + k.getName() + " not thrown"); } |
233 |
– |
catch (Throwable t) { |
234 |
– |
if (k.isAssignableFrom(t.getClass())) pass(); |
235 |
– |
else unexpected(t);}} |
239 |
|
private abstract static class CheckedThread extends Thread { |
240 |
|
abstract void realRun() throws Throwable; |
241 |
|
public void run() { |