@Test
  public void whenAddingDeliverShipmentWithVehDiffStartEndLocs_constraintShouldWork() {
    Shipment shipment =
        Shipment.Builder.newInstance("s")
            .setPickupLocation(Location.newInstance(0, 1))
            .setDeliveryLocation(Location.newInstance(4, 1))
            .build();
    VehicleImpl vehicle =
        VehicleImpl.Builder.newInstance("v")
            .setStartLocation(Location.newInstance(0, 0))
            .setEndLocation(Location.newInstance(0, 4))
            .build();
    final VehicleRoutingProblem vrp =
        VehicleRoutingProblem.Builder.newInstance().addJob(shipment).addVehicle(vehicle).build();
    VehicleRoute route = VehicleRoute.emptyRoute();
    JobInsertionContext context = new JobInsertionContext(route, shipment, vehicle, null, 0);
    context.getAssociatedActivities().add(vrp.getActivities(shipment).get(0));
    context.getAssociatedActivities().add(vrp.getActivities(shipment).get(1));
    maxDistanceMap = new HashMap<>();
    maxDistanceMap.put(vehicle, 10d);

    StateManager stateManager = new StateManager(vrp);
    MaxDistanceConstraint maxDistanceConstraint =
        new MaxDistanceConstraint(
            stateManager,
            traveledDistanceId,
            new TransportDistance() {
              @Override
              public double getDistance(
                  Location from, Location to, double departureTime, Vehicle vehicle) {
                return vrp.getTransportCosts()
                    .getTransportTime(from, to, departureTime, null, vehicle);
              }
            },
            maxDistanceMap);
    Assert.assertTrue(
        maxDistanceConstraint
            .fulfilled(
                context,
                new Start(vehicle.getStartLocation(), 0, Double.MAX_VALUE),
                vrp.getActivities(shipment).get(0),
                new End(vehicle.getEndLocation(), 0, Double.MAX_VALUE),
                0)
            .equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));

    ActivityContext pickupContext = new ActivityContext();
    pickupContext.setArrivalTime(1);
    pickupContext.setEndTime(1);
    pickupContext.setInsertionIndex(0);
    context.setRelatedActivityContext(pickupContext);
    Assert.assertTrue(
        maxDistanceConstraint
            .fulfilled(
                context,
                vrp.getActivities(shipment).get(0),
                vrp.getActivities(shipment).get(1),
                new End(vehicle.getEndLocation(), 0, Double.MAX_VALUE),
                1)
            .equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
  }
  @Test
  public void whenEndLocationIsSet_constraintShouldWork() {
    VehicleImpl vehicle =
        VehicleImpl.Builder.newInstance("v")
            .setStartLocation(Location.newInstance(0, 0))
            .setEndLocation(Location.newInstance(10, 0))
            .build();
    Pickup pickup =
        Pickup.Builder.newInstance("pickup").setLocation(Location.newInstance(10, 0)).build();
    vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).addJob(pickup).build();
    route = VehicleRoute.emptyRoute();
    maxDistanceMap = new HashMap<>();
    maxDistanceMap.put(vehicle, 5d);

    MaxDistanceConstraint maxDistanceConstraint =
        new MaxDistanceConstraint(
            new StateManager(vrp),
            traveledDistanceId,
            new TransportDistance() {
              @Override
              public double getDistance(
                  Location from, Location to, double departureTime, Vehicle vehicle) {
                return vrp.getTransportCosts()
                    .getTransportTime(from, to, departureTime, null, vehicle);
              }
            },
            maxDistanceMap);
    JobInsertionContext context = new JobInsertionContext(route, pickup, vehicle, null, 0);
    Assert.assertTrue(
        maxDistanceConstraint
            .fulfilled(
                context,
                new Start(vehicle.getStartLocation(), 0, Double.MAX_VALUE),
                vrp.getActivities(pickup).get(0),
                new End(vehicle.getEndLocation(), 0, Double.MAX_VALUE),
                0)
            .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
  }
 @Test
 public void insertNewInVehicle2ShouldBeCorrect() {
   // current distance vehicle2: 160 allowed: 200
   MaxDistanceConstraint maxDistanceConstraint =
       new MaxDistanceConstraint(
           stateManager,
           traveledDistanceId,
           new TransportDistance() {
             @Override
             public double getDistance(
                 Location from, Location to, double departureTime, Vehicle vehicle) {
               return vrp.getTransportCosts()
                   .getTransportTime(from, to, departureTime, null, vehicle);
             }
           },
           maxDistanceMap);
   JobInsertionContext context = new JobInsertionContext(route, newDelivery, vehicle2, null, 0);
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, route.getStart(), newAct(), act(0), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
   // additional distance: 20+35-15=40
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(0), newAct(), act(1), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
   // additional distance: 35+65-30=70
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(1), newAct(), act(2), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
   // additional distance: 65+100-35
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(2), newAct(), act(3), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
   // additional distance: 100+45-55
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(3), newAct(), act(4), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
   // additional distance: 45+20-25
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(4), newAct(), route.getEnd(), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
 }
 /*
     vehicle: 200.0
 vehicle (max distance): 200.0
 vehicle2: 160.0
 vehicle2 (max distance): 180.0
      */
 @Test
 public void insertNewInVehicleShouldFail() {
   MaxDistanceConstraint maxDistanceConstraint =
       new MaxDistanceConstraint(
           stateManager,
           traveledDistanceId,
           new TransportDistance() {
             @Override
             public double getDistance(
                 Location from, Location to, double departureTime, Vehicle vehicle) {
               return vrp.getTransportCosts()
                   .getTransportTime(from, to, departureTime, null, vehicle);
             }
           },
           maxDistanceMap);
   JobInsertionContext context = new JobInsertionContext(route, newDelivery, vehicle, null, 0);
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, route.getStart(), newAct(), act(0), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(0), newAct(), act(1), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(1), newAct(), act(2), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(2), newAct(), act(3), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(3), newAct(), act(4), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(4), newAct(), route.getEnd(), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
 }