BitSetGrayCodeBinaryRepresentation extends BitSetBinaryRepresentation { @Override protected BitSet decodeGenomeToBinary() { BitSet binaryGenome = new BitSet(this.genomeLength); int index = 0; for (int variable = 0; variable < this.descriptor.numVariables; variable++){ binaryGenome.set(index, this.genome.get(index++)); for (int i = 1; i < this.descriptor.variablesLengths[variable]; i++){ binaryGenome.set(index, binaryGenome.get(index-1) ^ this.genome.get(index++)); } } return binaryGenome; } BitSetGrayCodeBinaryRepresentation(SimpleBinaryGenomeDescriptor descriptor);  BitSetGrayCodeBinaryRepresentation(BitSetGrayCodeBinaryRepresentation second); @Override Representation copy();  }
@Test public void testDecodeGenomeToBinary1(){ boolean[] gray = new boolean[]{ true, true, true, true, true, true, true, true, true, false, false, false, false, false, false, true, false, true, false, true, false, true }; assertEquals((6+2+4+10), gray.length); for (int idx = 0; idx < gray.length; idx++){ this.representation.setGeneAt(idx, gray[idx]); } assertEquals(gray.length, this.representation.genomeLength); BitSet result = this.representation.decodeGenomeToBinary(); assertTrue((6+2+4+10) >= result.length()); boolean[] binary = new boolean[]{ true, false, true, false, true, false, true, false, true, true, true, true, false, false, false, true, true, false, false, true, true, false }; assertTrue(binary.length >=result.length()); for (int i = 0; i < binary.length; i++){ Assert.assertEquals("in step " + i, binary[i], result.get(i) ); } }