| 24 | static final long SEED = -5450594; |
| 25 | |
| 26 | @Test |
| 27 | public final void testRoll() |
| 28 | { |
| 29 | final Random random = new Random(SEED); |
| 30 | RandomUtil.setRandomGenerator(random); |
| 31 | |
| 32 | random.setSeed(SEED); |
| 33 | int[] rolls = IntStream.generate(() -> RollingMethods.roll(SIDES)).limit(TIMES).sorted().toArray(); |
| 34 | |
| 35 | // Make sure the raw dice roll is in the correct range |
| 36 | assertTrue(IntStream.of(rolls).min().getAsInt() > 0); |
| 37 | assertTrue(IntStream.of(rolls).max().getAsInt() <= SIDES); |
| 38 | |
| 39 | // compute the sum of all the rolls |
| 40 | final int sum = IntStream.of(rolls).sum(); |
| 41 | |
| 42 | // rest the seed so we generate the same random numbers |
| 43 | random.setSeed(SEED); |
| 44 | final int testSum = RollingMethods.roll(TIMES, SIDES); |
| 45 | |
| 46 | // verify the RollingMethods generates the correct results |
| 47 | assertEquals(sum, testSum); |
| 48 | } |
| 49 | |
| 50 | @Test |
| 51 | public final void testTopRoll() |