--- jsr166/src/test/tck/SplittableRandomTest.java 2013/09/24 06:35:35 1.9 +++ jsr166/src/test/tck/SplittableRandomTest.java 2013/09/24 16:39:38 1.11 @@ -39,7 +39,7 @@ public class SplittableRandomTest extend static final int NCALLS = 10000; // max sampled int bound - static final int MAX_INT_BOUND = (1 << 28); + static final int MAX_INT_BOUND = (1 << 26); // max sampled long bound static final long MAX_LONG_BOUND = (1L << 42); @@ -145,10 +145,12 @@ public class SplittableRandomTest extend */ public void testNextIntBadBounds() { SplittableRandom sr = new SplittableRandom(); - try { - int f = sr.nextInt(17, 2); - shouldThrow(); - } catch (IllegalArgumentException success) {} + Runnable[] throwingActions = { + () -> sr.nextInt(17, 2), + () -> sr.nextInt(-42, -42), + () -> sr.nextInt(Integer.MAX_VALUE, Integer.MIN_VALUE), + }; + assertThrows(IllegalArgumentException.class, throwingActions); } /** @@ -212,10 +214,12 @@ public class SplittableRandomTest extend */ public void testNextLongBadBounds() { SplittableRandom sr = new SplittableRandom(); - try { - long f = sr.nextLong(17, 2); - shouldThrow(); - } catch (IllegalArgumentException success) {} + Runnable[] throwingActions = { + () -> sr.nextLong(17L, 2L), + () -> sr.nextLong(-42L, -42L), + () -> sr.nextLong(Long.MAX_VALUE, Long.MIN_VALUE), + }; + assertThrows(IllegalArgumentException.class, throwingActions); } /** @@ -276,6 +280,25 @@ public class SplittableRandomTest extend } /** + * nextDouble(! (least < bound)) throws IllegalArgumentException + */ + public void testNextDoubleBadBounds() { + SplittableRandom sr = new SplittableRandom(); + Runnable[] throwingActions = { + () -> sr.nextDouble(17.0d, 2.0d), + () -> sr.nextDouble(-42.0d, -42.0d), + () -> sr.nextDouble(Double.MAX_VALUE, Double.MIN_VALUE), + () -> sr.nextDouble(Double.NaN, 0.0d), + () -> sr.nextDouble(0.0d, Double.NaN), + }; + assertThrows(IllegalArgumentException.class, throwingActions); + } + + // TODO: Test infinite bounds! + //() -> sr.nextDouble(Double.NEGATIVE_INFINITY, 0.0d), + //() -> sr.nextDouble(0.0d, Double.POSITIVE_INFINITY), + + /** * nextDouble(least, bound) returns least <= value < bound; * repeated calls produce at least two distinct results */