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.6 by jsr166, Mon Sep 23 17:05:52 2013 UTC vs.
Revision 1.9 by jsr166, Tue Sep 24 06:35:35 2013 UTC

# Line 45 | Line 45 | public class SplittableRandomTest extend
45      static final long MAX_LONG_BOUND = (1L << 42);
46  
47      // Number of replications for other checks
48 <    static final int REPS = 20;
48 >    static final int REPS =
49 >        Integer.getInteger("SplittableRandomTest.reps", 4);
50  
51      /**
52       * Repeated calls to nextInt produce at least two distinct results
# Line 127 | Line 128 | public class SplittableRandomTest extend
128      }
129  
130      /**
131 <     * nextInt(negative) throws IllegalArgumentException
131 >     * nextInt(non-positive) throws IllegalArgumentException
132       */
133 <    public void testNextIntBoundedNeg() {
133 >    public void testNextIntNonPositive() {
134          SplittableRandom sr = new SplittableRandom();
135 <        try {
136 <            int f = sr.nextInt(-17);
137 <            shouldThrow();
138 <        } catch (IllegalArgumentException success) {}
135 >        Runnable[] throwingActions = {
136 >            () -> sr.nextInt(-17),
137 >            () -> sr.nextInt(0),
138 >            () -> sr.nextInt(Integer.MIN_VALUE),
139 >        };
140 >        assertThrows(IllegalArgumentException.class, throwingActions);
141      }
142  
143      /**
# Line 192 | Line 195 | public class SplittableRandomTest extend
195      }
196  
197      /**
198 <     * nextLong(negative) throws IllegalArgumentException
198 >     * nextLong(non-positive) throws IllegalArgumentException
199       */
200 <    public void testNextLongBoundedNeg() {
200 >    public void testNextLongNonPositive() {
201          SplittableRandom sr = new SplittableRandom();
202 <        try {
203 <            long f = sr.nextLong(-17);
204 <            shouldThrow();
205 <        } catch (IllegalArgumentException success) {}
202 >        Runnable[] throwingActions = {
203 >            () -> sr.nextLong(-17L),
204 >            () -> sr.nextLong(0L),
205 >            () -> sr.nextLong(Long.MIN_VALUE),
206 >        };
207 >        assertThrows(IllegalArgumentException.class, throwingActions);
208      }
209  
210      /**
# Line 256 | Line 261 | public class SplittableRandomTest extend
261      }
262  
263      /**
264 +     * nextDouble(non-positive) throws IllegalArgumentException
265 +     */
266 +    public void testNextDoubleNonPositive() {
267 +        SplittableRandom sr = new SplittableRandom();
268 +        Runnable[] throwingActions = {
269 +            () -> sr.nextDouble(-17.0d),
270 +            () -> sr.nextDouble(0.0d),
271 +            () -> sr.nextDouble(-Double.MIN_VALUE),
272 +            () -> sr.nextDouble(Double.NEGATIVE_INFINITY),
273 +            () -> sr.nextDouble(Double.NaN),
274 +        };
275 +        assertThrows(IllegalArgumentException.class, throwingActions);
276 +    }
277 +
278 +    /**
279       * nextDouble(least, bound) returns least <= value < bound;
280       * repeated calls produce at least two distinct results
281       */
# Line 283 | Line 303 | public class SplittableRandomTest extend
303       */
304      public void testBadStreamSize() {
305          SplittableRandom r = new SplittableRandom();
306 <        try {
307 <            java.util.stream.IntStream x = r.ints(-1L);
308 <            shouldThrow();
309 <        } catch (IllegalArgumentException success) {}
310 <        try {
311 <            java.util.stream.IntStream x = r.ints(-1L, 2, 3);
312 <            shouldThrow();
313 <        } catch (IllegalArgumentException success) {}
314 <        try {
295 <            java.util.stream.LongStream x = r.longs(-1L);
296 <            shouldThrow();
297 <        } catch (IllegalArgumentException success) {}
298 <        try {
299 <            java.util.stream.LongStream x = r.longs(-1L, -1L, 1L);
300 <            shouldThrow();
301 <        } catch (IllegalArgumentException success) {}
302 <        try {
303 <            java.util.stream.DoubleStream x = r.doubles(-1L);
304 <            shouldThrow();
305 <        } catch (IllegalArgumentException success) {}
306 <        try {
307 <            java.util.stream.DoubleStream x = r.doubles(-1L, .5, .6);
308 <            shouldThrow();
309 <        } catch (IllegalArgumentException success) {}
306 >        Runnable[] throwingActions = {
307 >            () -> { java.util.stream.IntStream x = r.ints(-1L); },
308 >            () -> { java.util.stream.IntStream x = r.ints(-1L, 2, 3); },
309 >            () -> { java.util.stream.LongStream x = r.longs(-1L); },
310 >            () -> { java.util.stream.LongStream x = r.longs(-1L, -1L, 1L); },
311 >            () -> { java.util.stream.DoubleStream x = r.doubles(-1L); },
312 >            () -> { java.util.stream.DoubleStream x = r.doubles(-1L, .5, .6); },
313 >        };
314 >        assertThrows(IllegalArgumentException.class, throwingActions);
315      }
316  
317      /**
# Line 315 | Line 320 | public class SplittableRandomTest extend
320       */
321      public void testBadStreamBounds() {
322          SplittableRandom r = new SplittableRandom();
323 <        try {
324 <            java.util.stream.IntStream x = r.ints(2, 1);
325 <            shouldThrow();
326 <        } catch (IllegalArgumentException success) {}
327 <        try {
328 <            java.util.stream.IntStream x = r.ints(10, 42, 42);
329 <            shouldThrow();
330 <        } catch (IllegalArgumentException success) {}
331 <        try {
327 <            java.util.stream.LongStream x = r.longs(-1L, -1L);
328 <            shouldThrow();
329 <        } catch (IllegalArgumentException success) {}
330 <        try {
331 <            java.util.stream.LongStream x = r.longs(10, 1L, -2L);
332 <            shouldThrow();
333 <        } catch (IllegalArgumentException success) {}
334 <        try {
335 <            java.util.stream.DoubleStream x = r.doubles(0.0, 0.0);
336 <            shouldThrow();
337 <        } catch (IllegalArgumentException success) {}
338 <        try {
339 <            java.util.stream.DoubleStream x = r.doubles(10, .5, .4);
340 <            shouldThrow();
341 <        } catch (IllegalArgumentException success) {}
323 >        Runnable[] throwingActions = {
324 >            () -> { java.util.stream.IntStream x = r.ints(2, 1); },
325 >            () -> { java.util.stream.IntStream x = r.ints(10, 42, 42); },
326 >            () -> { java.util.stream.LongStream x = r.longs(-1L, -1L); },
327 >            () -> { java.util.stream.LongStream x = r.longs(10, 1L, -2L); },
328 >            () -> { java.util.stream.DoubleStream x = r.doubles(0.0, 0.0); },
329 >            () -> { java.util.stream.DoubleStream x = r.doubles(10, .5, .4); },
330 >        };
331 >        assertThrows(IllegalArgumentException.class, throwingActions);
332      }
333  
334      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines