RouletteWheel extends SelectionOperation implements Stochastic { protected void spinRoulette(List<Individual> operands) { double prob; Individual selected; this.selectedPopulation.clear(); while(this.selectedPopulation.size()<super.getSize()) { prob = rng.nextDouble(); int cnt = 0; while(cnt < operands.size() && this.accProbs[cnt] < prob) { cnt++; } if(cnt >= operands.size()) { cnt = operands.size() - 1; } selected = operands.get(cnt); this.selectedPopulation.add(selected.clone()); } } RouletteWheel(int size, RandomNumberGenerator rng);  RouletteWheel(); @Override void setProperties(Properties p); @Override void doOperation(Individual operand); void doOperation(List<Individual> operands); void rankPopulation(List<Individual> operands); RandomNumberGenerator getRNG(); void setRNG(RandomNumberGenerator m);  }
@Test public void testSpinRoulette() { System.out.println("spinRoulette"); RouletteWheel instance = new RouletteWheelMock(15,rng); instance.calculateAccumulatedFitnessProbabilities(individuals); instance.spinRoulette(individuals); int result = instance.selectedPopulation.size(); assertEquals(15, result); }