From f58f6e867baac885c5dec7bdd7a619c4eaa29ea2 Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Fri, 11 Dec 2015 19:23:45 +0100 Subject: [PATCH] Some basic tests for Population refs #53 --- .../optimization/population/Population.java | 8 +- .../population/PopulationTest.java | 356 ++++++++++++++++++ 2 files changed, 360 insertions(+), 4 deletions(-) create mode 100644 src/test/java/eva2/optimization/population/PopulationTest.java diff --git a/src/main/java/eva2/optimization/population/Population.java b/src/main/java/eva2/optimization/population/Population.java index 9ae123a2..90f8b9a4 100644 --- a/src/main/java/eva2/optimization/population/Population.java +++ b/src/main/java/eva2/optimization/population/Population.java @@ -163,7 +163,6 @@ public class Population extends ArrayList implements Popul } Population sols = allSolutions.getSolutions(); for (int i = 0; i < sols.size(); i++) { -// addPopulation(allSolutions.getSolutions()); if (!checkCols.containsKey(sols.getEAIndividual(i).getIndyID())) { add(sols.getEAIndividual(i)); } @@ -1850,7 +1849,8 @@ public class Population extends ArrayList implements Popul /** * Returns the average, minimal and maximal individual distance as diversity * measure for the population. If the given metric argument is null, the - * euclidian distance of individual positions is used, which presumes that {@link eva2.optimization.individuals.AbstractEAIndividual#getDoublePosition(eva2.optimization.individuals.AbstractEAIndividual)} + * euclidean distance of individual positions is used, which presumes that + * {@link AbstractEAIndividual#getDoublePosition(AbstractEAIndividual)} * returns a valid double position for the individuals of the population. * This is of course rather expensive computationally. * @@ -1858,7 +1858,6 @@ public class Population extends ArrayList implements Popul * an array of three */ public double[] getPopulationMeasures(InterfaceDistanceMetric metric) { - double[] res = getPopulationMeasures(this, metric); return res; } @@ -1866,7 +1865,8 @@ public class Population extends ArrayList implements Popul /** * Returns the average, minimal and maximal individual distance as diversity * measure for the population. If the given metric argument is null, the - * euclidian distance of individual positions is used, which presumes that {@link AbstractEAIndividual#getDoublePosition(eva2.optimization.individuals.AbstractEAIndividual)} + * euclidean distance of individual positions is used, which presumes that + * {@link AbstractEAIndividual#getDoublePosition(AbstractEAIndividual)} * returns a valid double position for the individuals of the population. * This is of course rather expensive computationally. * diff --git a/src/test/java/eva2/optimization/population/PopulationTest.java b/src/test/java/eva2/optimization/population/PopulationTest.java new file mode 100644 index 00000000..488859d2 --- /dev/null +++ b/src/test/java/eva2/optimization/population/PopulationTest.java @@ -0,0 +1,356 @@ +package eva2.optimization.population; + +import eva2.optimization.individuals.ESIndividualDoubleData; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; + +public class PopulationTest { + Population emptyPopulation; + + @Before + public void setUp() throws Exception { + emptyPopulation = new Population(10); + } + + @Test + public void testEquals() throws Exception { + + } + + @Test + public void testPutData() throws Exception { + + } + + @Test + public void testGetData() throws Exception { + + } + + @Test + public void testHasData() throws Exception { + + } + + @Test + public void testResetProperties() throws Exception { + + } + + @Test + public void testGetInitPos() throws Exception { + + } + + @Test + public void testSetInitPos() throws Exception { + + } + + @Test + public void testSetInitAround() throws Exception { + + } + + @Test + public void testGetInitAround() throws Exception { + + } + + @Test + public void testFill() throws Exception { + assertEquals(0, emptyPopulation.size()); + + emptyPopulation.fill(new ESIndividualDoubleData()); + + // Should be filled with 10 individuals + assertEquals(10, emptyPopulation.getTargetSize()); + } + + @Test + public void testSetUseHistory() throws Exception { + + } + + @Test + public void testIsUsingHistory() throws Exception { + + } + + @Test + public void testSetAutoAging() throws Exception { + + } + + @Test + public void testIsAutoAging() throws Exception { + + } + + @Test + public void testSetMaxHistoryLength() throws Exception { + + } + + @Test + public void testGetMaxHistLength() throws Exception { + + } + + @Test + public void testGetHistoryLength() throws Exception { + + } + + @Test + public void testGetHistory() throws Exception { + + } + + @Test + public void testSetHistory() throws Exception { + + } + + @Test + public void testIncrFunctionCalls() throws Exception { + int currentFunctionCalls = emptyPopulation.getFunctionCalls(); + emptyPopulation.incrFunctionCalls(); + assertEquals(currentFunctionCalls + 1, emptyPopulation.getFunctionCalls()); + } + + @Test + public void testIncrFunctionCallsBy() throws Exception { + int currentFunctionCalls = emptyPopulation.getFunctionCalls(); + emptyPopulation.incrFunctionCallsBy(150); + assertEquals(currentFunctionCalls + 150, emptyPopulation.getFunctionCalls()); + } + + @Test + public void testGetFunctionCalls() throws Exception { + // New and empty population has 0 function calls + assertEquals(0, this.emptyPopulation.getFunctionCalls()); + } + + @Test + public void testSetFunctionCalls() throws Exception { + emptyPopulation.setFunctionCalls(150); + assertEquals(150, emptyPopulation.getFunctionCalls()); + } + + @Test + public void testSetAllFitnessValues() throws Exception { + + } + + @Test + public void testIncrGeneration() throws Exception { + int currentGeneration = emptyPopulation.getGeneration(); + emptyPopulation.incrGeneration(); + + assertEquals(currentGeneration + 1, emptyPopulation.getGeneration()); + } + + @Test + public void testGetGeneration() throws Exception { + // New population has generation 0 + assertEquals(0, emptyPopulation.getGeneration()); + } + + @Test + public void testSetGeneration() throws Exception { + emptyPopulation.setGeneration(10); + assertEquals(10, emptyPopulation.getGeneration()); + } + + @Test + public void testAddPopulation() throws Exception { + + } + + @Test + public void testAddPopulation1() throws Exception { + + } + + @Test + public void testResetFitness() throws Exception { + + } + + @Test + public void testGetDominatingSet() throws Exception { + + } + + @Test + public void testGetDominatingSet1() throws Exception { + + } + + @Test + public void testGetIndexOfBestIndividualPrefFeasible() throws Exception { + + } + + @Test + public void testGetIndexOfWorstIndividualNoConstr() throws Exception { + + } + + @Test + public void testGetIndexOfBestIndividualPrefFeasible1() throws Exception { + + } + + @Test + public void testGetIndexOfWorstIndividualNoConstr1() throws Exception { + + } + + @Test + public void testMoveNInds() throws Exception { + + } + + @Test + public void testMoveRandIndFromTo() throws Exception { + + } + + @Test + public void testGetSpecificData() throws Exception { + + } + + @Test + public void testGetSpecificDataNames() throws Exception { + + } + + @Test + public void testGetIDList() throws Exception { + + } + + @Test + public void testGetIndyList() throws Exception { + + } + + @Test + public void testSetTargetSize() throws Exception { + + } + + @Test + public void testSetTargetPopSize() throws Exception { + + } + + @Test + public void testGetBestIndividual() throws Exception { + + } + + @Test + public void testGetWorstIndividual() throws Exception { + + } + + @Test + public void testGetBestFitness() throws Exception { + + } + + @Test + public void testGetWorstFitness() throws Exception { + + } + + @Test + public void testGetMeanFitness() throws Exception { + + } + + @Test + public void testGetPopulationMeasures() throws Exception { + + } + + @Test + public void testGetCorrelations() throws Exception { + + } + + @Test + public void testGetCorrelations1() throws Exception { + + } + + @Test + public void testGetFitnessMeasures() throws Exception { + + } + + @Test + public void testGetCenter() throws Exception { + + } + + @Test + public void testGetCenterIndy() throws Exception { + + } + + @Test + public void testGetCenterWeighted() throws Exception { + + } + + @Test + public void testGetNeighborIndex() throws Exception { + + } + + @Test + public void testGetFitSum() throws Exception { + + } + + @Test + public void testUpdateRange() throws Exception { + + } + + @Test + public void testTargetSizeReached() throws Exception { + + } + + @Test + public void testTargetSizeExceeded() throws Exception { + + } + + @Test + public void testGetFreeSlots() throws Exception { + + } + + @Test + public void testClearHistory() throws Exception { + + } + + @Test + public void testCheckNoNullIndy() throws Exception { + + } + + @Test + public void testFilterByFitness() throws Exception { + + } +} \ No newline at end of file