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

Comparing jsr166/src/test/tck/ThreadLocalRandomTest.java (file contents):
Revision 1.12 by dl, Wed Jan 9 20:22:23 2013 UTC vs.
Revision 1.16 by jsr166, Fri Aug 16 07:07:01 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines