18 |
|
return new TestSuite(ThreadLocalRandomTest.class); |
19 |
|
} |
20 |
|
|
21 |
< |
/** |
21 |
> |
/* |
22 |
|
* Testing coverage notes: |
23 |
|
* |
24 |
|
* We don't test randomness properties, but only that repeated |
27 |
|
* across multiples of primes. |
28 |
|
*/ |
29 |
|
|
30 |
< |
// |
30 |
> |
// max numbers of calls to detect getting stuck on one value |
31 |
|
static final int NCALLS = 10000; |
32 |
|
|
33 |
|
// max sampled int bound |
34 |
|
static final int MAX_INT_BOUND = (1 << 28); |
35 |
|
|
36 |
< |
// Max sampled long bound |
36 |
> |
// max sampled long bound |
37 |
|
static final long MAX_LONG_BOUND = (1L << 42); |
38 |
|
|
39 |
+ |
// Number of replications for other checks |
40 |
+ |
static final int REPS = 20; |
41 |
+ |
|
42 |
|
/** |
43 |
|
* setSeed throws UnsupportedOperationException |
44 |
|
*/ |
50 |
|
} |
51 |
|
|
52 |
|
/** |
53 |
< |
* Repeated calls to nextInt produce at least one different result |
53 |
> |
* Repeated calls to nextInt produce at least two distinct results |
54 |
|
*/ |
55 |
|
public void testNextInt() { |
56 |
|
int f = ThreadLocalRandom.current().nextInt(); |
61 |
|
} |
62 |
|
|
63 |
|
/** |
64 |
< |
* Repeated calls to nextLong produce at least one different result |
64 |
> |
* Repeated calls to nextLong produce at least two distinct results |
65 |
|
*/ |
66 |
|
public void testNextLong() { |
67 |
|
long f = ThreadLocalRandom.current().nextLong(); |
72 |
|
} |
73 |
|
|
74 |
|
/** |
75 |
< |
* Repeated calls to nextBoolean produce at least one different result |
75 |
> |
* Repeated calls to nextBoolean produce at least two distinct results |
76 |
|
*/ |
77 |
|
public void testNextBoolean() { |
78 |
|
boolean f = ThreadLocalRandom.current().nextBoolean(); |
83 |
|
} |
84 |
|
|
85 |
|
/** |
86 |
< |
* Repeated calls to nextFloat produce at least one different result |
86 |
> |
* Repeated calls to nextFloat produce at least two distinct results |
87 |
|
*/ |
88 |
|
public void testNextFloat() { |
89 |
|
float f = ThreadLocalRandom.current().nextFloat(); |
94 |
|
} |
95 |
|
|
96 |
|
/** |
97 |
< |
* Repeated calls to nextDouble produce at least one different result |
97 |
> |
* Repeated calls to nextDouble produce at least two distinct results |
98 |
|
*/ |
99 |
|
public void testNextDouble() { |
100 |
|
double f = ThreadLocalRandom.current().nextDouble(); |
101 |
< |
double i = 0; |
101 |
> |
int i = 0; |
102 |
|
while (i < NCALLS && ThreadLocalRandom.current().nextDouble() == f) |
103 |
|
++i; |
104 |
|
assertTrue(i < NCALLS); |
105 |
|
} |
106 |
|
|
107 |
|
/** |
108 |
< |
* Repeated calls to nextGaussian produce at least one different result |
108 |
> |
* Repeated calls to nextGaussian produce at least two distinct results |
109 |
|
*/ |
110 |
|
public void testNextGaussian() { |
111 |
|
double f = ThreadLocalRandom.current().nextGaussian(); |
116 |
|
} |
117 |
|
|
118 |
|
/** |
119 |
< |
* nextInt(negative) throws IllegalArgumentException; |
119 |
> |
* nextInt(negative) throws IllegalArgumentException |
120 |
|
*/ |
121 |
|
public void testNextIntBoundedNeg() { |
122 |
|
try { |
126 |
|
} |
127 |
|
|
128 |
|
/** |
129 |
< |
* nextInt(least >= bound) throws IllegalArgumentException; |
129 |
> |
* nextInt(least >= bound) throws IllegalArgumentException |
130 |
|
*/ |
131 |
|
public void testNextIntBadBounds() { |
132 |
|
try { |
137 |
|
|
138 |
|
/** |
139 |
|
* nextInt(bound) returns 0 <= value < bound; |
140 |
< |
* repeated calls produce at least one different result |
140 |
> |
* repeated calls produce at least two distinct results |
141 |
|
*/ |
142 |
|
public void testNextIntBounded() { |
143 |
|
// sample bound space across prime number increments |
157 |
|
|
158 |
|
/** |
159 |
|
* nextInt(least, bound) returns least <= value < bound; |
160 |
< |
* repeated calls produce at least one different result |
160 |
> |
* repeated calls produce at least two distinct results |
161 |
|
*/ |
162 |
|
public void testNextIntBounded2() { |
163 |
|
for (int least = -15485863; least < MAX_INT_BOUND; least += 524959) { |
177 |
|
} |
178 |
|
|
179 |
|
/** |
180 |
< |
* nextLong(negative) throws IllegalArgumentException; |
180 |
> |
* nextLong(negative) throws IllegalArgumentException |
181 |
|
*/ |
182 |
|
public void testNextLongBoundedNeg() { |
183 |
|
try { |
187 |
|
} |
188 |
|
|
189 |
|
/** |
190 |
< |
* nextLong(least >= bound) throws IllegalArgumentException; |
190 |
> |
* nextLong(least >= bound) throws IllegalArgumentException |
191 |
|
*/ |
192 |
|
public void testNextLongBadBounds() { |
193 |
|
try { |
198 |
|
|
199 |
|
/** |
200 |
|
* nextLong(bound) returns 0 <= value < bound; |
201 |
< |
* repeated calls produce at least one different result |
201 |
> |
* repeated calls produce at least two distinct results |
202 |
|
*/ |
203 |
|
public void testNextLongBounded() { |
204 |
|
for (long bound = 2; bound < MAX_LONG_BOUND; bound += 15485863) { |
217 |
|
|
218 |
|
/** |
219 |
|
* nextLong(least, bound) returns least <= value < bound; |
220 |
< |
* repeated calls produce at least one different result |
220 |
> |
* repeated calls produce at least two distinct results |
221 |
|
*/ |
222 |
|
public void testNextLongBounded2() { |
223 |
|
for (long least = -86028121; least < MAX_LONG_BOUND; least += 982451653L) { |
238 |
|
|
239 |
|
/** |
240 |
|
* nextDouble(least, bound) returns least <= value < bound; |
241 |
< |
* repeated calls produce at least one different result |
241 |
> |
* repeated calls produce at least two distinct results |
242 |
|
*/ |
243 |
|
public void testNextDoubleBounded2() { |
244 |
|
for (double least = 0.0001; least < 1.0e20; least *= 8) { |