mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
adding multiple capacity obj to jobs and vehicleType
This commit is contained in:
parent
878442fe80
commit
c2377252ea
13 changed files with 388 additions and 19 deletions
|
|
@ -0,0 +1,66 @@
|
|||
|
||||
package jsprit.core.problem.job;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CapacityTest {
|
||||
|
||||
@Test
|
||||
public void whenSettingSimplyOneCapDimension_nuOfDimensionMustBeCorrect(){
|
||||
Capacity.Builder capBuilder = Capacity.Builder.newInstance();
|
||||
capBuilder.addDimension(0, 4);
|
||||
Capacity cap = capBuilder.build();
|
||||
assertEquals(1,cap.getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingTwoCapDimension_nuOfDimensionMustBeCorrect(){
|
||||
Capacity.Builder capBuilder = Capacity.Builder.newInstance();
|
||||
capBuilder.addDimension(0, 4);
|
||||
capBuilder.addDimension(1,10);
|
||||
Capacity cap = capBuilder.build();
|
||||
assertEquals(2,cap.getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingRandomNuOfCapDimension_nuOfDimensionMustBeCorrect(){
|
||||
Random rand = new Random();
|
||||
int nuOfCapDimensions = rand.nextInt(100);
|
||||
Capacity.Builder capBuilder = Capacity.Builder.newInstance();
|
||||
capBuilder.addDimension(nuOfCapDimensions-1, 4);
|
||||
Capacity cap = capBuilder.build();
|
||||
assertEquals(nuOfCapDimensions,cap.getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingOneDimValue_valueMustBeCorrect(){
|
||||
Capacity.Builder capBuilder = Capacity.Builder.newInstance();
|
||||
capBuilder.addDimension(0, 4);
|
||||
Capacity cap = capBuilder.build();
|
||||
assertEquals(4,cap.get(0));
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException.class)
|
||||
public void whenGettingIndexWhichIsHigherThanNuOfCapDimensions_throwIndexOutOfBoundsException(){
|
||||
Capacity.Builder capBuilder = Capacity.Builder.newInstance();
|
||||
capBuilder.addDimension(0, 4);
|
||||
Capacity cap = capBuilder.build();
|
||||
cap.get(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingNoDim_DefaultIsOneDimWithDimValueOfZero(){
|
||||
Capacity.Builder capBuilder = Capacity.Builder.newInstance();
|
||||
Capacity cap = capBuilder.build();
|
||||
assertEquals(1, cap.getNuOfDimensions());
|
||||
assertEquals(0, cap.get(0));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -16,13 +16,12 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.job;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import jsprit.core.problem.job.Service;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
|
|
@ -53,6 +52,38 @@ public class ServiceTest {
|
|||
// assertTrue(serviceSet.contains(two));
|
||||
serviceSet.remove(two);
|
||||
assertTrue(serviceSet.isEmpty());
|
||||
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void whenCapacityDimValueIsNegative_throwIllegalStateExpception(){
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").setLocationId("foo").addCapacityDimension(0, -10).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo(){
|
||||
Service one = Service.Builder.newInstance("s").setLocationId("foofoo")
|
||||
.addCapacityDimension(0,2)
|
||||
.addCapacityDimension(1,4)
|
||||
.build();
|
||||
assertEquals(2,one.getCapacity().getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenShipmentIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero(){
|
||||
Service one = Service.Builder.newInstance("s").setLocationId("foofoo")
|
||||
.build();
|
||||
assertEquals(1,one.getCapacity().getNuOfDimensions());
|
||||
assertEquals(0,one.getCapacity().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly(){
|
||||
Service one = Service.Builder.newInstance("s",1).setLocationId("foofoo")
|
||||
.build();
|
||||
assertEquals(1,one.getCapacityDemand());
|
||||
assertEquals(1,one.getCapacity().getNuOfDimensions());
|
||||
assertEquals(1,one.getCapacity().get(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,4 +54,38 @@ public class ShipmentTest {
|
|||
assertEquals(1.0,one.getDeliveryCoord().getX(),0.01);
|
||||
assertEquals(1.0,one.getDeliveryTimeWindow().getStart(),0.01);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void whenShipmentHasNegativeCapacityVal_throwIllegalStateExpception(){
|
||||
@SuppressWarnings("unused")
|
||||
Shipment one = Shipment.Builder.newInstance("s").setPickupLocation("foo").setDeliveryLocation("foofoo")
|
||||
.addCapacityDimension(0, -2)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo(){
|
||||
Shipment one = Shipment.Builder.newInstance("s").setPickupLocation("foo").setDeliveryLocation("foofoo")
|
||||
.addCapacityDimension(0,2)
|
||||
.addCapacityDimension(1,4)
|
||||
.build();
|
||||
assertEquals(2,one.getCapacity().getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenShipmentIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero(){
|
||||
Shipment one = Shipment.Builder.newInstance("s").setPickupLocation("foo").setPickupCoord(Coordinate.newInstance(0, 0))
|
||||
.setDeliveryLocation("foofoo").build();
|
||||
assertEquals(1,one.getCapacity().getNuOfDimensions());
|
||||
assertEquals(0,one.getCapacity().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly(){
|
||||
Shipment one = Shipment.Builder.newInstance("s",1).setPickupLocation("foo").setPickupCoord(Coordinate.newInstance(0, 0))
|
||||
.setDeliveryLocation("foofoo").build();
|
||||
assertEquals(1,one.getCapacityDemand());
|
||||
assertEquals(1,one.getCapacity().getNuOfDimensions());
|
||||
assertEquals(1,one.getCapacity().get(0));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
package jsprit.core.problem.vehicle;
|
||||
|
||||
|
||||
public class VehicleImplTest {
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package jsprit.core.problem.vehicle;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class VehicleTypeImplTest {
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void whenTypeHasNegativeCapacityVal_throwIllegalStateExpception(){
|
||||
@SuppressWarnings("unused")
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0,-10).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t")
|
||||
.addCapacityDimension(0,2)
|
||||
.addCapacityDimension(1, 4)
|
||||
.build();
|
||||
assertEquals(2,type.getCapacityDimensions().getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwoCapDimension_dimValuesMustBeCorrect(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t")
|
||||
.addCapacityDimension(0,2)
|
||||
.addCapacityDimension(1,4)
|
||||
.build();
|
||||
assertEquals(2,type.getCapacityDimensions().get(0));
|
||||
assertEquals(4,type.getCapacityDimensions().get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTypeIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDim(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").build();
|
||||
assertEquals(1,type.getCapacityDimensions().getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTypeIsBuiltWithoutSpecifyingCapacity_itShouldHvCapDimValOfZero(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").build();
|
||||
assertEquals(0,type.getCapacityDimensions().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTypeIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t",20).build();
|
||||
assertEquals(20,type.getCapacity());
|
||||
assertEquals(20,type.getCapacityDimensions().get(0));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue