### Question:
GeometricDistribution { int sample(double p, SourceOfRandomness random) { ensureProbability(p); if (p == 1) return 0; double uniform = random.nextDouble(); return (int) ceil(log(1 - uniform) / log(1 - p)); }  int sampleWithMean(double mean, SourceOfRandomness random);  }### Answer:
@Test public void negativeProbability() { thrown.expect(IllegalArgumentException.class); distro.sample(-ulp(0), random); }
@Test public void zeroProbability() { thrown.expect(IllegalArgumentException.class); distro.sample(0, random); }
@Test public void greaterThanOneProbability() { thrown.expect(IllegalArgumentException.class); distro.sample(1 + ulp(1), random); }
@Test public void sampleWithCertainProbability() { assertEquals(0, distro.sample(1, random)); }
@Test public void sampleWithNonCertainProbability() { when(random.nextDouble()).thenReturn(0.88); assertEquals(10, distro.sample(0.2, random)); }