ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ThreadLocalRandom8Test.java
(Generate patch)

Comparing jsr166/src/test/tck/ThreadLocalRandom8Test.java (file contents):
Revision 1.1 by jsr166, Fri Aug 16 07:07:01 2013 UTC vs.
Revision 1.6 by jsr166, Fri Sep 27 20:28:04 2013 UTC

# Line 6 | Line 6
6   import junit.framework.*;
7   import java.util.*;
8   import java.util.concurrent.ThreadLocalRandom;
9 import java.util.concurrent.atomic.AtomicLong;
9   import java.util.concurrent.atomic.AtomicInteger;
11 import java.util.concurrent.atomic.AtomicReference;
10   import java.util.concurrent.atomic.LongAdder;
11  
12   public class ThreadLocalRandom8Test extends JSR166TestCase {
# Line 21 | Line 19 | public class ThreadLocalRandom8Test exte
19      }
20  
21      // max sampled int bound
22 <    static final int MAX_INT_BOUND = (1 << 28);
22 >    static final int MAX_INT_BOUND = (1 << 26);
23  
24      // max sampled long bound
25      static final long MAX_LONG_BOUND = (1L << 42);
26  
27      // Number of replications for other checks
28 <    static final int REPS = 20;
28 >    static final int REPS =
29 >        Integer.getInteger("ThreadLocalRandom8Test.reps", 4);
30  
31      /**
32       * Invoking sized ints, long, doubles, with negative sizes throws
# Line 35 | Line 34 | public class ThreadLocalRandom8Test exte
34       */
35      public void testBadStreamSize() {
36          ThreadLocalRandom r = ThreadLocalRandom.current();
37 <        try {
38 <            java.util.stream.IntStream x = r.ints(-1L);
39 <            shouldThrow();
40 <        } catch (IllegalArgumentException success) {}
41 <        try {
42 <            java.util.stream.IntStream x = r.ints(-1L, 2, 3);
43 <            shouldThrow();
44 <        } catch (IllegalArgumentException success) {}
45 <        try {
47 <            java.util.stream.LongStream x = r.longs(-1L);
48 <            shouldThrow();
49 <        } catch (IllegalArgumentException success) {}
50 <        try {
51 <            java.util.stream.LongStream x = r.longs(-1L, -1L, 1L);
52 <            shouldThrow();
53 <        } catch (IllegalArgumentException success) {}
54 <        try {
55 <            java.util.stream.DoubleStream x = r.doubles(-1L);
56 <            shouldThrow();
57 <        } catch (IllegalArgumentException success) {}
58 <        try {
59 <            java.util.stream.DoubleStream x = r.doubles(-1L, .5, .6);
60 <            shouldThrow();
61 <        } catch (IllegalArgumentException success) {}
37 >        Runnable[] throwingActions = {
38 >            () -> r.ints(-1L),
39 >            () -> r.ints(-1L, 2, 3),
40 >            () -> r.longs(-1L),
41 >            () -> r.longs(-1L, -1L, 1L),
42 >            () -> r.doubles(-1L),
43 >            () -> r.doubles(-1L, .5, .6),
44 >        };
45 >        assertThrows(IllegalArgumentException.class, throwingActions);
46      }
47  
48      /**
# Line 67 | Line 51 | public class ThreadLocalRandom8Test exte
51       */
52      public void testBadStreamBounds() {
53          ThreadLocalRandom r = ThreadLocalRandom.current();
54 <        try {
55 <            java.util.stream.IntStream x = r.ints(2, 1);
56 <            shouldThrow();
57 <        } catch (IllegalArgumentException success) {}
58 <        try {
59 <            java.util.stream.IntStream x = r.ints(10, 42, 42);
60 <            shouldThrow();
61 <        } catch (IllegalArgumentException success) {}
62 <        try {
79 <            java.util.stream.LongStream x = r.longs(-1L, -1L);
80 <            shouldThrow();
81 <        } catch (IllegalArgumentException success) {}
82 <        try {
83 <            java.util.stream.LongStream x = r.longs(10, 1L, -2L);
84 <            shouldThrow();
85 <        } catch (IllegalArgumentException success) {}
86 <        try {
87 <            java.util.stream.DoubleStream x = r.doubles(0.0, 0.0);
88 <            shouldThrow();
89 <        } catch (IllegalArgumentException success) {}
90 <        try {
91 <            java.util.stream.DoubleStream x = r.doubles(10, .5, .4);
92 <            shouldThrow();
93 <        } catch (IllegalArgumentException success) {}
54 >        Runnable[] throwingActions = {
55 >            () -> r.ints(2, 1),
56 >            () -> r.ints(10, 42, 42),
57 >            () -> r.longs(-1L, -1L),
58 >            () -> r.longs(10, 1L, -2L),
59 >            () -> r.doubles(0.0, 0.0),
60 >            () -> r.doubles(10, .5, .4),
61 >        };
62 >        assertThrows(IllegalArgumentException.class, throwingActions);
63      }
64  
65      /**
# Line 102 | Line 71 | public class ThreadLocalRandom8Test exte
71          long size = 0;
72          for (int reps = 0; reps < REPS; ++reps) {
73              counter.reset();
74 <            r.ints(size).parallel().forEach(x -> {counter.increment();});
74 >            r.ints(size).parallel().forEach(x -> counter.increment());
75              assertEquals(size, counter.sum());
76              size += 524959;
77          }
# Line 117 | Line 86 | public class ThreadLocalRandom8Test exte
86          long size = 0;
87          for (int reps = 0; reps < REPS; ++reps) {
88              counter.reset();
89 <            r.longs(size).parallel().forEach(x -> {counter.increment();});
89 >            r.longs(size).parallel().forEach(x -> counter.increment());
90              assertEquals(size, counter.sum());
91              size += 524959;
92          }
# Line 132 | Line 101 | public class ThreadLocalRandom8Test exte
101          long size = 0;
102          for (int reps = 0; reps < REPS; ++reps) {
103              counter.reset();
104 <            r.doubles(size).parallel().forEach(x -> {counter.increment();});
104 >            r.doubles(size).parallel().forEach(x -> counter.increment());
105              assertEquals(size, counter.sum());
106              size += 524959;
107          }
# Line 199 | Line 168 | public class ThreadLocalRandom8Test exte
168          LongAdder counter = new LongAdder();
169          ThreadLocalRandom r = ThreadLocalRandom.current();
170          long size = 100;
171 <        r.ints().limit(size).parallel().forEach(x -> {counter.increment();});
171 >        r.ints().limit(size).parallel().forEach(x -> counter.increment());
172          assertEquals(size, counter.sum());
173      }
174  
# Line 210 | Line 179 | public class ThreadLocalRandom8Test exte
179          LongAdder counter = new LongAdder();
180          ThreadLocalRandom r = ThreadLocalRandom.current();
181          long size = 100;
182 <        r.longs().limit(size).parallel().forEach(x -> {counter.increment();});
182 >        r.longs().limit(size).parallel().forEach(x -> counter.increment());
183          assertEquals(size, counter.sum());
184      }
185  
# Line 221 | Line 190 | public class ThreadLocalRandom8Test exte
190          LongAdder counter = new LongAdder();
191          ThreadLocalRandom r = ThreadLocalRandom.current();
192          long size = 100;
193 <        r.doubles().limit(size).parallel().forEach(x -> {counter.increment();});
193 >        r.doubles().limit(size).parallel().forEach(x -> counter.increment());
194          assertEquals(size, counter.sum());
195      }
196  
# Line 232 | Line 201 | public class ThreadLocalRandom8Test exte
201          LongAdder counter = new LongAdder();
202          ThreadLocalRandom r = ThreadLocalRandom.current();
203          long size = 100;
204 <        r.ints().limit(size).forEach(x -> {counter.increment();});
204 >        r.ints().limit(size).forEach(x -> counter.increment());
205          assertEquals(size, counter.sum());
206      }
207  
# Line 243 | Line 212 | public class ThreadLocalRandom8Test exte
212          LongAdder counter = new LongAdder();
213          ThreadLocalRandom r = ThreadLocalRandom.current();
214          long size = 100;
215 <        r.longs().limit(size).forEach(x -> {counter.increment();});
215 >        r.longs().limit(size).forEach(x -> counter.increment());
216          assertEquals(size, counter.sum());
217      }
218  
# Line 254 | Line 223 | public class ThreadLocalRandom8Test exte
223          LongAdder counter = new LongAdder();
224          ThreadLocalRandom r = ThreadLocalRandom.current();
225          long size = 100;
226 <        r.doubles().limit(size).forEach(x -> {counter.increment();});
226 >        r.doubles().limit(size).forEach(x -> counter.increment());
227          assertEquals(size, counter.sum());
228      }
229  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines