Chromosome implements Comparable<Chromosome>,Fitness { protected Chromosome findSameChromosome(final Population population) { for (Chromosome anotherChr : population) { if (this.isSame(anotherChr)) { return anotherChr; } } return null; }  double getFitness(); int compareTo(final Chromosome another); void searchForFitnessUpdate(final Population population);  }
@Test public void testFindSameChromosome() { Chromosome c1 = new DummyChromosome(1) { public double fitness() { return 1; } }; Chromosome c2 = new DummyChromosome(2) { public double fitness() { return 2; } }; Chromosome c3 = new DummyChromosome(3) { public double fitness() { return 3; } }; Chromosome c4 = new DummyChromosome(1) { public double fitness() { return 5; } }; Chromosome c5 = new DummyChromosome(15) { public double fitness() { return 15; } }; List<Chromosome> popChr = new ArrayList<Chromosome>(); popChr.add(c1); popChr.add(c2); popChr.add(c3); Population pop = new ListPopulation(popChr,3) { public Population nextGeneration() { return null; } }; Assert.assertNull(c5.findSameChromosome(pop)); Assert.assertEquals(c1, c4.findSameChromosome(pop)); c4.searchForFitnessUpdate(pop); Assert.assertEquals(1, c4.getFitness(),0); }