diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/AbstractJob.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/AbstractJob.java index 81ef63e7..85a37e80 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/AbstractJob.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/AbstractJob.java @@ -26,7 +26,9 @@ import com.graphhopper.jsprit.core.problem.job.Job; public abstract class AbstractJob implements Job { private int index; + private Object userData; + @Override public int getIndex() { return index; } @@ -35,4 +37,15 @@ public abstract class AbstractJob implements Job { this.index = index; } + /** + * @return User-specific domain data associated by the job + */ + public Object getUserData() { + return userData; + } + + protected void setUserData(Object userData) { + this.userData = userData; + } + } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/AbstractVehicle.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/AbstractVehicle.java index bd259b4e..c8f69d2b 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/AbstractVehicle.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/AbstractVehicle.java @@ -30,6 +30,7 @@ public abstract class AbstractVehicle implements Vehicle { private int index; + @Override public int getIndex() { return index; } @@ -44,19 +45,35 @@ public abstract class AbstractVehicle implements Vehicle { private VehicleTypeKey vehicleIdentifier; - public int getIndex() { - return index; - } + private Object userData; - protected void setIndex(int index) { - this.index = index; - } + /** + * @return User-specific domain data associated with the vehicle + */ + @Override + public Object getUserData() { + return userData; + } - public VehicleTypeKey getVehicleTypeIdentifier() { - return vehicleIdentifier; - } + protected void setUserData(Object userData) { + this.userData = userData; + } - protected void setVehicleIdentifier(VehicleTypeKey vehicleTypeIdentifier) { - this.vehicleIdentifier = vehicleTypeIdentifier; - } + @Override + public int getIndex() { + return index; + } + + protected void setIndex(int index) { + this.index = index; + } + + @Override + public VehicleTypeKey getVehicleTypeIdentifier() { + return vehicleIdentifier; + } + + protected void setVehicleIdentifier(VehicleTypeKey vehicleTypeIdentifier) { + this.vehicleIdentifier = vehicleTypeIdentifier; + } } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/Location.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/Location.java index f9721e15..233a71a9 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/Location.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/Location.java @@ -66,10 +66,30 @@ public final class Location implements HasIndex, HasId { private String name = ""; + private Object userData; + public static Builder newInstance() { return new Builder(); } + /** + * Sets user specific domain data associated with the object. + * + *

+ * The user data is a black box for the framework, it only stores it, + * but never interacts with it in any way. + *

+ * + * @param userData + * any object holding the domain specific user data + * associated with the object. + * @return builder + */ + public Builder setUserData(Object userData) { + this.userData = userData; + return this; + } + /** * Sets location index * @@ -140,13 +160,23 @@ public final class Location implements HasIndex, HasId { private final String name; + private Object userData; + private Location(Builder builder) { + this.userData = builder.userData; this.index = builder.index; this.coordinate = builder.coordinate; this.id = builder.id; this.name = builder.name; } + /** + * @return User-specific domain data associated by the job + */ + public Object getUserData() { + return userData; + } + @Override public String getId() { return id; diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Service.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Service.java index 11be0994..57ed0639 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Service.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Service.java @@ -17,6 +17,8 @@ */ package com.graphhopper.jsprit.core.problem.job; +import java.util.Collection; + import com.graphhopper.jsprit.core.problem.AbstractJob; import com.graphhopper.jsprit.core.problem.Capacity; import com.graphhopper.jsprit.core.problem.Location; @@ -26,8 +28,6 @@ import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindows; import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindowsImpl; import com.graphhopper.jsprit.core.util.Coordinate; -import java.util.Collection; - /** * Service implementation of a job. *

@@ -86,15 +86,16 @@ public class Service extends AbstractJob { protected TimeWindowsImpl timeWindows; - private boolean twAdded = false; + private boolean twAdded = false; private int priority = 2; + protected Object userData; - Builder(String id){ - this.id = id; - timeWindows = new TimeWindowsImpl(); - timeWindows.add(timeWindow); - } + Builder(String id){ + this.id = id; + timeWindows = new TimeWindowsImpl(); + timeWindows.add(timeWindow); + } /** * Protected method to set the type-name of the service. @@ -137,6 +138,24 @@ public class Service extends AbstractJob { return this; } + /** + * Sets user specific domain data associated with the object. + * + *

+ * The user data is a black box for the framework, it only stores it, + * but never interacts with it in any way. + *

+ * + * @param userData + * any object holding the domain specific user data + * associated with the object. + * @return builder + */ + public Builder setUserData(Object userData) { + this.userData = userData; + return this; + } + /** * Adds capacity dimension. * @@ -247,7 +266,8 @@ public class Service extends AbstractJob { private final int priority; - Service(Builder builder) { + Service(Builder builder) { + setUserData(builder.userData); id = builder.id; serviceTime = builder.serviceTime; timeWindow = builder.timeWindow; @@ -256,13 +276,13 @@ public class Service extends AbstractJob { skills = builder.skills; name = builder.name; location = builder.location; - timeWindowManager = builder.timeWindows; + timeWindowManager = builder.timeWindows; priority = builder.priority; - } + } - public Collection getTimeWindows(){ - return timeWindowManager.getTimeWindows(); - } + public Collection getTimeWindows(){ + return timeWindowManager.getTimeWindows(); + } @Override public String getId() { @@ -367,6 +387,7 @@ public class Service extends AbstractJob { * * @return priority */ + @Override public int getPriority() { return priority; } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Shipment.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Shipment.java index 6b8bde5d..b2281fe2 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Shipment.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Shipment.java @@ -17,6 +17,8 @@ */ package com.graphhopper.jsprit.core.problem.job; +import java.util.Collection; + import com.graphhopper.jsprit.core.problem.AbstractJob; import com.graphhopper.jsprit.core.problem.Capacity; import com.graphhopper.jsprit.core.problem.Location; @@ -24,8 +26,6 @@ import com.graphhopper.jsprit.core.problem.Skills; import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow; import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindowsImpl; -import java.util.Collection; - /** * Shipment is an implementation of Job and consists of a pickup and a delivery of something. @@ -89,6 +89,8 @@ public class Shipment extends AbstractJob { private int priority = 2; + public Object userData; + /** * Returns new instance of this builder. * @@ -108,10 +110,29 @@ public class Shipment extends AbstractJob { deliveryTimeWindows.add(deliveryTimeWindow); } + /** + * Sets user specific domain data associated with the object. + * + *

+ * The user data is a black box for the framework, it only stores it, + * but never interacts with it in any way. + *

+ * + * @param userData + * any object holding the domain specific user data + * associated with the object. + * @return builder + */ + public Builder setUserData(Object userData) { + this.userData = userData; + return this; + } + /** * Sets pickup location. * - * @param pickupLocation pickup location + * @param pickupLocation + * pickup location * @return builder */ public Builder setPickupLocation(Location pickupLocation) { @@ -311,6 +332,7 @@ public class Shipment extends AbstractJob { private final int priority; Shipment(Builder builder) { + setUserData(builder.userData); this.id = builder.id; this.pickupServiceTime = builder.pickupServiceTime; this.pickupTimeWindow = builder.pickupTimeWindow; @@ -438,6 +460,7 @@ public class Shipment extends AbstractJob { * * @return priority */ + @Override public int getPriority() { return priority; } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/Vehicle.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/Vehicle.java index 27210957..fd19feac 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/Vehicle.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/Vehicle.java @@ -72,6 +72,14 @@ public interface Vehicle extends HasId, HasIndex { public abstract VehicleTypeKey getVehicleTypeIdentifier(); public abstract Skills getSkills(); + /** + * @return User-specific domain data associated with the vehicle + */ + public Object getUserData(); public abstract Break getBreak(); + // Switch to this as soon as we switct to Java 8: + // default Object getUserData() { + // return null; + // }; } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleImpl.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleImpl.java index 4930fef0..143cd6a7 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleImpl.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleImpl.java @@ -17,12 +17,13 @@ */ package com.graphhopper.jsprit.core.problem.vehicle; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.graphhopper.jsprit.core.problem.AbstractVehicle; import com.graphhopper.jsprit.core.problem.Location; import com.graphhopper.jsprit.core.problem.Skills; import com.graphhopper.jsprit.core.problem.job.Break; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** @@ -130,6 +131,8 @@ public class VehicleImpl extends AbstractVehicle { private Break aBreak; + private Object userData; + private Builder(String id) { super(); this.id = id; @@ -148,16 +151,39 @@ public class VehicleImpl extends AbstractVehicle { return this; } + /** + * Sets user specific domain data associated with the object. + * + *

+ * The user data is a black box for the framework, it only stores it, + * but never interacts with it in any way. + *

+ * + * @param userData + * any object holding the domain specific user data + * associated with the object. + * @return builder + */ + public Builder setUserData(Object userData) { + this.userData = userData; + return this; + } + /** * Sets the flag whether the vehicle must return to depot or not. *

- *

If returnToDepot is true, the vehicle must return to specified end-location. If you - * omit specifying the end-location, vehicle returns to start-location (that must to be set). If - * you specify it, it returns to specified end-location. *

- *

If returnToDepot is false, the end-location of the vehicle is endogenous. + * If returnToDepot is true, the vehicle must return to specified + * end-location. If you omit specifying the end-location, vehicle + * returns to start-location (that must to be set). If you specify it, + * it returns to specified end-location. + *

+ *

+ * If returnToDepot is false, the end-location of the vehicle is + * endogenous. * - * @param returnToDepot true if vehicle need to return to depot, otherwise false + * @param returnToDepot + * true if vehicle need to return to depot, otherwise false * @return this builder */ public Builder setReturnToDepot(boolean returnToDepot) { @@ -234,14 +260,13 @@ public class VehicleImpl extends AbstractVehicle { if (startLocation != null && endLocation != null) { if (!startLocation.getId().equals(endLocation.getId()) && !returnToDepot) throw new IllegalArgumentException("this must not be. you specified both endLocationId and open-routes. this is contradictory.
" + - "if you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified."); + "if you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified."); } if (startLocation != null && endLocation == null) { endLocation = startLocation; } - if (startLocation == null && endLocation == null) { + if (startLocation == null && endLocation == null) throw new IllegalArgumentException("vehicle requires startLocation. but neither locationId nor locationCoord nor startLocationId nor startLocationCoord has been set"); - } skills = skillBuilder.build(); return new VehicleImpl(this); } @@ -297,6 +322,7 @@ public class VehicleImpl extends AbstractVehicle { private final Break aBreak; private VehicleImpl(Builder builder) { + setUserData(builder.userData); id = builder.id; type = builder.type; earliestDeparture = builder.earliestStart; @@ -306,7 +332,7 @@ public class VehicleImpl extends AbstractVehicle { endLocation = builder.endLocation; startLocation = builder.startLocation; aBreak = builder.aBreak; -// setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(),startLocation.getId(),endLocation.getId(),earliestDeparture,latestArrival,skills)); + // setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(),startLocation.getId(),endLocation.getId(),earliestDeparture,latestArrival,skills)); setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(), startLocation.getId(), endLocation.getId(), earliestDeparture, latestArrival, skills, returnToDepot)); } @@ -318,11 +344,11 @@ public class VehicleImpl extends AbstractVehicle { @Override public String toString() { return "[id=" + id + "]" + - "[type=" + type + "]" + - "[startLocation=" + startLocation + "]" + - "[endLocation=" + endLocation + "]" + - "[isReturnToDepot=" + isReturnToDepot() + "]" + - "[skills=" + skills + "]"; + "[type=" + type + "]" + + "[startLocation=" + startLocation + "]" + + "[endLocation=" + endLocation + "]" + + "[isReturnToDepot=" + isReturnToDepot() + "]" + + "[skills=" + skills + "]"; } @@ -346,6 +372,7 @@ public class VehicleImpl extends AbstractVehicle { return id; } + @Override public boolean isReturnToDepot() { return returnToDepot; } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleType.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleType.java index 9847f4ba..e2eee81d 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleType.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleType.java @@ -56,4 +56,13 @@ public interface VehicleType { public String getProfile(); + /** + * @return User-specific domain data associated with the vehicle type + */ + public Object getUserData(); + + // Switch to this as soon as we switct to Java 8: + // default Object getUserData() { + // return null; + // }; } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleTypeImpl.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleTypeImpl.java index 864d978c..7f033e5c 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleTypeImpl.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleTypeImpl.java @@ -116,16 +116,39 @@ public class VehicleTypeImpl implements VehicleType { private boolean dimensionAdded = false; + private Object userData; + private Builder(String id) { this.id = id; } + /** - * Sets the maximum velocity this vehicle-type can go [in meter per seconds]. + * Sets user specific domain data associated with the object. + * + *

+ * The user data is a black box for the framework, it only stores it, + * but never interacts with it in any way. + *

+ * + * @param userData + * any object holding the domain specific user data + * associated with the object. + * @return builder + */ + public Builder setUserData(Object userData) { + this.userData = userData; + return this; + } + + /** + * Sets the maximum velocity this vehicle-type can go [in meter per + * seconds]. * * @param inMeterPerSeconds * @return this builder - * @throws IllegalArgumentException if velocity is smaller than zero + * @throws IllegalArgumentException + * if velocity is smaller than zero */ public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds) { if (inMeterPerSeconds < 0.0) throw new IllegalArgumentException("velocity cannot be smaller than zero"); @@ -240,8 +263,8 @@ public class VehicleTypeImpl implements VehicleType { if (dimVal < 0) throw new IllegalArgumentException("capacity value cannot be negative"); if (capacityDimensions != null) throw new IllegalArgumentException("either build your dimension with build your dimensions with " + - "addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." + - "You used both methods."); + "addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." + + "You used both methods."); dimensionAdded = true; capacityBuilder.addDimension(dimIndex, dimVal); return this; @@ -261,8 +284,8 @@ public class VehicleTypeImpl implements VehicleType { public Builder setCapacityDimensions(Capacity capacity) { if (dimensionAdded) throw new IllegalArgumentException("either build your dimension with build your dimensions with " + - "addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." + - "You used both methods."); + "addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." + + "You used both methods."); this.capacityDimensions = capacity; return this; } @@ -278,7 +301,7 @@ public class VehicleTypeImpl implements VehicleType { final int prime = 31; int result = 1; result = prime * result - + ((typeId == null) ? 0 : typeId.hashCode()); + + ((typeId == null) ? 0 : typeId.hashCode()); return result; } @@ -314,12 +337,15 @@ public class VehicleTypeImpl implements VehicleType { private final double maxVelocity; + private Object userData; + /** * priv constructor constructing vehicle-type * * @param builder */ private VehicleTypeImpl(VehicleTypeImpl.Builder builder) { + this.userData = builder.userData; typeId = builder.id; capacity = builder.capacity; maxVelocity = builder.maxVelo; @@ -328,6 +354,14 @@ public class VehicleTypeImpl implements VehicleType { profile = builder.profile; } + /** + * @return User-specific domain data associated with the vehicle + */ + @Override + public Object getUserData() { + return userData; + } + /* (non-Javadoc) * @see basics.route.VehicleType#getTypeId() */ @@ -347,8 +381,8 @@ public class VehicleTypeImpl implements VehicleType { @Override public String toString() { return "[typeId=" + typeId + "]" + - "[capacity=" + capacityDimensions + "]" + - "[costs=" + vehicleCostParams + "]"; + "[capacity=" + capacityDimensions + "]" + + "[costs=" + vehicleCostParams + "]"; } @Override diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/LocationTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/LocationTest.java index edcd76ff..00e41666 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/LocationTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/LocationTest.java @@ -18,11 +18,18 @@ package com.graphhopper.jsprit.core.problem; -import com.graphhopper.jsprit.core.util.Coordinate; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; import org.junit.Assert; import org.junit.Test; +import com.graphhopper.jsprit.core.util.Coordinate; + /** * Created by schroeder on 16.12.14. */ @@ -82,7 +89,7 @@ public class LocationTest { @Test public void whenCoordinateSetWithFactory_returnCorrectLocation() { -// Location l = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10,20)).build(); + // Location l = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10,20)).build(); Location l = Location.newInstance(10, 20); Assert.assertEquals(10., l.getCoordinate().getX(),0.001); Assert.assertEquals(20., l.getCoordinate().getY(),0.001); @@ -90,4 +97,16 @@ public class LocationTest { } + @Test + public void whenSettingUserData_itIsAssociatedWithTheLocation() { + Location one = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 20)) + .setUserData(new HashMap()).build(); + Location two = Location.Builder.newInstance().setIndex(1).setUserData(42).build(); + Location three = Location.Builder.newInstance().setIndex(2).build(); + + assertTrue(one.getUserData() instanceof Map); + assertEquals(42, two.getUserData()); + assertNull(three.getUserData()); + } + } diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/DeliveryTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/DeliveryTest.java index 0ab568c6..3eb0b141 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/DeliveryTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/DeliveryTest.java @@ -17,11 +17,18 @@ */ package com.graphhopper.jsprit.core.problem.job; -import com.graphhopper.jsprit.core.problem.Location; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; + import org.junit.Assert; import org.junit.Test; -import static org.junit.Assert.*; +import com.graphhopper.jsprit.core.problem.Location; public class DeliveryTest { @@ -33,9 +40,9 @@ public class DeliveryTest { @Test public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() { Delivery one = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("foofoo")) - .addSizeDimension(0, 2) - .addSizeDimension(1, 4) - .build(); + .addSizeDimension(0, 2) + .addSizeDimension(1, 4) + .build(); assertEquals(2, one.getSize().getNuOfDimensions()); assertEquals(2, one.getSize().get(0)); assertEquals(4, one.getSize().get(1)); @@ -45,7 +52,7 @@ public class DeliveryTest { @Test public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() { Delivery one = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("foofoo")) - .build(); + .build(); assertEquals(1, one.getSize().getNuOfDimensions()); assertEquals(0, one.getSize().get(0)); } @@ -53,7 +60,7 @@ public class DeliveryTest { @Test public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() { Delivery one = Delivery.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo")) - .build(); + .build(); assertEquals(1, one.getSize().getNuOfDimensions()); assertEquals(1, one.getSize().get(0)); } @@ -61,7 +68,7 @@ public class DeliveryTest { @Test public void whenAddingSkills_theyShouldBeAddedCorrectly() { Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addRequiredSkill("drill").addRequiredSkill("screwdriver").build(); + .addRequiredSkill("drill").addRequiredSkill("screwdriver").build(); assertTrue(s.getRequiredSkills().containsSkill("drill")); assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver")); } @@ -69,7 +76,7 @@ public class DeliveryTest { @Test public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() { Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build(); + .addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build(); assertTrue(s.getRequiredSkills().containsSkill("drill")); assertTrue(s.getRequiredSkills().containsSkill("drilL")); } @@ -77,7 +84,7 @@ public class DeliveryTest { @Test public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() { Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addRequiredSkill("screwDriver").build(); + .addRequiredSkill("screwDriver").build(); assertFalse(s.getRequiredSkills().containsSkill("drill")); assertFalse(s.getRequiredSkills().containsSkill("drilL")); } @@ -85,23 +92,35 @@ public class DeliveryTest { @Test public void nameShouldBeAssigned() { Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .setName("name").build(); + .setName("name").build(); assertEquals("name", s.getName()); } @Test public void whenSettingPriorities_itShouldBeSetCorrectly(){ Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .setPriority(3).build(); + .setPriority(3).build(); Assert.assertEquals(3, s.getPriority()); } @Test public void whenNotSettingPriorities_defaultShouldBe(){ Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .build(); + .build(); Assert.assertEquals(2, s.getPriority()); } + @Test + public void whenSettingUserData_itIsAssociatedWithTheJob() { + Delivery one = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc")) + .setUserData(new HashMap()).build(); + Delivery two = Delivery.Builder.newInstance("s2").setLocation(Location.newInstance("loc")).setUserData(42) + .build(); + Delivery three = Delivery.Builder.newInstance("s3").setLocation(Location.newInstance("loc")).build(); + + assertTrue(one.getUserData() instanceof Map); + assertEquals(42, two.getUserData()); + assertNull(three.getUserData()); + } } diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/PickupTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/PickupTest.java index 6236536c..9f36a40f 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/PickupTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/PickupTest.java @@ -17,11 +17,18 @@ */ package com.graphhopper.jsprit.core.problem.job; -import com.graphhopper.jsprit.core.problem.Location; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; + import org.junit.Assert; import org.junit.Test; -import static org.junit.Assert.*; +import com.graphhopper.jsprit.core.problem.Location; public class PickupTest { @@ -33,9 +40,9 @@ public class PickupTest { @Test public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() { Pickup one = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("foofoo")) - .addSizeDimension(0, 2) - .addSizeDimension(1, 4) - .build(); + .addSizeDimension(0, 2) + .addSizeDimension(1, 4) + .build(); assertEquals(2, one.getSize().getNuOfDimensions()); assertEquals(2, one.getSize().get(0)); assertEquals(4, one.getSize().get(1)); @@ -45,7 +52,7 @@ public class PickupTest { @Test public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() { Pickup one = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("foofoo")) - .build(); + .build(); assertEquals(1, one.getSize().getNuOfDimensions()); assertEquals(0, one.getSize().get(0)); } @@ -53,7 +60,7 @@ public class PickupTest { @Test public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() { Pickup one = Pickup.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo")) - .build(); + .build(); assertEquals(1, one.getSize().getNuOfDimensions()); assertEquals(1, one.getSize().get(0)); } @@ -61,7 +68,7 @@ public class PickupTest { @Test public void whenAddingSkills_theyShouldBeAddedCorrectly() { Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addRequiredSkill("drill").addRequiredSkill("screwdriver").build(); + .addRequiredSkill("drill").addRequiredSkill("screwdriver").build(); assertTrue(s.getRequiredSkills().containsSkill("drill")); assertTrue(s.getRequiredSkills().containsSkill("drill")); assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver")); @@ -70,7 +77,7 @@ public class PickupTest { @Test public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() { Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build(); + .addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build(); assertTrue(s.getRequiredSkills().containsSkill("drill")); assertTrue(s.getRequiredSkills().containsSkill("drilL")); } @@ -78,7 +85,7 @@ public class PickupTest { @Test public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() { Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addRequiredSkill("screwDriver").build(); + .addRequiredSkill("screwDriver").build(); assertFalse(s.getRequiredSkills().containsSkill("drill")); assertFalse(s.getRequiredSkills().containsSkill("drilL")); } @@ -86,7 +93,7 @@ public class PickupTest { @Test public void nameShouldBeAssigned() { Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .setName("name").build(); + .setName("name").build(); assertEquals("name", s.getName()); } @@ -94,15 +101,26 @@ public class PickupTest { @Test public void whenSettingPriorities_itShouldBeSetCorrectly(){ Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .setPriority(3).build(); + .setPriority(3).build(); Assert.assertEquals(3, s.getPriority()); } @Test public void whenNotSettingPriorities_defaultShouldBe(){ Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .build(); + .build(); Assert.assertEquals(2, s.getPriority()); } + @Test + public void whenSettingUserData_itIsAssociatedWithTheJob() { + Pickup one = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc")) + .setUserData(new HashMap()).build(); + Pickup two = Pickup.Builder.newInstance("s2").setLocation(Location.newInstance("loc")).setUserData(42).build(); + Pickup three = Pickup.Builder.newInstance("s3").setLocation(Location.newInstance("loc")).build(); + + assertTrue(one.getUserData() instanceof Map); + assertEquals(42, two.getUserData()); + assertNull(three.getUserData()); + } } diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ServiceTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ServiceTest.java index f1efce37..6b051e84 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ServiceTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ServiceTest.java @@ -17,17 +17,25 @@ */ package com.graphhopper.jsprit.core.problem.job; -import com.graphhopper.jsprit.core.problem.Location; -import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsCollectionContaining.hasItem; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + import org.junit.Assert; import org.junit.Test; -import java.util.HashSet; -import java.util.Set; - -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsCollectionContaining.hasItem; -import static org.junit.Assert.*; +import com.graphhopper.jsprit.core.problem.Location; +import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow; public class ServiceTest { @@ -53,7 +61,7 @@ public class ServiceTest { Service one = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("foo")).build(); Service two = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("fo")).build(); serviceSet.add(one); -// assertTrue(serviceSet.contains(two)); + // assertTrue(serviceSet.contains(two)); serviceSet.remove(two); assertTrue(serviceSet.isEmpty()); } @@ -67,16 +75,16 @@ public class ServiceTest { @Test public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() { Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("foofoo")) - .addSizeDimension(0, 2) - .addSizeDimension(1, 4) - .build(); + .addSizeDimension(0, 2) + .addSizeDimension(1, 4) + .build(); assertEquals(2, one.getSize().getNuOfDimensions()); } @Test public void whenShipmentIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() { Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("foofoo")) - .build(); + .build(); assertEquals(1, one.getSize().getNuOfDimensions()); assertEquals(0, one.getSize().get(0)); } @@ -84,7 +92,7 @@ public class ServiceTest { @Test public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() { Service one = Service.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo")) - .build(); + .build(); assertEquals(1, one.getSize().getNuOfDimensions()); assertEquals(1, one.getSize().get(0)); } @@ -116,71 +124,71 @@ public class ServiceTest { } - @Test - public void whenSettingLocationCoord_itShouldBeSetCorrectly(){ - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance(1, 2)).build(); - assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01); - assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01); + @Test + public void whenSettingLocationCoord_itShouldBeSetCorrectly(){ + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance(1, 2)).build(); assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01); assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01); - } + assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01); + assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01); + } - @Test(expected=IllegalArgumentException.class) - public void whenSettingNeitherLocationIdNorCoord_throwsException(){ - @SuppressWarnings("unused") - Service s = Service.Builder.newInstance("s").build(); - } + @Test(expected=IllegalArgumentException.class) + public void whenSettingNeitherLocationIdNorCoord_throwsException(){ + @SuppressWarnings("unused") + Service s = Service.Builder.newInstance("s").build(); + } - @Test(expected=IllegalArgumentException.class) - public void whenServiceTimeSmallerZero_throwIllegalStateException(){ - @SuppressWarnings("unused") - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(-1).build(); - } + @Test(expected=IllegalArgumentException.class) + public void whenServiceTimeSmallerZero_throwIllegalStateException(){ + @SuppressWarnings("unused") + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(-1).build(); + } - @Test - public void whenSettingServiceTime_itShouldBeSetCorrectly(){ - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(1).build(); - assertEquals(1.0,s.getServiceDuration(),0.01); - } + @Test + public void whenSettingServiceTime_itShouldBeSetCorrectly(){ + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(1).build(); + assertEquals(1.0,s.getServiceDuration(),0.01); + } - @Test(expected=IllegalArgumentException.class) - public void whenTimeWindowIsNull_throwException(){ - @SuppressWarnings("unused") - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(null).build(); - } + @Test(expected=IllegalArgumentException.class) + public void whenTimeWindowIsNull_throwException(){ + @SuppressWarnings("unused") + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(null).build(); + } - @Test - public void whenSettingTimeWindow_itShouldBeSetCorrectly(){ - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build(); - assertEquals(1.0,s.getTimeWindow().getStart(),0.01); - assertEquals(2.0,s.getTimeWindow().getEnd(),0.01); - } + @Test + public void whenSettingTimeWindow_itShouldBeSetCorrectly(){ + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build(); + assertEquals(1.0,s.getTimeWindow().getStart(),0.01); + assertEquals(2.0,s.getTimeWindow().getEnd(),0.01); + } - @Test - public void whenAddingSkills_theyShouldBeAddedCorrectly(){ - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addRequiredSkill("drill").addRequiredSkill("screwdriver").build(); - assertTrue(s.getRequiredSkills().containsSkill("drill")); - assertTrue(s.getRequiredSkills().containsSkill("drill")); - assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver")); - } + @Test + public void whenAddingSkills_theyShouldBeAddedCorrectly(){ + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) + .addRequiredSkill("drill").addRequiredSkill("screwdriver").build(); + assertTrue(s.getRequiredSkills().containsSkill("drill")); + assertTrue(s.getRequiredSkills().containsSkill("drill")); + assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver")); + } - @Test - public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){ - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build(); - assertTrue(s.getRequiredSkills().containsSkill("drill")); - assertTrue(s.getRequiredSkills().containsSkill("drilL")); - } + @Test + public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){ + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) + .addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build(); + assertTrue(s.getRequiredSkills().containsSkill("drill")); + assertTrue(s.getRequiredSkills().containsSkill("drilL")); + } @Test public void whenAddingSeveralTimeWindows_itShouldBeSetCorrectly(){ TimeWindow tw1 = TimeWindow.newInstance(1.0, 2.0); TimeWindow tw2 = TimeWindow.newInstance(3.0, 5.0); Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addTimeWindow(tw1) - .addTimeWindow(tw2) - .build(); + .addTimeWindow(tw1) + .addTimeWindow(tw2) + .build(); assertEquals(2, s.getTimeWindows().size()); assertThat(s.getTimeWindows(),hasItem(is(tw1))); assertThat(s.getTimeWindows(),hasItem(is(tw2))); @@ -189,7 +197,7 @@ public class ServiceTest { @Test public void whenAddingTimeWindow_itShouldBeSetCorrectly(){ Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build(); + .addTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build(); assertEquals(1.0, s.getTimeWindow().getStart(), 0.01); assertEquals(2.0, s.getTimeWindow().getEnd(), 0.01); } @@ -200,7 +208,7 @@ public class ServiceTest { @Test public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() { Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addRequiredSkill("screwDriver").build(); + .addRequiredSkill("screwDriver").build(); assertFalse(s.getRequiredSkills().containsSkill("drill")); assertFalse(s.getRequiredSkills().containsSkill("drilL")); } @@ -208,74 +216,87 @@ public class ServiceTest { @Test public void nameShouldBeAssigned() { Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .setName("name").build(); + .setName("name").build(); assertEquals("name", s.getName()); } - @Test - public void shouldKnowMultipleTimeWindows(){ - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addTimeWindow(TimeWindow.newInstance(0., 10.)).addTimeWindow(TimeWindow.newInstance(20., 30.)) - .setName("name").build(); - assertEquals(2,s.getTimeWindows().size()); - } + @Test + public void shouldKnowMultipleTimeWindows(){ + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) + .addTimeWindow(TimeWindow.newInstance(0., 10.)).addTimeWindow(TimeWindow.newInstance(20., 30.)) + .setName("name").build(); + assertEquals(2,s.getTimeWindows().size()); + } - @Test(expected = IllegalArgumentException.class) - public void whenMultipleTWOverlap_throwEx(){ - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addTimeWindow(TimeWindow.newInstance(0.,10.)) - .addTimeWindow(TimeWindow.newInstance(5., 30.)) - .setName("name").build(); - } + @Test(expected = IllegalArgumentException.class) + public void whenMultipleTWOverlap_throwEx(){ + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) + .addTimeWindow(TimeWindow.newInstance(0.,10.)) + .addTimeWindow(TimeWindow.newInstance(5., 30.)) + .setName("name").build(); + } - @Test(expected = IllegalArgumentException.class) - public void whenMultipleTWOverlap2_throwEx(){ - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addTimeWindow(TimeWindow.newInstance(20., 30.)) - .addTimeWindow(TimeWindow.newInstance(0., 25.)) - .setName("name").build(); - } + @Test(expected = IllegalArgumentException.class) + public void whenMultipleTWOverlap2_throwEx(){ + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) + .addTimeWindow(TimeWindow.newInstance(20., 30.)) + .addTimeWindow(TimeWindow.newInstance(0., 25.)) + .setName("name").build(); + } @Test public void whenSettingPriorities_itShouldBeSetCorrectly(){ Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .setPriority(1).build(); + .setPriority(1).build(); Assert.assertEquals(1, s.getPriority()); } @Test public void whenSettingPriorities_itShouldBeSetCorrectly2(){ Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .setPriority(3).build(); + .setPriority(3).build(); Assert.assertEquals(3, s.getPriority()); } @Test public void whenSettingPriorities_itShouldBeSetCorrectly3() { Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .setPriority(10).build(); + .setPriority(10).build(); Assert.assertEquals(10, s.getPriority()); } @Test public void whenNotSettingPriorities_defaultShouldBe2(){ Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .build(); + .build(); Assert.assertEquals(2, s.getPriority()); } @Test(expected = IllegalArgumentException.class) public void whenSettingIncorrectPriorities_itShouldThrowException(){ Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .setPriority(30).build(); + .setPriority(30).build(); } @Test(expected = IllegalArgumentException.class) public void whenSettingIncorrectPriorities_itShouldThrowException2(){ Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .setPriority(0).build(); + .setPriority(0).build(); } + + @Test + public void whenSettingUserData_itIsAssociatedWithTheJob() { + Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) + .setUserData(new HashMap()).build(); + Service two = Service.Builder.newInstance("s2").setLocation(Location.newInstance("loc")).setUserData(42) + .build(); + Service three = Service.Builder.newInstance("s3").setLocation(Location.newInstance("loc")).build(); + + assertTrue(one.getUserData() instanceof Map); + assertEquals(42, two.getUserData()); + assertNull(three.getUserData()); + } } diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ShipmentTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ShipmentTest.java index cbfa1f26..e7caf2c1 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ShipmentTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/job/ShipmentTest.java @@ -17,25 +17,34 @@ */ package com.graphhopper.jsprit.core.problem.job; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsCollectionContaining.hasItem; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; + import com.graphhopper.jsprit.core.problem.Location; import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow; import com.graphhopper.jsprit.core.util.Coordinate; import com.graphhopper.jsprit.core.util.TestUtils; -import org.junit.Assert; -import org.junit.Test; - -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsCollectionContaining.hasItem; -import static org.junit.Assert.*; public class ShipmentTest { @Test public void whenTwoShipmentsHaveTheSameId_theyReferencesShouldBeUnEqual() { Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()). - setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); + setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); Shipment two = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()). - setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); + setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); assertTrue(one != two); } @@ -43,9 +52,9 @@ public class ShipmentTest { @Test public void whenTwoShipmentsHaveTheSameId_theyShouldBeEqual() { Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()). - setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); + setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); Shipment two = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()). - setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); + setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); assertTrue(one.equals(two)); } @@ -53,7 +62,7 @@ public class ShipmentTest { @Test public void whenShipmentIsInstantiatedWithASizeOf10_theSizeShouldBe10() { Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()). - setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); + setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); assertEquals(10, one.getSize().get(0)); } @@ -61,24 +70,24 @@ public class ShipmentTest { public void whenShipmentIsBuiltWithNegativeDemand_itShouldThrowException() { @SuppressWarnings("unused") Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, -10) - .setPickupLocation(Location.Builder.newInstance().setId("foo").build()) - .setDeliveryLocation(TestUtils.loc("foofoo")).build(); + .setPickupLocation(Location.Builder.newInstance().setId("foo").build()) + .setDeliveryLocation(TestUtils.loc("foofoo")).build(); } @Test(expected = IllegalArgumentException.class) public void whenShipmentIsBuiltWithNegativeDemand_itShouldThrowException_v2() { @SuppressWarnings("unused") Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, -10) - .setPickupLocation(Location.Builder.newInstance().setId("foo").build()) - .setDeliveryLocation(TestUtils.loc("foofoo")).build(); + .setPickupLocation(Location.Builder.newInstance().setId("foo").build()) + .setDeliveryLocation(TestUtils.loc("foofoo")).build(); } @Test(expected = IllegalArgumentException.class) public void whenIdIsNull_itShouldThrowException() { @SuppressWarnings("unused") Shipment one = Shipment.Builder.newInstance(null).addSizeDimension(0, 10) - .setPickupLocation(Location.Builder.newInstance().setId("foo").build()) - .setDeliveryLocation(TestUtils.loc("foofoo")).build(); + .setPickupLocation(Location.Builder.newInstance().setId("foo").build()) + .setDeliveryLocation(TestUtils.loc("foofoo")).build(); } @Test @@ -115,7 +124,7 @@ public class ShipmentTest { @Test public void whenPickupCoordIsSet_itShouldBeDoneCorrectly() { Shipment s = Shipment.Builder.newInstance("s") - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").setCoordinate(Coordinate.newInstance(1, 2)).build()).build(); + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").setCoordinate(Coordinate.newInstance(1, 2)).build()).build(); assertEquals(1.0, s.getPickupLocation().getCoordinate().getX(), 0.01); assertEquals(2.0, s.getPickupLocation().getCoordinate().getY(), 0.01); assertEquals(1.0, s.getPickupLocation().getCoordinate().getX(), 0.01); @@ -126,7 +135,7 @@ public class ShipmentTest { @Test public void whenDeliveryLocationIdIsSet_itShouldBeDoneCorrectly() { Shipment s = Shipment.Builder.newInstance("s") - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); assertEquals("delLoc", s.getDeliveryLocation().getId()); assertEquals("delLoc", s.getDeliveryLocation().getId()); } @@ -135,8 +144,8 @@ public class ShipmentTest { @Test public void whenDeliveryCoordIsSet_itShouldBeDoneCorrectly() { Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(1, 2))) - .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()) - .build(); + .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()) + .build(); assertEquals(1.0, s.getDeliveryLocation().getCoordinate().getX(), 0.01); assertEquals(2.0, s.getDeliveryLocation().getCoordinate().getY(), 0.01); assertEquals(1.0, s.getDeliveryLocation().getCoordinate().getX(), 0.01); @@ -146,22 +155,22 @@ public class ShipmentTest { @Test public void whenPickupServiceTimeIsNotSet_itShouldBeZero() { Shipment s = Shipment.Builder.newInstance("s") - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); assertEquals(0.0, s.getPickupServiceTime(), 0.01); } @Test public void whenDeliveryServiceTimeIsNotSet_itShouldBeZero() { Shipment s = Shipment.Builder.newInstance("s") - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); assertEquals(0.0, s.getDeliveryServiceTime(), 0.01); } @Test public void whenPickupServiceTimeIsSet_itShouldBeDoneCorrectly() { Shipment s = Shipment.Builder.newInstance("s") - .setPickupServiceTime(2.0) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setPickupServiceTime(2.0) + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); assertEquals(2.0, s.getPickupServiceTime(), 0.01); } @@ -169,13 +178,13 @@ public class ShipmentTest { public void whenPickupServiceIsSmallerThanZero_itShouldThrowException() { @SuppressWarnings("unused") Shipment s = Shipment.Builder.newInstance("s").setPickupServiceTime(-2.0) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); } @Test public void whenDeliveryServiceTimeIsSet_itShouldBeDoneCorrectly() { Shipment s = Shipment.Builder.newInstance("s").setDeliveryServiceTime(2.0) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); assertEquals(2.0, s.getDeliveryServiceTime(), 0.01); } @@ -201,7 +210,7 @@ public class ShipmentTest { @Test public void whenPickupTimeWindowIsSet_itShouldBeDoneCorrectly() { Shipment s = Shipment.Builder.newInstance("s").setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01); assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01); } @@ -222,7 +231,7 @@ public class ShipmentTest { @Test public void whenDeliveryTimeWindowIsSet_itShouldBeDoneCorrectly() { Shipment s = Shipment.Builder.newInstance("s").setDeliveryTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01); assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01); } @@ -230,7 +239,7 @@ public class ShipmentTest { @Test public void whenUsingAddDeliveryTimeWindow_itShouldBeDoneCorrectly() { Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01); assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01); } @@ -238,7 +247,7 @@ public class ShipmentTest { @Test public void whenUsingAddDeliveryTimeWindow2_itShouldBeDoneCorrectly() { Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(1, 2) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01); assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01); } @@ -248,7 +257,7 @@ public class ShipmentTest { TimeWindow tw1 = TimeWindow.newInstance(1,2); TimeWindow tw2 = TimeWindow.newInstance(4,5); Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(tw1).addDeliveryTimeWindow(tw2) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); assertEquals(s.getDeliveryTimeWindows().size(),2); assertThat(s.getDeliveryTimeWindows(),hasItem(is(tw1))); assertThat(s.getDeliveryTimeWindows(),hasItem(is(tw2))); @@ -257,7 +266,7 @@ public class ShipmentTest { @Test(expected = IllegalArgumentException.class) public void whenAddingMultipleOverlappingDeliveryTimeWindows_itShouldThrowException() { Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(1, 3).addDeliveryTimeWindow(2,5) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01); assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01); } @@ -267,7 +276,7 @@ public class ShipmentTest { @Test public void whenUsingAddPickupTimeWindow_itShouldBeDoneCorrectly() { Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01); assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01); } @@ -275,7 +284,7 @@ public class ShipmentTest { @Test public void whenUsingAddPickupTimeWindow2_itShouldBeDoneCorrectly() { Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(1, 2) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01); assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01); } @@ -285,7 +294,7 @@ public class ShipmentTest { TimeWindow tw1 = TimeWindow.newInstance(1,2); TimeWindow tw2 = TimeWindow.newInstance(4,5); Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(tw1).addPickupTimeWindow(tw2) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); assertEquals(s.getPickupTimeWindows().size(),2); assertThat(s.getPickupTimeWindows(), hasItem(is(tw1))); assertThat(s.getPickupTimeWindows(), hasItem(is(tw2))); @@ -294,7 +303,7 @@ public class ShipmentTest { @Test(expected = IllegalArgumentException.class) public void whenAddingMultipleOverlappingPickupTimeWindows_itShouldThrowException() { Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(1, 3).addPickupTimeWindow(2,5) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01); assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01); } @@ -305,26 +314,26 @@ public class ShipmentTest { public void whenShipmentHasNegativeCapacityVal_throwIllegalStateExpception() { @SuppressWarnings("unused") Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("foo").build()) - .setDeliveryLocation(TestUtils.loc("foofoo")) - .addSizeDimension(0, -2) - .build(); + .setDeliveryLocation(TestUtils.loc("foofoo")) + .addSizeDimension(0, -2) + .build(); } @Test public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() { Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("foo").build()) - .setDeliveryLocation(TestUtils.loc("foofoo")) - .addSizeDimension(0, 2) - .addSizeDimension(1, 4) - .build(); + .setDeliveryLocation(TestUtils.loc("foofoo")) + .addSizeDimension(0, 2) + .addSizeDimension(1, 4) + .build(); assertEquals(2, one.getSize().getNuOfDimensions()); } @Test public void whenShipmentIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() { Shipment one = Shipment.Builder.newInstance("s") - .setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build()) - .setDeliveryLocation(TestUtils.loc("foofoo")).build(); + .setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build()) + .setDeliveryLocation(TestUtils.loc("foofoo")).build(); assertEquals(1, one.getSize().getNuOfDimensions()); assertEquals(0, one.getSize().get(0)); } @@ -332,8 +341,8 @@ public class ShipmentTest { @Test public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() { Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 1) - .setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build()) - .setDeliveryLocation(TestUtils.loc("foofoo")).build(); + .setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build()) + .setDeliveryLocation(TestUtils.loc("foofoo")).build(); assertEquals(1, one.getSize().getNuOfDimensions()); assertEquals(1, one.getSize().get(0)); } @@ -341,8 +350,8 @@ public class ShipmentTest { @Test public void whenAddingSkills_theyShouldBeAddedCorrectly() { Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build()) - .setDeliveryLocation(TestUtils.loc("delLoc")) - .addRequiredSkill("drill").addRequiredSkill("screwdriver").build(); + .setDeliveryLocation(TestUtils.loc("delLoc")) + .addRequiredSkill("drill").addRequiredSkill("screwdriver").build(); assertTrue(s.getRequiredSkills().containsSkill("drill")); assertTrue(s.getRequiredSkills().containsSkill("drill")); assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver")); @@ -351,9 +360,9 @@ public class ShipmentTest { @Test public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() { Shipment s = Shipment.Builder.newInstance("s") - .setPickupLocation(Location.Builder.newInstance().setId("pick").build()) - .setDeliveryLocation(TestUtils.loc("del")) - .addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build(); + .setPickupLocation(Location.Builder.newInstance().setId("pick").build()) + .setDeliveryLocation(TestUtils.loc("del")) + .addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build(); assertTrue(s.getRequiredSkills().containsSkill("drill")); assertTrue(s.getRequiredSkills().containsSkill("drilL")); } @@ -361,8 +370,8 @@ public class ShipmentTest { @Test public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() { Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build()) - .setDeliveryLocation(TestUtils.loc("del")) - .addRequiredSkill("screwDriver").build(); + .setDeliveryLocation(TestUtils.loc("del")) + .addRequiredSkill("screwDriver").build(); assertFalse(s.getRequiredSkills().containsSkill("drill")); assertFalse(s.getRequiredSkills().containsSkill("drilL")); } @@ -370,15 +379,15 @@ public class ShipmentTest { @Test public void nameShouldBeAssigned() { Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build()) - .setDeliveryLocation(TestUtils.loc("del")) - .setName("name").build(); + .setDeliveryLocation(TestUtils.loc("del")) + .setName("name").build(); assertEquals("name", s.getName()); } @Test public void whenSettingLocation_itShouldWork() { Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build()) - .setDeliveryLocation(Location.Builder.newInstance().setId("del").build()).build(); + .setDeliveryLocation(Location.Builder.newInstance().setId("del").build()).build(); assertEquals("loc", s.getPickupLocation().getId()); assertEquals("loc", s.getPickupLocation().getId()); assertEquals("del", s.getDeliveryLocation().getId()); @@ -388,49 +397,62 @@ public class ShipmentTest { @Test public void whenSettingPriorities_itShouldBeSetCorrectly(){ Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc")) - .setDeliveryLocation(Location.newInstance("loc")) - .setPriority(1).build(); + .setDeliveryLocation(Location.newInstance("loc")) + .setPriority(1).build(); Assert.assertEquals(1, s.getPriority()); } @Test public void whenSettingPriorities_itShouldBeSetCorrectly2(){ Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc")) - .setDeliveryLocation(Location.newInstance("loc")) - .setPriority(3).build(); + .setDeliveryLocation(Location.newInstance("loc")) + .setPriority(3).build(); Assert.assertEquals(3, s.getPriority()); } @Test public void whenSettingPriorities_itShouldBeSetCorrectly3() { Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc")) - .setDeliveryLocation(Location.newInstance("loc")) - .setPriority(10).build(); + .setDeliveryLocation(Location.newInstance("loc")) + .setPriority(10).build(); Assert.assertEquals(10, s.getPriority()); } @Test public void whenNotSettingPriorities_defaultShouldBe2(){ Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc")) - .setDeliveryLocation(Location.newInstance("loc")) - .build(); + .setDeliveryLocation(Location.newInstance("loc")) + .build(); Assert.assertEquals(2, s.getPriority()); } @Test(expected = IllegalArgumentException.class) public void whenSettingIncorrectPriorities_itShouldThrowException(){ Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc")) - .setDeliveryLocation(Location.newInstance("loc")) - .setPriority(30).build(); + .setDeliveryLocation(Location.newInstance("loc")) + .setPriority(30).build(); } @Test(expected = IllegalArgumentException.class) public void whenSettingIncorrectPriorities_itShouldThrowException2(){ Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc")) - .setDeliveryLocation(Location.newInstance("loc")) - .setPriority(0).build(); + .setDeliveryLocation(Location.newInstance("loc")) + .setPriority(0).build(); } + @Test + public void whenSettingUserData_itIsAssociatedWithTheJob() { + Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc")) + .setDeliveryLocation(Location.newInstance("loc")).setUserData(new HashMap()).build(); + Shipment two = Shipment.Builder.newInstance("s2").setPickupLocation(Location.newInstance("loc")) + .setDeliveryLocation(Location.newInstance("loc")).setUserData(42).build(); + Shipment three = Shipment.Builder.newInstance("s3").setPickupLocation(Location.newInstance("loc")) + .setDeliveryLocation(Location.newInstance("loc")).build(); + + assertTrue(one.getUserData() instanceof Map); + assertEquals(42, two.getUserData()); + assertNull(three.getUserData()); + } } diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleImplTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleImplTest.java index cd3f7e48..99ac6ab7 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleImplTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleImplTest.java @@ -18,12 +18,20 @@ package com.graphhopper.jsprit.core.problem.vehicle; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + import com.graphhopper.jsprit.core.problem.Location; import com.graphhopper.jsprit.core.problem.job.Break; import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow; -import org.junit.Test; - -import static org.junit.Assert.*; public class VehicleImplTest { @@ -39,10 +47,10 @@ public class VehicleImplTest { @Test public void whenAddingDriverBreak_itShouldBeAddedCorrectly() { VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build(); - Break aBreak = (Break) Break.Builder.newInstance("break").setTimeWindow(TimeWindow.newInstance(100, 200)).setServiceTime(30).build(); + Break aBreak = Break.Builder.newInstance("break").setTimeWindow(TimeWindow.newInstance(100, 200)).setServiceTime(30).build(); Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")) - .setType(type1).setEndLocation(Location.newInstance("start")) - .setBreak(aBreak).build(); + .setType(type1).setEndLocation(Location.newInstance("start")) + .setBreak(aBreak).build(); assertNotNull(v.getBreak()); assertEquals(100., v.getBreak().getTimeWindow().getStart(), 0.1); assertEquals(200., v.getBreak().getTimeWindow().getEnd(), 0.1); @@ -54,7 +62,7 @@ public class VehicleImplTest { 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(); + .addSkill("drill").addSkill("screwdriver").build(); assertTrue(v.getSkills().containsSkill("drill")); assertTrue(v.getSkills().containsSkill("drill")); assertTrue(v.getSkills().containsSkill("screwdriver")); @@ -64,7 +72,7 @@ public class VehicleImplTest { 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(); + .addSkill("drill").addSkill("screwdriver").build(); assertTrue(v.getSkills().containsSkill("drill")); assertTrue(v.getSkills().containsSkill("dRill")); assertTrue(v.getSkills().containsSkill("ScrewDriver")); @@ -233,9 +241,23 @@ public class VehicleImplTest { 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(); + .addSkill("drill").build(); assertFalse(v.getSkills().containsSkill("ScrewDriver")); } + @Test + public void whenSettingUserData_itIsAssociatedWithTheVehicle() { + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build(); + Vehicle one = VehicleImpl.Builder.newInstance("v").setType(type1) + .setStartLocation(Location.newInstance("start")).setUserData(new HashMap()).build(); + Vehicle two = VehicleImpl.Builder.newInstance("v").setType(type1) + .setStartLocation(Location.newInstance("start")).setUserData(42).build(); + Vehicle three = VehicleImpl.Builder.newInstance("v").setType(type1) + .setStartLocation(Location.newInstance("start")).build(); + + assertTrue(one.getUserData() instanceof Map); + assertEquals(42, two.getUserData()); + assertNull(three.getUserData()); + } } diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleTypeImplTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleTypeImplTest.java index 85478347..f0159376 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleTypeImplTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/vehicle/VehicleTypeImplTest.java @@ -17,9 +17,15 @@ */ package com.graphhopper.jsprit.core.problem.vehicle; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; -import static org.junit.Assert.*; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; public class VehicleTypeImplTest { @@ -32,18 +38,18 @@ public class VehicleTypeImplTest { @Test public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() { VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t") - .addCapacityDimension(0, 2) - .addCapacityDimension(1, 4) - .build(); + .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(); + .addCapacityDimension(0, 2) + .addCapacityDimension(1, 4) + .build(); assertEquals(2, type.getCapacityDimensions().get(0)); assertEquals(4, type.getCapacityDimensions().get(1)); } @@ -152,4 +158,15 @@ public class VehicleTypeImplTest { } + @Test + public void whenSettingUserData_itIsAssociatedWithTheVehicleType() { + VehicleType one = VehicleTypeImpl.Builder.newInstance("type").setUserData(new HashMap()) + .build(); + VehicleType two = VehicleTypeImpl.Builder.newInstance("type").setUserData(42).build(); + VehicleType three = VehicleTypeImpl.Builder.newInstance("type").build(); + + assertTrue(one.getUserData() instanceof Map); + assertEquals(42, two.getUserData()); + assertNull(three.getUserData()); + } }