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

generated hashcode and equals in core.problem.vehicle.VehicleImpl such

that two vehicles are equal if they have the same id and if their types
are equal
This commit is contained in:
Stefan Schroeder 2014-06-26 10:58:42 +02:00
parent 2a36ed42cf
commit be5918a67d
3 changed files with 74 additions and 2 deletions

View file

@ -171,5 +171,21 @@ public class VehicleImplTest {
assertTrue(true);
}
@Test
public void whenTwoVehiclesHaveTheSameId_theyShouldBeEqual(){
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("start").setReturnToDepot(false).build();
Vehicle v2 = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("start").setReturnToDepot(false).build();
assertTrue(v.equals(v2));
}
@Test
public void whenTwoVehiclesHaveTheSameIdButDiffType_theyShouldNotBeEqual(){
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setType(type1).setEndLocationId("start").setReturnToDepot(false).build();
PenaltyVehicleType penType = new PenaltyVehicleType(type1);
Vehicle v2 = VehicleImpl.Builder.newInstance("v").setType(penType).setStartLocationId("start").setEndLocationId("start").setReturnToDepot(false).build();
assertTrue(!v.equals(v2));
}
}

View file

@ -115,9 +115,25 @@ public class VehicleTypeImplTest {
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(-10).build();
}
@Test
public void whenSettingPerTimeCosts_itShouldBeSetCorrectly(){
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(10).build();
assertEquals(10.0, type.getVehicleCostParams().perDistanceUnit,0.0);
assertEquals(10.0, type.getVehicleCostParams().perTimeUnit,0.0);
}
@Test
public void whenHavingTwoTypesWithTheSameId_theyShouldBeEqual(){
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(10).build();
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(10).build();
assertTrue(type.equals(type2));
}
@Test
public void whenHavingTwoTypesWithTheSameIdButDiffClass_theyShouldNotBeEqual(){
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(10).build();
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(10).build();
PenaltyVehicleType penType = new PenaltyVehicleType(type2);
assertTrue(!type.equals(penType));
}