@Test public void testThresholdWorks() { for (int i = 0; i <= 100; i++) { expect(random.nextDouble()).andReturn(0.01 * i); } control.replay(); Sampler sampler = new Sampler(25, random); for (int i = 0; i <= 100; i++) { assertThat(sampler.select(), is(i < 25)); } }
public boolean select() { return rand.nextDouble() < threshold; }
Sampler { public boolean select() { return rand.nextDouble() < threshold; } }
Sampler { public boolean select() { return rand.nextDouble() < threshold; } Sampler(float selectPercent);  Sampler(float selectPercent, Random rand); }
Sampler { public boolean select() { return rand.nextDouble() < threshold; } Sampler(float selectPercent);  Sampler(float selectPercent, Random rand); boolean select(); }
Sampler { public boolean select() { return rand.nextDouble() < threshold; } Sampler(float selectPercent);  Sampler(float selectPercent, Random rand); boolean select();  }