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.1 by dl, Fri Jul 31 23:02:50 2009 UTC vs.
Revision 1.9 by jsr166, Fri May 27 19:44:03 2011 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6   import junit.framework.*;
7   import java.util.concurrent.*;
8   import java.util.*;
9  
10
10   public class ThreadLocalRandomTest extends JSR166TestCase {
11  
12      public static void main(String[] args) {
13 <        junit.textui.TestRunner.run (suite());  
13 >        junit.textui.TestRunner.run(suite());
14      }
15      public static Test suite() {
16 <        return new TestSuite(ThreadLocalRandomTest.class);
16 >        return new TestSuite(ThreadLocalRandomTest.class);
17      }
18  
19      /**
20       * Testing coverage notes:
21 <     *
21 >     *
22       * We don't test randomness properties, but only that repeated
23       * calls, up to NCALLS tries, produce at least one different
24       * result.  For bounded versions, we sample various intervals
25       * across multiples of primes.
26       */
27  
28 <    //
28 >    //
29      static final int NCALLS = 10000;
30  
31      // max sampled int bound
# Line 41 | Line 40 | public class ThreadLocalRandomTest exten
40      public void testSetSeed() {
41          try {
42              ThreadLocalRandom.current().setSeed(17);
43 <        } catch(UnsupportedOperationException success) {
44 <        }
43 >            shouldThrow();
44 >        } catch (UnsupportedOperationException success) {}
45      }
46  
47      /**
# Line 67 | Line 66 | public class ThreadLocalRandomTest exten
66          assertTrue(i < NCALLS);
67      }
68  
70
69      /**
70       * Repeated calls to nextBoolean produce at least one different result
71       */
# Line 112 | Line 110 | public class ThreadLocalRandomTest exten
110          assertTrue(i < NCALLS);
111      }
112  
115
113      /**
114       * nextInt(negative) throws IllegalArgumentException;
115       */
116      public void testNextIntBoundedNeg() {
117          try {
118 <            int  f = ThreadLocalRandom.current().nextInt(-17);
119 <        } catch(IllegalArgumentException success) {
120 <        }
118 >            int f = ThreadLocalRandom.current().nextInt(-17);
119 >            shouldThrow();
120 >        } catch (IllegalArgumentException success) {}
121      }
122  
123      /**
# Line 128 | Line 125 | public class ThreadLocalRandomTest exten
125       */
126      public void testNextIntBadBounds() {
127          try {
128 <            int  f = ThreadLocalRandom.current().nextInt(17, 2);
129 <        } catch(IllegalArgumentException success) {
130 <        }
128 >            int f = ThreadLocalRandom.current().nextInt(17, 2);
129 >            shouldThrow();
130 >        } catch (IllegalArgumentException success) {}
131      }
132  
136
133      /**
134       * nextInt(bound) returns 0 <= value < bound;
135       * repeated calls produce at least one different result
# Line 145 | Line 141 | public class ThreadLocalRandomTest exten
141              assertTrue(0 <= f && f < bound);
142              int i = 0;
143              int j;
144 <            while (i < NCALLS &&
144 >            while (i < NCALLS &&
145                     (j = ThreadLocalRandom.current().nextInt(bound)) == f) {
146                  assertTrue(0 <= j && j < bound);
147                  ++i;
# Line 154 | Line 150 | public class ThreadLocalRandomTest exten
150          }
151      }
152  
157
153      /**
154       * nextInt(least, bound) returns least <= value < bound;
155       * repeated calls produce at least one different result
# Line 166 | Line 161 | public class ThreadLocalRandomTest exten
161                  assertTrue(least <= f && f < bound);
162                  int i = 0;
163                  int j;
164 <                while (i < NCALLS &&
164 >                while (i < NCALLS &&
165                         (j = ThreadLocalRandom.current().nextInt(least, bound)) == f) {
166                      assertTrue(least <= j && j < bound);
167                      ++i;
# Line 181 | Line 176 | public class ThreadLocalRandomTest exten
176       */
177      public void testNextLongBoundedNeg() {
178          try {
179 <            long  f = ThreadLocalRandom.current().nextLong(-17);
180 <        } catch(IllegalArgumentException success) {
181 <        }
179 >            long f = ThreadLocalRandom.current().nextLong(-17);
180 >            shouldThrow();
181 >        } catch (IllegalArgumentException success) {}
182      }
183  
184      /**
# Line 191 | Line 186 | public class ThreadLocalRandomTest exten
186       */
187      public void testNextLongBadBounds() {
188          try {
189 <            long  f = ThreadLocalRandom.current().nextLong(17, 2);
190 <        } catch(IllegalArgumentException success) {
191 <        }
189 >            long f = ThreadLocalRandom.current().nextLong(17, 2);
190 >            shouldThrow();
191 >        } catch (IllegalArgumentException success) {}
192      }
193  
194      /**
# Line 206 | Line 201 | public class ThreadLocalRandomTest exten
201              assertTrue(0 <= f && f < bound);
202              int i = 0;
203              long j;
204 <            while (i < NCALLS &&
204 >            while (i < NCALLS &&
205                     (j = ThreadLocalRandom.current().nextLong(bound)) == f) {
206                  assertTrue(0 <= j && j < bound);
207                  ++i;
# Line 226 | Line 221 | public class ThreadLocalRandomTest exten
221                  assertTrue(least <= f && f < bound);
222                  int i = 0;
223                  long j;
224 <                while (i < NCALLS &&
224 >                while (i < NCALLS &&
225                         (j = ThreadLocalRandom.current().nextLong(least, bound)) == f) {
226                      assertTrue(least <= j && j < bound);
227                      ++i;
# Line 236 | Line 231 | public class ThreadLocalRandomTest exten
231          }
232      }
233  
239
234      /**
235       * nextDouble(least, bound) returns least <= value < bound;
236       * repeated calls produce at least one different result
# Line 248 | Line 242 | public class ThreadLocalRandomTest exten
242                  assertTrue(least <= f && f < bound);
243                  int i = 0;
244                  double j;
245 <                while (i < NCALLS &&
245 >                while (i < NCALLS &&
246                         (j = ThreadLocalRandom.current().nextDouble(least, bound)) == f) {
247                      assertTrue(least <= j && j < bound);
248                      ++i;
# Line 258 | Line 252 | public class ThreadLocalRandomTest exten
252          }
253      }
254  
261
255   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines