11 |
|
public class ThreadLocalRandomTest extends JSR166TestCase { |
12 |
|
|
13 |
|
public static void main(String[] args) { |
14 |
< |
junit.textui.TestRunner.run (suite()); |
14 |
> |
junit.textui.TestRunner.run (suite()); |
15 |
|
} |
16 |
|
public static Test suite() { |
17 |
|
return new TestSuite(ThreadLocalRandomTest.class); |
19 |
|
|
20 |
|
/** |
21 |
|
* Testing coverage notes: |
22 |
< |
* |
22 |
> |
* |
23 |
|
* We don't test randomness properties, but only that repeated |
24 |
|
* calls, up to NCALLS tries, produce at least one different |
25 |
|
* result. For bounded versions, we sample various intervals |
26 |
|
* across multiples of primes. |
27 |
|
*/ |
28 |
|
|
29 |
< |
// |
29 |
> |
// |
30 |
|
static final int NCALLS = 10000; |
31 |
|
|
32 |
|
// max sampled int bound |
41 |
|
public void testSetSeed() { |
42 |
|
try { |
43 |
|
ThreadLocalRandom.current().setSeed(17); |
44 |
< |
} catch(UnsupportedOperationException success) { |
44 |
> |
shouldThrow(); |
45 |
> |
} catch (UnsupportedOperationException success) { |
46 |
|
} |
47 |
|
} |
48 |
|
|
120 |
|
public void testNextIntBoundedNeg() { |
121 |
|
try { |
122 |
|
int f = ThreadLocalRandom.current().nextInt(-17); |
123 |
< |
} catch(IllegalArgumentException success) { |
123 |
> |
shouldThrow(); |
124 |
> |
} catch (IllegalArgumentException success) { |
125 |
|
} |
126 |
|
} |
127 |
|
|
131 |
|
public void testNextIntBadBounds() { |
132 |
|
try { |
133 |
|
int f = ThreadLocalRandom.current().nextInt(17, 2); |
134 |
< |
} catch(IllegalArgumentException success) { |
134 |
> |
shouldThrow(); |
135 |
> |
} catch (IllegalArgumentException success) { |
136 |
|
} |
137 |
|
} |
138 |
|
|
148 |
|
assertTrue(0 <= f && f < bound); |
149 |
|
int i = 0; |
150 |
|
int j; |
151 |
< |
while (i < NCALLS && |
151 |
> |
while (i < NCALLS && |
152 |
|
(j = ThreadLocalRandom.current().nextInt(bound)) == f) { |
153 |
|
assertTrue(0 <= j && j < bound); |
154 |
|
++i; |
169 |
|
assertTrue(least <= f && f < bound); |
170 |
|
int i = 0; |
171 |
|
int j; |
172 |
< |
while (i < NCALLS && |
172 |
> |
while (i < NCALLS && |
173 |
|
(j = ThreadLocalRandom.current().nextInt(least, bound)) == f) { |
174 |
|
assertTrue(least <= j && j < bound); |
175 |
|
++i; |
185 |
|
public void testNextLongBoundedNeg() { |
186 |
|
try { |
187 |
|
long f = ThreadLocalRandom.current().nextLong(-17); |
188 |
< |
} catch(IllegalArgumentException success) { |
188 |
> |
shouldThrow(); |
189 |
> |
} catch (IllegalArgumentException success) { |
190 |
|
} |
191 |
|
} |
192 |
|
|
196 |
|
public void testNextLongBadBounds() { |
197 |
|
try { |
198 |
|
long f = ThreadLocalRandom.current().nextLong(17, 2); |
199 |
< |
} catch(IllegalArgumentException success) { |
199 |
> |
shouldThrow(); |
200 |
> |
} catch (IllegalArgumentException success) { |
201 |
|
} |
202 |
|
} |
203 |
|
|
211 |
|
assertTrue(0 <= f && f < bound); |
212 |
|
int i = 0; |
213 |
|
long j; |
214 |
< |
while (i < NCALLS && |
214 |
> |
while (i < NCALLS && |
215 |
|
(j = ThreadLocalRandom.current().nextLong(bound)) == f) { |
216 |
|
assertTrue(0 <= j && j < bound); |
217 |
|
++i; |
231 |
|
assertTrue(least <= f && f < bound); |
232 |
|
int i = 0; |
233 |
|
long j; |
234 |
< |
while (i < NCALLS && |
234 |
> |
while (i < NCALLS && |
235 |
|
(j = ThreadLocalRandom.current().nextLong(least, bound)) == f) { |
236 |
|
assertTrue(least <= j && j < bound); |
237 |
|
++i; |
253 |
|
assertTrue(least <= f && f < bound); |
254 |
|
int i = 0; |
255 |
|
double j; |
256 |
< |
while (i < NCALLS && |
256 |
> |
while (i < NCALLS && |
257 |
|
(j = ThreadLocalRandom.current().nextDouble(least, bound)) == f) { |
258 |
|
assertTrue(least <= j && j < bound); |
259 |
|
++i; |