Sampler { public static IntSeries sampleIndex(int sampleSize, int originalSize) { return sampleIndex(sampleSize, originalSize, defaultRandom); }  static Random getDefaultRandom(); static IntSeries sampleIndex(int sampleSize, int originalSize); static IntSeries sampleIndex(int sampleSize, int originalSize, Random random);  }
@Test public void testSampleIndex_SizeTooLarge() { assertThrows(IllegalArgumentException.class, () -> Sampler.sampleIndex(6, 5, new Random(5))); }
@Test public void testSampleIndex() { IntSeries sample = Sampler.sampleIndex(5, 10, new Random(5)); new IntSeriesAsserts(sample).expectData(3, 4, 2, 8, 5); }
@Test public void testSampleIndex_SameSize() { IntSeries sample = Sampler.sampleIndex(5, 5, new Random(5)); new IntSeriesAsserts(sample).expectData(3, 1, 4, 0, 2); }
@Test public void testSampleIndex_NonRepeating() { IntSeries sample = Sampler.sampleIndex(50, 100, new SecureRandom()); Set<Integer> seen = new HashSet<>(); for (int i = 0; i < sample.size(); i++) { boolean repeated = !seen.add(i); assertFalse(repeated, i + " is present at least twice"); } }
@Test public void testSampleIndex_NonRepeating_BetweenRuns() { Random random = new SecureRandom(); IntSeries s1 = Sampler.sampleIndex(5, 100, random); IntSeries s2 = Sampler.sampleIndex(5, 100, random); boolean hasDifferences = false; for (int i = 0; i < 5; i++) { if (s1.getInt(i) != s2.getInt(i)) { hasDifferences = true; break; } } assertTrue(hasDifferences); }
@Test public void testSampleIndex_ImplicitRandom_NonRepeating_BetweenRuns() { IntSeries s1 = Sampler.sampleIndex(5, 100); IntSeries s2 = Sampler.sampleIndex(5, 100); boolean hasDifferences = false; for (int i = 0; i < 5; i++) { if (s1.getInt(i) != s2.getInt(i)) { hasDifferences = true; break; } } assertTrue(hasDifferences); }