SimpleGrayCodeBinaryRepresentation extends SimpleBinaryRepresentation { @Override protected void encodeBinaryGenome() { boolean[] grayGenome = new boolean[this.genome.length]; int index = 0; for (int variable = 0; variable < this.descriptor.numVariables; variable++){ grayGenome[index] = this.genome[index++]; for (int i = 1; i < this.descriptor.variablesLengths[variable]; i++){ grayGenome[index] = this.genome[index-1] ^ this.genome[index++]; } } this.genome = grayGenome; } SimpleGrayCodeBinaryRepresentation(SimpleBinaryGenomeDescriptor descriptor);  SimpleGrayCodeBinaryRepresentation(SimpleGrayCodeBinaryRepresentation second); @Override Representation copy();  }
@Test public void testEncodeBinaryGenome1(){ 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 }; this.representation.genome = binary; 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 }; this.representation.encodeBinaryGenome(); boolean[] result = this.representation.genome; assertEquals((6+2+4+10), result.length); assertEquals(binary.length, result.length); assertEquals(binary.length, gray.length); for (int i = 0; i < binary.length; i++){ Assert.assertEquals("in step " + i, gray[i], result[i]); } }