116 |
|
} |
117 |
|
|
118 |
|
/** |
119 |
< |
* nextInt(negative) throws IllegalArgumentException |
119 |
> |
* nextInt(non-positive) throws IllegalArgumentException |
120 |
|
*/ |
121 |
< |
public void testNextIntBoundedNeg() { |
122 |
< |
try { |
123 |
< |
int f = ThreadLocalRandom.current().nextInt(-17); |
124 |
< |
shouldThrow(); |
125 |
< |
} catch (IllegalArgumentException success) {} |
121 |
> |
public void testNextIntBoundNonPositive() { |
122 |
> |
ThreadLocalRandom rnd = ThreadLocalRandom.current(); |
123 |
> |
for (int bound : new int[] { 0, -17, Integer.MIN_VALUE }) { |
124 |
> |
try { |
125 |
> |
rnd.nextInt(bound); |
126 |
> |
shouldThrow(); |
127 |
> |
} catch (IllegalArgumentException success) {} |
128 |
> |
} |
129 |
|
} |
130 |
|
|
131 |
|
/** |
132 |
|
* nextInt(least >= bound) throws IllegalArgumentException |
133 |
|
*/ |
134 |
|
public void testNextIntBadBounds() { |
135 |
< |
try { |
136 |
< |
int f = ThreadLocalRandom.current().nextInt(17, 2); |
137 |
< |
shouldThrow(); |
138 |
< |
} catch (IllegalArgumentException success) {} |
135 |
> |
int[][] badBoundss = { |
136 |
> |
{ 17, 2 }, |
137 |
> |
{ -42, -42 }, |
138 |
> |
{ Integer.MAX_VALUE, Integer.MIN_VALUE }, |
139 |
> |
}; |
140 |
> |
ThreadLocalRandom rnd = ThreadLocalRandom.current(); |
141 |
> |
for (int[] badBounds : badBoundss) { |
142 |
> |
try { |
143 |
> |
rnd.nextInt(badBounds[0], badBounds[1]); |
144 |
> |
shouldThrow(); |
145 |
> |
} catch (IllegalArgumentException success) {} |
146 |
> |
} |
147 |
|
} |
148 |
|
|
149 |
|
/** |
188 |
|
} |
189 |
|
|
190 |
|
/** |
191 |
< |
* nextLong(negative) throws IllegalArgumentException |
191 |
> |
* nextLong(non-positive) throws IllegalArgumentException |
192 |
|
*/ |
193 |
< |
public void testNextLongBoundedNeg() { |
194 |
< |
try { |
195 |
< |
long f = ThreadLocalRandom.current().nextLong(-17); |
196 |
< |
shouldThrow(); |
197 |
< |
} catch (IllegalArgumentException success) {} |
193 |
> |
public void testNextLongBoundNonPositive() { |
194 |
> |
ThreadLocalRandom rnd = ThreadLocalRandom.current(); |
195 |
> |
for (long bound : new long[] { 0L, -17L, Long.MIN_VALUE }) { |
196 |
> |
try { |
197 |
> |
rnd.nextLong(bound); |
198 |
> |
shouldThrow(); |
199 |
> |
} catch (IllegalArgumentException success) {} |
200 |
> |
} |
201 |
|
} |
202 |
|
|
203 |
|
/** |
204 |
|
* nextLong(least >= bound) throws IllegalArgumentException |
205 |
|
*/ |
206 |
|
public void testNextLongBadBounds() { |
207 |
< |
try { |
208 |
< |
long f = ThreadLocalRandom.current().nextLong(17, 2); |
209 |
< |
shouldThrow(); |
210 |
< |
} catch (IllegalArgumentException success) {} |
207 |
> |
long[][] badBoundss = { |
208 |
> |
{ 17L, 2L }, |
209 |
> |
{ -42L, -42L }, |
210 |
> |
{ Long.MAX_VALUE, Long.MIN_VALUE }, |
211 |
> |
}; |
212 |
> |
ThreadLocalRandom rnd = ThreadLocalRandom.current(); |
213 |
> |
for (long[] badBounds : badBoundss) { |
214 |
> |
try { |
215 |
> |
rnd.nextLong(badBounds[0], badBounds[1]); |
216 |
> |
shouldThrow(); |
217 |
> |
} catch (IllegalArgumentException success) {} |
218 |
> |
} |
219 |
|
} |
220 |
|
|
221 |
|
/** |
258 |
|
} |
259 |
|
} |
260 |
|
|
261 |
+ |
/** |
262 |
+ |
* nextDouble(non-positive) throws IllegalArgumentException |
263 |
+ |
*/ |
264 |
+ |
public void testNextDoubleBoundNonPositive() { |
265 |
+ |
ThreadLocalRandom rnd = ThreadLocalRandom.current(); |
266 |
+ |
double[] badBounds = { |
267 |
+ |
0.0d, |
268 |
+ |
-17.0d, |
269 |
+ |
-Double.MIN_VALUE, |
270 |
+ |
Double.NEGATIVE_INFINITY, |
271 |
+ |
Double.NaN, |
272 |
+ |
}; |
273 |
+ |
for (double bound : badBounds) { |
274 |
+ |
try { |
275 |
+ |
rnd.nextDouble(bound); |
276 |
+ |
shouldThrow(); |
277 |
+ |
} catch (IllegalArgumentException success) {} |
278 |
+ |
} |
279 |
+ |
} |
280 |
+ |
|
281 |
|
/** |
282 |
|
* nextDouble(least, bound) returns least <= value < bound; |
283 |
|
* repeated calls produce at least two distinct results |