--- jsr166/src/test/tck/SplittableRandomTest.java 2013/09/24 06:35:35 1.9 +++ jsr166/src/test/tck/SplittableRandomTest.java 2013/12/21 21:32:34 1.14 @@ -39,10 +39,10 @@ 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); + static final long MAX_LONG_BOUND = (1L << 40); // Number of replications for other checks static final int REPS = @@ -89,7 +89,7 @@ public class SplittableRandomTest extend * same values for nextLong. */ public void testSeedConstructor() { - for (long seed = 2; seed < MAX_LONG_BOUND; seed += 15485863) { + for (long seed = 2; seed < MAX_LONG_BOUND; seed += 15485863) { SplittableRandom sr1 = new SplittableRandom(seed); SplittableRandom sr2 = new SplittableRandom(seed); for (int i = 0; i < REPS; ++i) @@ -130,7 +130,7 @@ public class SplittableRandomTest extend /** * nextInt(non-positive) throws IllegalArgumentException */ - public void testNextIntNonPositive() { + public void testNextIntBoundNonPositive() { SplittableRandom sr = new SplittableRandom(); Runnable[] throwingActions = { () -> sr.nextInt(-17), @@ -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); } /** @@ -197,7 +199,7 @@ public class SplittableRandomTest extend /** * nextLong(non-positive) throws IllegalArgumentException */ - public void testNextLongNonPositive() { + public void testNextLongBoundNonPositive() { SplittableRandom sr = new SplittableRandom(); Runnable[] throwingActions = { () -> sr.nextLong(-17L), @@ -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); } /** @@ -263,7 +267,7 @@ public class SplittableRandomTest extend /** * nextDouble(non-positive) throws IllegalArgumentException */ - public void testNextDoubleNonPositive() { + public void testNextDoubleBoundNonPositive() { SplittableRandom sr = new SplittableRandom(); Runnable[] throwingActions = { () -> sr.nextDouble(-17.0d), @@ -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 */