3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
< |
import junit.framework.*; |
7 |
< |
import java.util.*; |
6 |
> |
|
7 |
|
import java.util.concurrent.ThreadLocalRandom; |
8 |
|
import java.util.concurrent.atomic.AtomicInteger; |
9 |
|
import java.util.concurrent.atomic.LongAdder; |
10 |
|
|
11 |
+ |
import junit.framework.Test; |
12 |
+ |
import junit.framework.TestSuite; |
13 |
+ |
|
14 |
|
public class ThreadLocalRandom8Test extends JSR166TestCase { |
15 |
|
|
16 |
|
public static void main(String[] args) { |
36 |
|
*/ |
37 |
|
public void testBadStreamSize() { |
38 |
|
ThreadLocalRandom r = ThreadLocalRandom.current(); |
39 |
< |
try { |
40 |
< |
java.util.stream.IntStream x = r.ints(-1L); |
41 |
< |
shouldThrow(); |
42 |
< |
} catch (IllegalArgumentException success) {} |
43 |
< |
try { |
44 |
< |
java.util.stream.IntStream x = r.ints(-1L, 2, 3); |
45 |
< |
shouldThrow(); |
46 |
< |
} catch (IllegalArgumentException success) {} |
47 |
< |
try { |
46 |
< |
java.util.stream.LongStream x = r.longs(-1L); |
47 |
< |
shouldThrow(); |
48 |
< |
} catch (IllegalArgumentException success) {} |
49 |
< |
try { |
50 |
< |
java.util.stream.LongStream x = r.longs(-1L, -1L, 1L); |
51 |
< |
shouldThrow(); |
52 |
< |
} catch (IllegalArgumentException success) {} |
53 |
< |
try { |
54 |
< |
java.util.stream.DoubleStream x = r.doubles(-1L); |
55 |
< |
shouldThrow(); |
56 |
< |
} catch (IllegalArgumentException success) {} |
57 |
< |
try { |
58 |
< |
java.util.stream.DoubleStream x = r.doubles(-1L, .5, .6); |
59 |
< |
shouldThrow(); |
60 |
< |
} catch (IllegalArgumentException success) {} |
39 |
> |
Runnable[] throwingActions = { |
40 |
> |
() -> r.ints(-1L), |
41 |
> |
() -> r.ints(-1L, 2, 3), |
42 |
> |
() -> r.longs(-1L), |
43 |
> |
() -> r.longs(-1L, -1L, 1L), |
44 |
> |
() -> r.doubles(-1L), |
45 |
> |
() -> r.doubles(-1L, .5, .6), |
46 |
> |
}; |
47 |
> |
assertThrows(IllegalArgumentException.class, throwingActions); |
48 |
|
} |
49 |
|
|
50 |
|
/** |
53 |
|
*/ |
54 |
|
public void testBadStreamBounds() { |
55 |
|
ThreadLocalRandom r = ThreadLocalRandom.current(); |
56 |
< |
try { |
57 |
< |
java.util.stream.IntStream x = r.ints(2, 1); |
58 |
< |
shouldThrow(); |
59 |
< |
} catch (IllegalArgumentException success) {} |
60 |
< |
try { |
61 |
< |
java.util.stream.IntStream x = r.ints(10, 42, 42); |
62 |
< |
shouldThrow(); |
63 |
< |
} catch (IllegalArgumentException success) {} |
64 |
< |
try { |
78 |
< |
java.util.stream.LongStream x = r.longs(-1L, -1L); |
79 |
< |
shouldThrow(); |
80 |
< |
} catch (IllegalArgumentException success) {} |
81 |
< |
try { |
82 |
< |
java.util.stream.LongStream x = r.longs(10, 1L, -2L); |
83 |
< |
shouldThrow(); |
84 |
< |
} catch (IllegalArgumentException success) {} |
85 |
< |
try { |
86 |
< |
java.util.stream.DoubleStream x = r.doubles(0.0, 0.0); |
87 |
< |
shouldThrow(); |
88 |
< |
} catch (IllegalArgumentException success) {} |
89 |
< |
try { |
90 |
< |
java.util.stream.DoubleStream x = r.doubles(10, .5, .4); |
91 |
< |
shouldThrow(); |
92 |
< |
} catch (IllegalArgumentException success) {} |
56 |
> |
Runnable[] throwingActions = { |
57 |
> |
() -> r.ints(2, 1), |
58 |
> |
() -> r.ints(10, 42, 42), |
59 |
> |
() -> r.longs(-1L, -1L), |
60 |
> |
() -> r.longs(10, 1L, -2L), |
61 |
> |
() -> r.doubles(0.0, 0.0), |
62 |
> |
() -> r.doubles(10, .5, .4), |
63 |
> |
}; |
64 |
> |
assertThrows(IllegalArgumentException.class, throwingActions); |
65 |
|
} |
66 |
|
|
67 |
|
/** |