BinaryChromosome extends AbstractListChromosome<Integer> { @Override protected boolean isSame(Chromosome another) { if (! (another instanceof BinaryChromosome)) { return false; } BinaryChromosome anotherBc = (BinaryChromosome) another; if (getLength() != anotherBc.getLength()) { return false; } for (int i=0; i< getRepresentation().size(); i++) { if (!(getRepresentation().get(i).equals(anotherBc.getRepresentation().get(i)))) { return false; } } return true; } BinaryChromosome(List<Integer> representation);  BinaryChromosome(Integer[] representation); static List<Integer> randomBinaryRepresentation(int length);  }
@Test public void testIsSame() { Chromosome c1 = new DummyBinaryChromosome(new Integer[] {0,1,0,1,0,1}); Chromosome c2 = new DummyBinaryChromosome(new Integer[] {0,1,1,0,1}); Chromosome c3 = new DummyBinaryChromosome(new Integer[] {0,1,0,1,0,1,1}); Chromosome c4 = new DummyBinaryChromosome(new Integer[] {1,1,0,1,0,1}); Chromosome c5 = new DummyBinaryChromosome(new Integer[] {0,1,0,1,0,0}); Chromosome c6 = new DummyBinaryChromosome(new Integer[] {0,1,0,1,0,1}); Assert.assertFalse(c1.isSame(c2)); Assert.assertFalse(c1.isSame(c3)); Assert.assertFalse(c1.isSame(c4)); Assert.assertFalse(c1.isSame(c5)); Assert.assertTrue(c1.isSame(c6)); }