SimpleBinaryRepresentation implements GenotypeRepresentation { protected void integerToBinary(double[] intValues){ int maxIndex = -1; int minIndex; double currentValue; double newValue; for (int variableIdx = 0; variableIdx < intValues.length; variableIdx++){ currentValue = intValues[variableIdx]; minIndex = maxIndex; maxIndex += this.descriptor.getVariablesLengths()[variableIdx]; for (int genomeIdx = maxIndex; genomeIdx > minIndex; genomeIdx--){ newValue = Math.floor(currentValue / 2.0); this.genome[genomeIdx] = ( (currentValue - newValue * 2.0) > 0.5); currentValue = newValue; } } encodeBinaryGenome(); } SimpleBinaryRepresentation(SimpleBinaryGenomeDescriptor descriptor);  SimpleBinaryRepresentation(SimpleBinaryRepresentation second); int getTotalLength(); int[] getValueLengths(); boolean getGeneAt(int idx); void setGeneAt(int idx, boolean value); void invertGeneAt(int idx); void swapGenes(GenotypeRepresentation secondRepresentation, int[] positions); void swapGenes(GenotypeRepresentation secondRepresentation, int from, int to); void receiveGenes(GenotypeRepresentation secondRepresentation, int[] positions); void receiveGenes(GenotypeRepresentation secondRepresentation, int from, int to); void andGenes(GenotypeRepresentation secondRepresentation, int[] positions); void andGenes(GenotypeRepresentation secondRepresentation, int from, int to); void orGenes(GenotypeRepresentation secondRepresentation, int[] positions); void orGenes(GenotypeRepresentation secondRepresentation, int from, int to); void xorGenes(GenotypeRepresentation secondRepresentation, int[] positions); void xorGenes(GenotypeRepresentation secondRepresentation, int from, int to); double[] getDoubleValue(); void setDoubleValue(double[] phenotypeValue); Representation copy();  }
@Test public void testIntegerToBinary1(){ this.representation.genome = new boolean[MathUtils.sumSizes(this.descriptor.variablesLengths)]; this.representation.integerToBinary(new double[] {23, 2, 31, 500}); boolean[] expected = new boolean[]{ false, true, false, true, true, true, true, false, true, true, true, true, true, true, true, true, true, false, true, false, false }; assertEquals(MathUtils.sumSizes(this.descriptor.variablesLengths), this.representation.genome.length); assertEquals(this.representation.genome.length, expected.length); for (int i = 0; i < expected.length; i++){ assertEquals(expected[i], this.representation.genome[i]); } }