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

Comparing jsr166/src/test/tck/SplittableRandomTest.java (file contents):
Revision 1.7 by jsr166, Mon Sep 23 17:23:50 2013 UTC vs.
Revision 1.15 by jsr166, Wed Dec 31 16:44:02 2014 UTC

# Line 7 | Line 7 | import junit.framework.*;
7   import java.util.*;
8   import java.util.SplittableRandom;
9   import java.util.concurrent.atomic.AtomicInteger;
10 import java.util.concurrent.atomic.AtomicLong;
10   import java.util.concurrent.atomic.LongAdder;
11  
12   public class SplittableRandomTest extends JSR166TestCase {
# Line 39 | Line 38 | public class SplittableRandomTest extend
38      static final int NCALLS = 10000;
39  
40      // max sampled int bound
41 <    static final int MAX_INT_BOUND = (1 << 28);
41 >    static final int MAX_INT_BOUND = (1 << 26);
42  
43      // max sampled long bound
44 <    static final long MAX_LONG_BOUND = (1L << 42);
44 >    static final long MAX_LONG_BOUND = (1L << 40);
45  
46      // Number of replications for other checks
47      static final int REPS =
# Line 89 | Line 88 | public class SplittableRandomTest extend
88       * same values for nextLong.
89       */
90      public void testSeedConstructor() {
91 <        for (long seed = 2; seed < MAX_LONG_BOUND; seed += 15485863)  {
91 >        for (long seed = 2; seed < MAX_LONG_BOUND; seed += 15485863) {
92              SplittableRandom sr1 = new SplittableRandom(seed);
93              SplittableRandom sr2 = new SplittableRandom(seed);
94              for (int i = 0; i < REPS; ++i)
# Line 128 | Line 127 | public class SplittableRandomTest extend
127      }
128  
129      /**
130 <     * nextInt(negative) throws IllegalArgumentException
130 >     * nextInt(non-positive) throws IllegalArgumentException
131       */
132 <    public void testNextIntBoundedNeg() {
132 >    public void testNextIntBoundNonPositive() {
133          SplittableRandom sr = new SplittableRandom();
134 <        try {
135 <            int f = sr.nextInt(-17);
136 <            shouldThrow();
137 <        } catch (IllegalArgumentException success) {}
134 >        Runnable[] throwingActions = {
135 >            () -> sr.nextInt(-17),
136 >            () -> sr.nextInt(0),
137 >            () -> sr.nextInt(Integer.MIN_VALUE),
138 >        };
139 >        assertThrows(IllegalArgumentException.class, throwingActions);
140      }
141  
142      /**
# Line 143 | Line 144 | public class SplittableRandomTest extend
144       */
145      public void testNextIntBadBounds() {
146          SplittableRandom sr = new SplittableRandom();
147 <        try {
148 <            int f = sr.nextInt(17, 2);
149 <            shouldThrow();
150 <        } catch (IllegalArgumentException success) {}
147 >        Runnable[] throwingActions = {
148 >            () -> sr.nextInt(17, 2),
149 >            () -> sr.nextInt(-42, -42),
150 >            () -> sr.nextInt(Integer.MAX_VALUE, Integer.MIN_VALUE),
151 >        };
152 >        assertThrows(IllegalArgumentException.class, throwingActions);
153      }
154  
155      /**
# Line 193 | Line 196 | public class SplittableRandomTest extend
196      }
197  
198      /**
199 <     * nextLong(negative) throws IllegalArgumentException
199 >     * nextLong(non-positive) throws IllegalArgumentException
200       */
201 <    public void testNextLongBoundedNeg() {
201 >    public void testNextLongBoundNonPositive() {
202          SplittableRandom sr = new SplittableRandom();
203 <        try {
204 <            long f = sr.nextLong(-17);
205 <            shouldThrow();
206 <        } catch (IllegalArgumentException success) {}
203 >        Runnable[] throwingActions = {
204 >            () -> sr.nextLong(-17L),
205 >            () -> sr.nextLong(0L),
206 >            () -> sr.nextLong(Long.MIN_VALUE),
207 >        };
208 >        assertThrows(IllegalArgumentException.class, throwingActions);
209      }
210  
211      /**
# Line 208 | Line 213 | public class SplittableRandomTest extend
213       */
214      public void testNextLongBadBounds() {
215          SplittableRandom sr = new SplittableRandom();
216 <        try {
217 <            long f = sr.nextLong(17, 2);
218 <            shouldThrow();
219 <        } catch (IllegalArgumentException success) {}
216 >        Runnable[] throwingActions = {
217 >            () -> sr.nextLong(17L, 2L),
218 >            () -> sr.nextLong(-42L, -42L),
219 >            () -> sr.nextLong(Long.MAX_VALUE, Long.MIN_VALUE),
220 >        };
221 >        assertThrows(IllegalArgumentException.class, throwingActions);
222      }
223  
224      /**
# Line 257 | Line 264 | public class SplittableRandomTest extend
264      }
265  
266      /**
267 +     * nextDouble(non-positive) throws IllegalArgumentException
268 +     */
269 +    public void testNextDoubleBoundNonPositive() {
270 +        SplittableRandom sr = new SplittableRandom();
271 +        Runnable[] throwingActions = {
272 +            () -> sr.nextDouble(-17.0d),
273 +            () -> sr.nextDouble(0.0d),
274 +            () -> sr.nextDouble(-Double.MIN_VALUE),
275 +            () -> sr.nextDouble(Double.NEGATIVE_INFINITY),
276 +            () -> sr.nextDouble(Double.NaN),
277 +        };
278 +        assertThrows(IllegalArgumentException.class, throwingActions);
279 +    }
280 +
281 +    /**
282 +     * nextDouble(! (least < bound)) throws IllegalArgumentException
283 +     */
284 +    public void testNextDoubleBadBounds() {
285 +        SplittableRandom sr = new SplittableRandom();
286 +        Runnable[] throwingActions = {
287 +            () -> sr.nextDouble(17.0d, 2.0d),
288 +            () -> sr.nextDouble(-42.0d, -42.0d),
289 +            () -> sr.nextDouble(Double.MAX_VALUE, Double.MIN_VALUE),
290 +            () -> sr.nextDouble(Double.NaN, 0.0d),
291 +            () -> sr.nextDouble(0.0d, Double.NaN),
292 +        };
293 +        assertThrows(IllegalArgumentException.class, throwingActions);
294 +    }
295 +
296 +    // TODO: Test infinite bounds!
297 +    //() -> sr.nextDouble(Double.NEGATIVE_INFINITY, 0.0d),
298 +    //() -> sr.nextDouble(0.0d, Double.POSITIVE_INFINITY),
299 +
300 +    /**
301       * nextDouble(least, bound) returns least <= value < bound;
302       * repeated calls produce at least two distinct results
303       */
# Line 284 | Line 325 | public class SplittableRandomTest extend
325       */
326      public void testBadStreamSize() {
327          SplittableRandom r = new SplittableRandom();
328 <        try {
329 <            java.util.stream.IntStream x = r.ints(-1L);
330 <            shouldThrow();
331 <        } catch (IllegalArgumentException success) {}
332 <        try {
333 <            java.util.stream.IntStream x = r.ints(-1L, 2, 3);
334 <            shouldThrow();
335 <        } catch (IllegalArgumentException success) {}
336 <        try {
296 <            java.util.stream.LongStream x = r.longs(-1L);
297 <            shouldThrow();
298 <        } catch (IllegalArgumentException success) {}
299 <        try {
300 <            java.util.stream.LongStream x = r.longs(-1L, -1L, 1L);
301 <            shouldThrow();
302 <        } catch (IllegalArgumentException success) {}
303 <        try {
304 <            java.util.stream.DoubleStream x = r.doubles(-1L);
305 <            shouldThrow();
306 <        } catch (IllegalArgumentException success) {}
307 <        try {
308 <            java.util.stream.DoubleStream x = r.doubles(-1L, .5, .6);
309 <            shouldThrow();
310 <        } catch (IllegalArgumentException success) {}
328 >        Runnable[] throwingActions = {
329 >            () -> { java.util.stream.IntStream x = r.ints(-1L); },
330 >            () -> { java.util.stream.IntStream x = r.ints(-1L, 2, 3); },
331 >            () -> { java.util.stream.LongStream x = r.longs(-1L); },
332 >            () -> { java.util.stream.LongStream x = r.longs(-1L, -1L, 1L); },
333 >            () -> { java.util.stream.DoubleStream x = r.doubles(-1L); },
334 >            () -> { java.util.stream.DoubleStream x = r.doubles(-1L, .5, .6); },
335 >        };
336 >        assertThrows(IllegalArgumentException.class, throwingActions);
337      }
338  
339      /**
# Line 316 | Line 342 | public class SplittableRandomTest extend
342       */
343      public void testBadStreamBounds() {
344          SplittableRandom r = new SplittableRandom();
345 <        try {
346 <            java.util.stream.IntStream x = r.ints(2, 1);
347 <            shouldThrow();
348 <        } catch (IllegalArgumentException success) {}
349 <        try {
350 <            java.util.stream.IntStream x = r.ints(10, 42, 42);
351 <            shouldThrow();
352 <        } catch (IllegalArgumentException success) {}
353 <        try {
328 <            java.util.stream.LongStream x = r.longs(-1L, -1L);
329 <            shouldThrow();
330 <        } catch (IllegalArgumentException success) {}
331 <        try {
332 <            java.util.stream.LongStream x = r.longs(10, 1L, -2L);
333 <            shouldThrow();
334 <        } catch (IllegalArgumentException success) {}
335 <        try {
336 <            java.util.stream.DoubleStream x = r.doubles(0.0, 0.0);
337 <            shouldThrow();
338 <        } catch (IllegalArgumentException success) {}
339 <        try {
340 <            java.util.stream.DoubleStream x = r.doubles(10, .5, .4);
341 <            shouldThrow();
342 <        } catch (IllegalArgumentException success) {}
345 >        Runnable[] throwingActions = {
346 >            () -> { java.util.stream.IntStream x = r.ints(2, 1); },
347 >            () -> { java.util.stream.IntStream x = r.ints(10, 42, 42); },
348 >            () -> { java.util.stream.LongStream x = r.longs(-1L, -1L); },
349 >            () -> { java.util.stream.LongStream x = r.longs(10, 1L, -2L); },
350 >            () -> { java.util.stream.DoubleStream x = r.doubles(0.0, 0.0); },
351 >            () -> { java.util.stream.DoubleStream x = r.doubles(10, .5, .4); },
352 >        };
353 >        assertThrows(IllegalArgumentException.class, throwingActions);
354      }
355  
356      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines