Commit 327a95b0 authored by Fabian Becker's avatar Fabian Becker

Tests for MaximumTimeTerminator

refs #61
parent 469e2033
......@@ -29,12 +29,12 @@ public class KnownOptimaFoundTerminator implements InterfaceTerminator, Serializ
}
@Override
public void initialize(InterfaceOptimizationProblem prob) {
public void initialize(InterfaceOptimizationProblem prob) throws IllegalArgumentException {
if (prob != null) {
if (prob instanceof InterfaceMultimodalProblemKnown) {
mProblem = (InterfaceMultimodalProblemKnown) prob;
} else {
LOGGER.log(Level.WARNING, "KnownOptimaFoundTerminator only works with InterfaceMultimodalProblemKnown instances!");
throw new IllegalArgumentException("KnownOptimaFoundTerminator only works with InterfaceMultimodalProblemKnown instances!");
}
} else {
LOGGER.log(Level.WARNING, "KnownOptimaFoundTerminator wont work with null problem!");
......
......@@ -722,9 +722,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
this.historyList.add((AbstractEAIndividual) this.getBestEAIndividual().clone());
}
if (isAutoAging()) {
for (AbstractEAIndividual individual : this) {
individual.incrAge();
}
this.forEach(AbstractEAIndividual::incrAge);
}
this.generationCount++;
firePropertyChangedEvent(NEXT_GENERATION_PERFORMED);
......
package eva2.optimization.operator.terminators;
import eva2.optimization.population.Population;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class MaximumTimeTerminatorTest {
MaximumTimeTerminator terminator;
@Before
public void setUp() throws Exception {
terminator = new MaximumTimeTerminator();
terminator.setMaximumTime(1);
}
@Test(timeout = 2500)
public void testIsTerminated() throws Exception {
terminator.initialize(null);
while(!terminator.isTerminated(new Population()));
}
@Test
public void testLastTerminationMessage() throws Exception {
assertNotNull(terminator.lastTerminationMessage());
}
@Test
public void testInitialize() throws Exception {
terminator.initialize(null);
// Should not be terminated after reinitialization
assertFalse(terminator.isTerminated(new Population()));
}
@Test
public void testToString() throws Exception {
assertNotNull(terminator.toString());
}
@Test
public void testGetMaximumTime() throws Exception {
assertEquals(1, terminator.getMaximumTime());
}
@Test
public void testSetMaximumTime() throws Exception {
terminator.setMaximumTime(10);
assertEquals(10, terminator.getMaximumTime());
}
}
\ 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