1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
import junit.framework.*; |
7 |
|
import java.util.concurrent.*; |
8 |
|
import java.util.*; |
9 |
|
|
10 |
– |
|
10 |
|
public class ThreadLocalRandomTest extends JSR166TestCase { |
11 |
|
|
12 |
|
public static void main(String[] args) { |
13 |
< |
junit.textui.TestRunner.run (suite()); |
13 |
> |
junit.textui.TestRunner.run(suite()); |
14 |
|
} |
15 |
|
public static Test suite() { |
16 |
|
return new TestSuite(ThreadLocalRandomTest.class); |
66 |
|
assertTrue(i < NCALLS); |
67 |
|
} |
68 |
|
|
70 |
– |
|
69 |
|
/** |
70 |
|
* Repeated calls to nextBoolean produce at least one different result |
71 |
|
*/ |
110 |
|
assertTrue(i < NCALLS); |
111 |
|
} |
112 |
|
|
115 |
– |
|
113 |
|
/** |
114 |
|
* nextInt(negative) throws IllegalArgumentException; |
115 |
|
*/ |
116 |
|
public void testNextIntBoundedNeg() { |
117 |
|
try { |
118 |
< |
int f = ThreadLocalRandom.current().nextInt(-17); |
118 |
> |
int f = ThreadLocalRandom.current().nextInt(-17); |
119 |
|
shouldThrow(); |
120 |
|
} catch (IllegalArgumentException success) {} |
121 |
|
} |
125 |
|
*/ |
126 |
|
public void testNextIntBadBounds() { |
127 |
|
try { |
128 |
< |
int f = ThreadLocalRandom.current().nextInt(17, 2); |
128 |
> |
int f = ThreadLocalRandom.current().nextInt(17, 2); |
129 |
|
shouldThrow(); |
130 |
|
} catch (IllegalArgumentException success) {} |
131 |
|
} |
132 |
|
|
136 |
– |
|
133 |
|
/** |
134 |
|
* nextInt(bound) returns 0 <= value < bound; |
135 |
|
* repeated calls produce at least one different result |
150 |
|
} |
151 |
|
} |
152 |
|
|
157 |
– |
|
153 |
|
/** |
154 |
|
* nextInt(least, bound) returns least <= value < bound; |
155 |
|
* repeated calls produce at least one different result |
176 |
|
*/ |
177 |
|
public void testNextLongBoundedNeg() { |
178 |
|
try { |
179 |
< |
long f = ThreadLocalRandom.current().nextLong(-17); |
179 |
> |
long f = ThreadLocalRandom.current().nextLong(-17); |
180 |
|
shouldThrow(); |
181 |
|
} catch (IllegalArgumentException success) {} |
182 |
|
} |
186 |
|
*/ |
187 |
|
public void testNextLongBadBounds() { |
188 |
|
try { |
189 |
< |
long f = ThreadLocalRandom.current().nextLong(17, 2); |
189 |
> |
long f = ThreadLocalRandom.current().nextLong(17, 2); |
190 |
|
shouldThrow(); |
191 |
|
} catch (IllegalArgumentException success) {} |
192 |
|
} |
231 |
|
} |
232 |
|
} |
233 |
|
|
239 |
– |
|
234 |
|
/** |
235 |
|
* nextDouble(least, bound) returns least <= value < bound; |
236 |
|
* repeated calls produce at least one different result |
252 |
|
} |
253 |
|
} |
254 |
|
|
261 |
– |
|
255 |
|
} |