1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

break feature

This commit is contained in:
oblonski 2015-09-23 18:19:32 +02:00
parent a55ea8f3cf
commit 1919c05ceb
6 changed files with 34 additions and 247 deletions

View file

@ -37,191 +37,6 @@ public class VehicleImplTest {
Vehicle v = VehicleImpl.Builder.newInstance("v").build();
}
@Test
public void whenVehicleIsBuiltToReturnToDepot_itShouldReturnToDepot(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setReturnToDepot(true).setStartLocation(Location.newInstance("loc")).build();
assertTrue(v.isReturnToDepot());
}
@Test
public void whenVehicleIsBuiltToNotReturnToDepot_itShouldNotReturnToDepot(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setReturnToDepot(false).setStartLocation(Location.newInstance("loc")).build();
assertFalse(v.isReturnToDepot());
}
@Test
public void whenVehicleIsBuiltWithLocation_itShouldHvTheCorrectLocation(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build();
assertEquals("loc",v.getStartLocation().getId());
}
@Test
public void whenVehicleIsBuiltWithCoord_itShouldHvTheCorrectCoord(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1, 2)).build();
assertEquals(1.0,v.getStartLocation().getCoordinate().getX(),0.01);
assertEquals(2.0,v.getStartLocation().getCoordinate().getY(),0.01);
}
@Test
public void whenVehicleIsBuiltAndEarliestStartIsNotSet_itShouldSetTheDefaultOfZero(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1, 2)).build();
assertEquals(0.0,v.getEarliestDeparture(),0.01);
}
@Test
public void whenVehicleIsBuiltAndEarliestStartSet_itShouldBeSetCorrectly(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setEarliestStart(10.0).setStartLocation(Location.newInstance(1, 2)).build();
assertEquals(10.0,v.getEarliestDeparture(),0.01);
}
@Test
public void whenVehicleIsBuiltAndLatestArrivalIsNotSet_itShouldSetDefaultOfDoubleMaxValue(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1, 2)).build();
assertEquals(Double.MAX_VALUE,v.getLatestArrival(),0.01);
}
@Test
public void whenVehicleIsBuiltAndLatestArrivalIsSet_itShouldBeSetCorrectly(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setLatestArrival(30.0).setStartLocation(Location.newInstance(1, 2)).build();
assertEquals(30.0,v.getLatestArrival(),0.01);
}
@Test
public void whenNoVehicleIsCreate_itShouldHvTheCorrectId(){
Vehicle v = VehicleImpl.createNoVehicle();
assertEquals("noVehicle",v.getId());
}
@Test
public void whenStartLocationIsSet_itIsDoneCorrectly(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).build();
assertEquals("startLoc", v.getStartLocation().getId());
}
@Test(expected=IllegalStateException.class)
public void whenStartLocationIsNull_itThrowsException(){
@SuppressWarnings("unused")
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(null)).build();
}
@Test
public void whenStartLocationCoordIsSet_itIsDoneCorrectly(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1, 2)).build();
assertEquals(1.0, v.getStartLocation().getCoordinate().getX(),0.01);
assertEquals(2.0, v.getStartLocation().getCoordinate().getY(),0.01);
}
@Test
public void whenEndLocationIsSet_itIsDoneCorrectly(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).setEndLocation(Location.newInstance("endLoc")).build();
assertEquals("startLoc", v.getStartLocation().getId());
assertEquals("endLoc", v.getEndLocation().getId());
}
@Test
public void whenEndLocationCoordIsSet_itIsDoneCorrectly(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).setEndLocation(Location.newInstance(1, 2)).build();
assertEquals(1.0, v.getEndLocation().getCoordinate().getX(),0.01);
assertEquals(2.0, v.getEndLocation().getCoordinate().getY(),0.01);
}
@Test
public void whenNeitherEndLocationIdNorEndLocationCoordAreSet_endLocationIdMustBeEqualToStartLocationId(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).build();
assertEquals("startLoc", v.getEndLocation().getId());
}
@Test
public void whenNeitherEndLocationIdNorEndLocationCoordAreSet_endLocationCoordMustBeEqualToStartLocationCoord(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).build();
assertEquals(v.getEndLocation().getCoordinate(), v.getStartLocation().getCoordinate());
}
@Test
public void whenNeitherEndLocationIdNorEndLocationCoordAreSet_endLocationCoordMustBeEqualToStartLocationCoordV2(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).build();
assertEquals(v.getEndLocation().getCoordinate(), v.getStartLocation().getCoordinate());
}
@Test
public void whenEndLocationCoordinateIsSetButNoId_idMustBeCoordToString(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance(3.0, 4.0)).build();
assertEquals(v.getEndLocation().getCoordinate().toString(), v.getEndLocation().getId());
}
@Test(expected=IllegalStateException.class)
public void whenEndLocationIdIsSpecifiedANDReturnToDepotIsFalse_itShouldThrowException(){
@SuppressWarnings("unused")
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance("endLoc")).setReturnToDepot(false).build();
}
@Test(expected=IllegalStateException.class)
public void whenEndLocationCoordIsSpecifiedANDReturnToDepotIsFalse_itShouldThrowException(){
@SuppressWarnings("unused")
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance(3, 4)).setReturnToDepot(false).build();
}
@Test
public void whenEndLocationCoordIsNotSpecifiedANDReturnToDepotIsFalse_endLocationCoordMustBeStartLocationCoord(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setReturnToDepot(false).build();
assertEquals(v.getStartLocation().getCoordinate(),v.getEndLocation().getCoordinate());
}
@Test
public void whenEndLocationIdIsNotSpecifiedANDReturnToDepotIsFalse_endLocationIdMustBeStartLocationId(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setReturnToDepot(false).build();
assertEquals(v.getStartLocation().getCoordinate().toString(),v.getEndLocation().getId());
}
@Test(expected=IllegalStateException.class)
public void whenStartAndEndAreUnequalANDReturnToDepotIsFalse_itShouldThrowException(){
@SuppressWarnings("unused")
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).setReturnToDepot(false).build();
}
@Test
public void whenStartAndEndAreEqualANDReturnToDepotIsFalse_itShouldThrowException(){
@SuppressWarnings("unused")
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("start")).setReturnToDepot(false).build();
assertTrue(true);
}
@Test
public void whenTwoVehiclesHaveTheSameId_theyShouldBeEqual(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("start")).setReturnToDepot(false).build();
Vehicle v2 = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("start")).setReturnToDepot(false).build();
assertTrue(v.equals(v2));
}
@Test
public void whenAddingSkills_theyShouldBeAddedCorrectly(){
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
.addSkill("drill").addSkill("screwdriver").build();
assertTrue(v.getSkills().containsSkill("drill"));
assertTrue(v.getSkills().containsSkill("drill"));
assertTrue(v.getSkills().containsSkill("screwdriver"));
}
@Test
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
.addSkill("drill").addSkill("screwdriver").build();
assertTrue(v.getSkills().containsSkill("drill"));
assertTrue(v.getSkills().containsSkill("dRill"));
assertTrue(v.getSkills().containsSkill("ScrewDriver"));
}
@Test
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly(){
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
.addSkill("drill").build();
assertFalse(v.getSkills().containsSkill("ScrewDriver"));
}
@Test
public void whenAddingDriverBreak_itShouldBeAddedCorrectly(){