ListPopulation implements Population { public void setPopulationLimit(final int populationLimit) throws NotPositiveException, NumberIsTooSmallException { if (populationLimit <= 0) { throw new NotPositiveException(LocalizedFormats.POPULATION_LIMIT_NOT_POSITIVE, populationLimit); } if (populationLimit < chromosomes.size()) { throw new NumberIsTooSmallException(populationLimit, chromosomes.size(), true); } this.populationLimit = populationLimit; } ListPopulation(final int populationLimit);  ListPopulation(final List<Chromosome> chromosomes, final int populationLimit); @Deprecated void setChromosomes(final List<Chromosome> chromosomes); void addChromosomes(final Collection<Chromosome> chromosomeColl); List<Chromosome> getChromosomes(); void addChromosome(final Chromosome chromosome); Chromosome getFittestChromosome(); int getPopulationLimit(); void setPopulationLimit(final int populationLimit); int getPopulationSize(); @Override String toString(); Iterator<Chromosome> iterator();  }
@Test(expected = NotPositiveException.class) public void testSetPopulationLimit() { final ListPopulation population = new ListPopulation(10) { public Population nextGeneration() { return null; } }; population.setPopulationLimit(-50); }
@Test(expected=NumberIsTooSmallException.class) public void testSetPopulationLimitTooSmall() { final ArrayList<Chromosome> chromosomes = new ArrayList<Chromosome> (); chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3))); chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3))); chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3))); final ListPopulation population = new ListPopulation(chromosomes, 3) { public Population nextGeneration() { return null; } }; population.setPopulationLimit(2); }