mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
clean, test and document core.algorithm.termination.IterationWithoutImprovementTermination
This commit is contained in:
parent
b3dd790be2
commit
dce8019b80
2 changed files with 82 additions and 10 deletions
|
|
@ -0,0 +1,61 @@
|
|||
package jsprit.core.algorithm.termination;
|
||||
|
||||
|
||||
import jsprit.core.algorithm.SearchStrategy;
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IterationsWithoutImprovementTest {
|
||||
|
||||
@Test
|
||||
public void itShouldTerminateAfter100(){
|
||||
IterationWithoutImprovementTermination termination = new IterationWithoutImprovementTermination(100);
|
||||
SearchStrategy.DiscoveredSolution discoveredSolution = mock(SearchStrategy.DiscoveredSolution.class);
|
||||
when(discoveredSolution.isAccepted()).thenReturn(false);
|
||||
int terminatedAfter = 0;
|
||||
for(int i=0;i<200;i++){
|
||||
boolean terminate = termination.isPrematureBreak(discoveredSolution);
|
||||
if(terminate) {
|
||||
terminatedAfter = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.assertEquals(100,terminatedAfter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itShouldTerminateAfter1(){
|
||||
IterationWithoutImprovementTermination termination = new IterationWithoutImprovementTermination(1);
|
||||
SearchStrategy.DiscoveredSolution discoveredSolution = mock(SearchStrategy.DiscoveredSolution.class);
|
||||
when(discoveredSolution.isAccepted()).thenReturn(false);
|
||||
int terminatedAfter = 0;
|
||||
for(int i=0;i<200;i++){
|
||||
boolean terminate = termination.isPrematureBreak(discoveredSolution);
|
||||
if(terminate) {
|
||||
terminatedAfter = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.assertEquals(1,terminatedAfter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itShouldTerminateAfter150(){
|
||||
IterationWithoutImprovementTermination termination = new IterationWithoutImprovementTermination(100);
|
||||
SearchStrategy.DiscoveredSolution discoveredSolution = mock(SearchStrategy.DiscoveredSolution.class);
|
||||
int terminatedAfter = 0;
|
||||
for(int i=0;i<200;i++){
|
||||
when(discoveredSolution.isAccepted()).thenReturn(false);
|
||||
if(i == 49) when(discoveredSolution.isAccepted()).thenReturn(true);
|
||||
boolean terminate = termination.isPrematureBreak(discoveredSolution);
|
||||
if(terminate) {
|
||||
terminatedAfter = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.assertEquals(150,terminatedAfter);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue