--- jsr166/src/test/tck/SplittableRandomTest.java 2013/09/24 06:35:35 1.9 +++ jsr166/src/test/tck/SplittableRandomTest.java 2014/12/31 19:05:43 1.16 @@ -3,13 +3,14 @@ * Expert Group and released to the public domain, as explained at * http://creativecommons.org/publicdomain/zero/1.0/ */ -import junit.framework.*; -import java.util.*; + import java.util.SplittableRandom; import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.LongAdder; +import junit.framework.Test; +import junit.framework.TestSuite; + public class SplittableRandomTest extends JSR166TestCase { public static void main(String[] args) { @@ -39,10 +40,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 +90,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 +131,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 +146,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 +200,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 +215,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 +268,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 +281,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 */