Commit 49edda55 authored by Fabian Becker's avatar Fabian Becker

Add basic test for ESIndividualPermutationData

refs #53
parent 2d765445
......@@ -237,10 +237,6 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
this.firstindex = firstindex;
}
/************************************************************************************
* AbstractEAIndividual methods
*/
/**
* This method will initialize the individual with a given value for the
* phenotype.
......@@ -305,7 +301,7 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
}
public double[] mapMatrixToVector(double[][] matrix) {
public static double[] mapMatrixToVector(double[][] matrix) {
int sumentries = 0;
for (int i = 0; i < matrix.length; i++) {
sumentries += matrix[i].length;
......@@ -321,7 +317,7 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
return res;
}
public double[][] mapVectorToMatrix(double[] vector, int[] sizes) {
public static double[][] mapVectorToMatrix(double[] vector, int[] sizes) {
double[][] matrix = new double[sizes.length][];
int counter = 0;
for (int i = 0; i < sizes.length; i++) {
......@@ -353,8 +349,6 @@ public class ESIndividualPermutationData extends AbstractEAIndividual implements
}
}
}
}
/**
......
package eva2.optimization.individuals;
import org.junit.Test;
import static org.junit.Assert.*;
public class ESIndividualPermutationDataTest {
@Test
public void testMapXToY() throws Exception {
double[][] matrix = new double[][]{
{1.2, 2.3, 3.4, 1.2},
{0.2, 0.3, 0.4}
};
// Properly constructs vector from matrix
assertArrayEquals(
new double[]{1.2, 2.3, 3.4, 1.2, 0.2, 0.3, 0.4},
ESIndividualPermutationData.mapMatrixToVector(matrix), 0.0
);
// Properly converts to vector and back to matrix
assertArrayEquals(
matrix,
ESIndividualPermutationData.mapVectorToMatrix(
ESIndividualPermutationData.mapMatrixToVector(matrix), new int[]{4,3}
)
);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment