From 2a94626710ee657d04c0294f8a4e4e09259235ee Mon Sep 17 00:00:00 2001 From: oblonski <4sschroeder@gmail.com> Date: Sat, 15 Feb 2014 08:53:35 +0100 Subject: [PATCH] add test --- .../VehicleRoutingAlgorithmTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 jsprit-core/src/test/java/jsprit/core/algorithm/VehicleRoutingAlgorithmTest.java diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/VehicleRoutingAlgorithmTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/VehicleRoutingAlgorithmTest.java new file mode 100644 index 00000000..c8b8b2cd --- /dev/null +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/VehicleRoutingAlgorithmTest.java @@ -0,0 +1,50 @@ +package jsprit.core.algorithm; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; + +import java.util.Collection; + +import jsprit.core.algorithm.listener.IterationStartsListener; +import jsprit.core.problem.VehicleRoutingProblem; +import jsprit.core.problem.solution.VehicleRoutingProblemSolution; + +import org.junit.Test; + +public class VehicleRoutingAlgorithmTest { + + @Test + public void whenSettingIterations_itIsSetCorrectly(){ + VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(mock(VehicleRoutingProblem.class), + mock(SearchStrategyManager.class)); + algorithm.setNuOfIterations(50); + assertEquals(50,algorithm.getNuOfIterations()); + } + + private static class CountIterations implements IterationStartsListener { + + private int countIterations = 0; + + @Override + public void informIterationStarts(int i, VehicleRoutingProblem problem,Collection solutions) { + countIterations++; + } + + public int getCountIterations() { + return countIterations; + } + + } + + @Test + public void whenSettingIterations_iterAreExecutedCorrectly(){ + VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(mock(VehicleRoutingProblem.class), + mock(SearchStrategyManager.class)); + algorithm.setNuOfIterations(100); + CountIterations counter = new CountIterations(); + algorithm.addListener(counter); + algorithm.searchSolutions(); + assertEquals(100,counter.getCountIterations()); + } + +}