@Test public void testNextIntIAE() { try { randomData.nextInt(4, 3); Assert.fail("MathIllegalArgumentException expected"); } catch (MathIllegalArgumentException ex) { // ignored } }
@Test public void testNextIntWideRange() { int lower = -0x6543210F; int upper = 0x456789AB; int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; for (int i = 0; i < 1000000; ++i) { int r = randomData.nextInt(lower, upper); max = FastMath.max(max, r); min = FastMath.min(min, r); Assert.assertTrue(r >= lower); Assert.assertTrue(r <= upper); } double ratio = (((double) max) - ((double) min)) / (((double) upper) - ((double) lower)); Assert.assertTrue(ratio > 0.99999); }
private void checkNextIntUniform(int min, int max) { final Frequency freq = new Frequency(); for (int i = 0; i < smallSampleSize; i++) { final int value = randomData.nextInt(min, max); Assert.assertTrue("nextInt range", (value >= min) && (value <= max)); freq.addValue(value); } final int len = max - min + 1; final long[] observed = new long[len]; for (int i = 0; i < len; i++) { observed[i] = freq.getCount(min + i); } final double[] expected = new double[len]; for (int i = 0; i < len; i++) { expected[i] = 1d / len; } TestUtils.assertChiSquareAccept(expected, observed, 0.001); }
@Test public void testNextIntExtremeValues() { int x = randomData.nextInt(Integer.MIN_VALUE, Integer.MAX_VALUE); int y = randomData.nextInt(Integer.MIN_VALUE, Integer.MAX_VALUE); Assert.assertFalse(x == y); }