Skip to content

Commit

Permalink
add tests to ensure reproducibility
Browse files Browse the repository at this point in the history
  • Loading branch information
oblonski committed Apr 24, 2015
1 parent 4757753 commit 5f0fee3
Show file tree
Hide file tree
Showing 3 changed files with 387 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
******************************************************************************/
package jsprit.core.algorithm;

import jsprit.core.algorithm.acceptor.SolutionAcceptor;
import jsprit.core.algorithm.selector.SolutionSelector;
import jsprit.core.problem.solution.SolutionCostCalculator;
import jsprit.core.util.RandomNumberGeneration;
import org.junit.Assert;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import static org.hamcrest.CoreMatchers.is;
Expand Down Expand Up @@ -192,4 +199,33 @@ public void whenRandomIsNull_throwException(){
managerUnderTest.getRandomStrategy();

}

@Test
public void strategyDrawShouldBeReproducible(){
SearchStrategyManager managerUnderTest = new SearchStrategyManager();
SearchStrategy mockedStrategy1 = new SearchStrategy("strat1"
,mock(SolutionSelector.class),mock(SolutionAcceptor.class),mock(SolutionCostCalculator.class));
SearchStrategy mockedStrategy2 = new SearchStrategy("strat2"
,mock(SolutionSelector.class),mock(SolutionAcceptor.class),mock(SolutionCostCalculator.class));

managerUnderTest.addStrategy(mockedStrategy1, 0.2);
managerUnderTest.addStrategy(mockedStrategy2, 0.8);
List<String> firstRecord = new ArrayList<String>();
for(int i=0; i<1000;i++){
firstRecord.add(managerUnderTest.getRandomStrategy().getId());
}

RandomNumberGeneration.reset();
List<String> secondRecord = new ArrayList<String>();
for(int i=0; i<1000;i++){
secondRecord.add(managerUnderTest.getRandomStrategy().getId());
}

for(int i=0;i<1000;i++){
if(!firstRecord.get(i).equals(secondRecord.get(i))){
Assert.assertFalse(true);
}
}
Assert.assertTrue(true);
}
}
Loading

0 comments on commit 5f0fee3

Please sign in to comment.