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

added non-negative restriction

This commit is contained in:
oblonski 2014-02-19 09:08:15 +01:00
parent bcfe9a401d
commit 21e4bb09f5
6 changed files with 15 additions and 3 deletions

View file

@ -160,8 +160,10 @@ public class Service implements Job {
* @param dimensionIndex
* @param dimensionValue
* @return the builder
* @throws IllegalArgumentException if dimensionValue < 0
*/
public Builder addCapacityDimension(int dimensionIndex, int dimensionValue){
if(dimensionValue<0) throw new IllegalArgumentException("capacity value cannot be negative");
capacityBuilder.addDimension(dimensionIndex, dimensionValue);
return this;
}

View file

@ -212,9 +212,11 @@ public class Shipment implements Job{
*
* @param dimIndex
* @param dimVal
* @return
* @return builder
* @throws IllegalArgumentException if dimVal < 0
*/
public Builder addCapacityDimension(int dimIndex, int dimVal) {
if(dimVal<0) throw new IllegalArgumentException("capacity value cannot be negative");
capacityBuilder.addDimension(dimIndex, dimVal);
return this;
}

View file

@ -193,8 +193,10 @@ public class VehicleTypeImpl implements VehicleType {
* @param dimIndex
* @param dimVal
* @return the builder
* @throws IllegalArgumentException if dimVal < 0
*/
public Builder addCapacityDimension(int dimIndex, int dimVal) {
if(dimVal<0) throw new IllegalArgumentException("capacity value cannot be negative");
capacityBuilder.addDimension(dimIndex,dimVal);
return this;
}

View file

@ -60,7 +60,7 @@ public class ServiceTest {
assertTrue(serviceSet.isEmpty());
}
@Test(expected=IllegalStateException.class)
@Test(expected=IllegalArgumentException.class)
public void whenCapacityDimValueIsNegative_throwIllegalStateExpception(){
@SuppressWarnings("unused")
Service s = Service.Builder.newInstance("s").setLocationId("foo").addCapacityDimension(0, -10).build();

View file

@ -44,6 +44,12 @@ public class ShipmentTest {
Shipment one = Shipment.Builder.newInstance("s", -10).setPickupLocation("foo").setDeliveryLocation("foofoo").build();
}
@Test(expected=IllegalArgumentException.class)
public void whenShipmentIsBuiltWithNegativeDemand_itShouldThrowException_v2(){
@SuppressWarnings("unused")
Shipment one = Shipment.Builder.newInstance("s").addCapacityDimension(0, -10).setPickupLocation("foo").setDeliveryLocation("foofoo").build();
}
@Test(expected=IllegalArgumentException.class)
public void whenIdIsNull_itShouldThrowException(){
@SuppressWarnings("unused")

View file

@ -7,7 +7,7 @@ import org.junit.Test;
public class VehicleTypeImplTest {
@Test(expected=IllegalStateException.class)
@Test(expected=IllegalArgumentException.class)
public void whenTypeHasNegativeCapacityVal_throwIllegalStateExpception(){
@SuppressWarnings("unused")
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0,-10).build();