Population { public double getTotalFitness() { if (fitnessCalculatedFlags.cardinality() == chromosomes.length) { double totalFitness = 0.0; for (int i = 0; i < chromosomes.length; i++) totalFitness += chromosomes[i].getFitness(); return totalFitness; } return Double.NaN; } Population(int size); Chromosome getChromosome(int idx); double calculateFitnessForChromosome(int idx, Function<Chromosome, Double> fitnessFunction); void calculateFitnessForAll(Function<Chromosome, Double> fitnessFunction); void setChromosome(int idx, Chromosome chromosome); Chromosome getChromosome(Integer idx); Chromosome[] selectBestKChromosome(int k); double getTotalFitness(); double getAverageFitness(); int size(); void setFitness(Integer idx, Double fitness);  }
@Test public void getTotalFitness() { double res = population.getTotalFitness(); Assert.assertEquals(res, Double.NaN, PRECISION); population.calculateFitnessForAll(fitnessFunction); res = population.getTotalFitness(); Assert.assertEquals(res, 9900.0, PRECISION); }