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:
parent
bcfe9a401d
commit
21e4bb09f5
6 changed files with 15 additions and 3 deletions
|
|
@ -160,8 +160,10 @@ public class Service implements Job {
|
||||||
* @param dimensionIndex
|
* @param dimensionIndex
|
||||||
* @param dimensionValue
|
* @param dimensionValue
|
||||||
* @return the builder
|
* @return the builder
|
||||||
|
* @throws IllegalArgumentException if dimensionValue < 0
|
||||||
*/
|
*/
|
||||||
public Builder addCapacityDimension(int dimensionIndex, int dimensionValue){
|
public Builder addCapacityDimension(int dimensionIndex, int dimensionValue){
|
||||||
|
if(dimensionValue<0) throw new IllegalArgumentException("capacity value cannot be negative");
|
||||||
capacityBuilder.addDimension(dimensionIndex, dimensionValue);
|
capacityBuilder.addDimension(dimensionIndex, dimensionValue);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -212,9 +212,11 @@ public class Shipment implements Job{
|
||||||
*
|
*
|
||||||
* @param dimIndex
|
* @param dimIndex
|
||||||
* @param dimVal
|
* @param dimVal
|
||||||
* @return
|
* @return builder
|
||||||
|
* @throws IllegalArgumentException if dimVal < 0
|
||||||
*/
|
*/
|
||||||
public Builder addCapacityDimension(int dimIndex, int dimVal) {
|
public Builder addCapacityDimension(int dimIndex, int dimVal) {
|
||||||
|
if(dimVal<0) throw new IllegalArgumentException("capacity value cannot be negative");
|
||||||
capacityBuilder.addDimension(dimIndex, dimVal);
|
capacityBuilder.addDimension(dimIndex, dimVal);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -193,8 +193,10 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
* @param dimIndex
|
* @param dimIndex
|
||||||
* @param dimVal
|
* @param dimVal
|
||||||
* @return the builder
|
* @return the builder
|
||||||
|
* @throws IllegalArgumentException if dimVal < 0
|
||||||
*/
|
*/
|
||||||
public Builder addCapacityDimension(int dimIndex, int dimVal) {
|
public Builder addCapacityDimension(int dimIndex, int dimVal) {
|
||||||
|
if(dimVal<0) throw new IllegalArgumentException("capacity value cannot be negative");
|
||||||
capacityBuilder.addDimension(dimIndex,dimVal);
|
capacityBuilder.addDimension(dimIndex,dimVal);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ public class ServiceTest {
|
||||||
assertTrue(serviceSet.isEmpty());
|
assertTrue(serviceSet.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalStateException.class)
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void whenCapacityDimValueIsNegative_throwIllegalStateExpception(){
|
public void whenCapacityDimValueIsNegative_throwIllegalStateExpception(){
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
Service s = Service.Builder.newInstance("s").setLocationId("foo").addCapacityDimension(0, -10).build();
|
Service s = Service.Builder.newInstance("s").setLocationId("foo").addCapacityDimension(0, -10).build();
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,12 @@ public class ShipmentTest {
|
||||||
Shipment one = Shipment.Builder.newInstance("s", -10).setPickupLocation("foo").setDeliveryLocation("foofoo").build();
|
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)
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void whenIdIsNull_itShouldThrowException(){
|
public void whenIdIsNull_itShouldThrowException(){
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import org.junit.Test;
|
||||||
public class VehicleTypeImplTest {
|
public class VehicleTypeImplTest {
|
||||||
|
|
||||||
|
|
||||||
@Test(expected=IllegalStateException.class)
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void whenTypeHasNegativeCapacityVal_throwIllegalStateExpception(){
|
public void whenTypeHasNegativeCapacityVal_throwIllegalStateExpception(){
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0,-10).build();
|
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0,-10).build();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue