mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
tested new methods .get/putProblemState
This commit is contained in:
parent
8c2e3ca210
commit
4e23697fc8
2 changed files with 32 additions and 1 deletions
|
|
@ -167,7 +167,8 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
||||||
}
|
}
|
||||||
|
|
||||||
<T> T getDefaultProblemState(StateId stateId, Class<T> type){
|
<T> T getDefaultProblemState(StateId stateId, Class<T> type){
|
||||||
return defaultProblemStates_.getState(stateId, type);
|
if(defaultProblemStates_.containsKey(stateId)) return defaultProblemStates_.getState(stateId, type);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -143,4 +143,34 @@ public class StateManagerTest {
|
||||||
Capacity getCap = stateManager.getActivityState(activity, id, Capacity.class);
|
Capacity getCap = stateManager.getActivityState(activity, id, Capacity.class);
|
||||||
assertEquals(500, getCap.get(0));
|
assertEquals(500, getCap.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenProblemStateIsSet_itMustBeSetCorrectly(){
|
||||||
|
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||||
|
StateId id = StateFactory.createId("problemState");
|
||||||
|
stateManager.putProblemState(id, Boolean.class, true);
|
||||||
|
boolean problemState = stateManager.getProblemState(id, Boolean.class);
|
||||||
|
assertTrue(problemState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=NullPointerException.class)
|
||||||
|
public void whenProblemStateIsSetAndStateManagerClearedAfterwards_itThrowsException(){
|
||||||
|
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||||
|
StateId id = StateFactory.createId("problemState");
|
||||||
|
stateManager.putProblemState(id, Boolean.class, true);
|
||||||
|
stateManager.clear();
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
boolean problemState = stateManager.getProblemState(id, Boolean.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenProblemStateIsSetAndStateManagerClearedAfterwards_itReturnsDefault(){
|
||||||
|
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||||
|
StateId id = StateFactory.createId("problemState");
|
||||||
|
stateManager.putDefaultProblemState(id, Boolean.class, false);
|
||||||
|
stateManager.putProblemState(id, Boolean.class, true);
|
||||||
|
stateManager.clear();
|
||||||
|
boolean problemState = stateManager.getProblemState(id, Boolean.class);
|
||||||
|
assertFalse(problemState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue