SimpleBinaryRepresentation implements GenotypeRepresentation { protected double[] binaryToInteger(){ double[] intValues = new double[this.descriptor.getNumVariables()]; boolean[] decodedGenome = this.decodeGenomeToBinary(); int index = MathUtils.sumSizes(this.descriptor.variablesLengths) - 1; double intValue; double power; for (int variable = intValues.length - 1; variable >= 0 ; variable--){ intValue = 0.0; power = 1.0; for (int gene = 0; gene < this.descriptor.getVariablesLengths()[variable]; gene++){ intValue += (decodedGenome[index--]?power:0); power *= 2; } intValues[variable] = Math.ceil(intValue); } return intValues; } 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 testBinaryToInteger1(){ this.representation.genome = new boolean[]{ false, true, false, true, true, true, true, false, true, true, true, true, true, true, true, true, true, false, true, false, false }; double[] expected = new double[] {23, 2, 15, 500}; double[] result = this.representation.binaryToInteger(); assertEquals(MathUtils.sumSizes(this.descriptor.variablesLengths), this.representation.genome.length); assertEquals(expected.length, result.length); Assert.assertArrayEquals(expected, result, 0.0); }