### Question:
RouletteWheelSampler implements Sampler<T> { public T sample() { double r = rng.nextDouble(); for(Pair<T, Double> cumProbPair : wheel) if(r < cumProbPair.getValue()) return cumProbPair.getKey(); throw new IllegalStateException("Invalid state -- RouletteWheelSampler should never fail to sample!"); } RouletteWheelSampler(Map<T, Double> domainWeights, SeedFactory factory);  RouletteWheelSampler(Collection<T> data, ProbabilityDensityFunction<T> pdf, SeedFactory factory); static RouletteWheelSampler<T> create(Map<T, Double> domainWeights, SeedFactory factory); static RouletteWheelSampler<T> create(MultinomialPDF<T> pdf, SeedFactory factory); static RouletteWheelSampler<T> create(Collection<T> data, ProbabilityDensityFunction<T> pdf, SeedFactory factory); static RouletteWheelSampler<T> createUniform(Collection<T> data, SeedFactory factory); T sample();  }### Answer:
@Test public void testSample() throws Exception { Map<String, Double> dataPoints = ImmutableMap.of( "a", 0.25, "b", 0.25, "c", 0.25, "d", 0.25 ); SeedFactory seedFactory = new SeedFactory(1234); Sampler<String> sampler = new RouletteWheelSampler<String>(dataPoints, seedFactory); String result = sampler.sample(); assertThat(dataPoints.keySet(), hasItem(result)); }
@Test public void testSampleUnnormalized() throws Exception { Map<String, Double> dataPoints = ImmutableMap.of( "a", 1.0, "b", 1.0, "c", 1.0, "d", 1.0 ); SeedFactory seedFactory = new SeedFactory(1234); Sampler<String> sampler = new RouletteWheelSampler<String>(dataPoints, seedFactory); String result = sampler.sample(); assertThat(dataPoints.keySet(), hasItem(result)); }