@Override public ImmutableList<ImmutableList<Parcel>> solve(GlobalStateObject state) throws InterruptedException { return validateOutputs(delegateSolver.solve(validateInputs(state)), state); } }
public GlobalStateObject build() { return SolverValidator.validateInputs(buildUnsafe()); }
@Test public void validateNegativeTime() { final GlobalStateObject state = GlobalStateObject.create( ImmutableSet.<Parcel>of(), ImmutableList.<VehicleStateObject>of(), -1, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, mock(RoadModelSnapshot.class)); boolean fail = false; try { SolverValidator.validateInputs(state); } catch (final IllegalArgumentException e) { fail = true; assertThat(e.getMessage()).contains("Time must be >= 0"); } assertThat(fail).isTrue(); }
@Test(expected = IllegalArgumentException.class) public void validateParcelInTwoInventories() { final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), POINT, absent, ImmutableSet.of(p1), 0, p2, ImmutableList.<Parcel>of()); final VehicleStateObject vs2 = VehicleStateObject.create(vdto(), POINT, absent, ImmutableSet.of(p1), 0, p2, ImmutableList.<Parcel>of()); final ImmutableSet<Parcel> empty = ImmutableSet.of(); final GlobalStateObject state = GlobalStateObject.create(empty, ImmutableList.of(vs1, vs2), 0, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, mock(RoadModelSnapshot.class)); SolverValidator.validateInputs(state); }
/** * Vehicle doesn't have its cargo in its route. */ @Test(expected = IllegalArgumentException.class) public void validateInvalidCurrentRoute3() { final Point p = new Point(0, 0); final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), p, absent, ImmutableSet.of(p1), 0, p1, ImmutableList.of(p3)); final ImmutableSet<Parcel> available = ImmutableSet.of(p3); final GlobalStateObject state = GlobalStateObject.create(available, ImmutableList.of(vs1), 0, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, mock(RoadModelSnapshot.class)); SolverValidator.validateInputs(state); }
/** * Duplicate in route. */ @Test(expected = IllegalArgumentException.class) public void validateInvalidCurrentRoute5() { final Point p = new Point(0, 0); final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), p, absent, ImmutableSet.of(p1), 0, p1, ImmutableList.of(p1, p1, p3)); final ImmutableSet<Parcel> available = ImmutableSet.of(p3); final GlobalStateObject state = GlobalStateObject.create(available, ImmutableList.of(vs1), 0, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, mock(RoadModelSnapshot.class)); SolverValidator.validateInputs(state); }
/** * Only once occurence of available parcel, should occur twice. */ @Test(expected = IllegalArgumentException.class) public void validateInvalidCurrentRoute6a() { final Point p = new Point(0, 0); final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), p, absent, ImmutableSet.of(p1), 0, p1, ImmutableList.of(p1, p2)); final ImmutableSet<Parcel> available = ImmutableSet.of(p2); final GlobalStateObject state = GlobalStateObject.create(available, ImmutableList.of(vs1), 0, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, mock(RoadModelSnapshot.class)); SolverValidator.validateInputs(state); }
/** * Too many occurences of available parcel, should occur twice. */ @Test(expected = IllegalArgumentException.class) public void validateInvalidCurrentRoute6b() { final Point p = new Point(0, 0); final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), p, absent, ImmutableSet.of(p1), 0, p1, ImmutableList.of(p1, p2, p2, p2)); final ImmutableSet<Parcel> available = ImmutableSet.of(p2); final GlobalStateObject state = GlobalStateObject.create(available, ImmutableList.of(vs1), 0, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, mock(RoadModelSnapshot.class)); SolverValidator.validateInputs(state); }
/** * The first location in a route must match the destination field if not null. * In this test it is another parcel. */ @Test(expected = IllegalArgumentException.class) public void validateInvalidCurrentRoute4a() { final Point p = new Point(0, 0); final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), p, absent, ImmutableSet.of(p1), 0, p1, ImmutableList.of(p3, p1, p3)); final ImmutableSet<Parcel> available = ImmutableSet.of(p3); final GlobalStateObject state = GlobalStateObject.create(available, ImmutableList.of(vs1), 0, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, mock(RoadModelSnapshot.class)); SolverValidator.validateInputs(state); }
@Test(expected = IllegalArgumentException.class) public void valiateInputsDestinationNotInContents() { final ImmutableSet<Parcel> empty = ImmutableSet.of(); final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), POINT, absent, empty, 0, p1, ImmutableList.<Parcel>of()); final VehicleStateObject vs2 = VehicleStateObject.create(vdto(), POINT, absent, ImmutableSet.of(p2, p1), 0, p1, ImmutableList.<Parcel>of()); final GlobalStateObject state = GlobalStateObject.create(empty, ImmutableList.of(vs1, vs2), 0, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, mock(RoadModelSnapshot.class)); SolverValidator.validateInputs(state); }
@Test public void validateParcelAvailableAndInInventory() { final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), POINT, absent, ImmutableSet.of(p1), 0, p2, ImmutableList.<Parcel>of()); final GlobalStateObject state = GlobalStateObject.create( ImmutableSet.of(p1), ImmutableList.of(vs1), 0, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, mock(RoadModelSnapshot.class)); boolean fail = false; try { SolverValidator.validateInputs(state); } catch (final IllegalArgumentException e) { fail = true; assertThat(e.getMessage()).contains( "Parcels can not be available AND in the inventory of a vehicle"); } assertThat(fail).isTrue(); }
/** * The first location in a route must match the destination field if not null. * In this test the route is empty. */ @Test(expected = IllegalArgumentException.class) public void validateInvalidCurrentRoute4b() { final Point p = new Point(0, 0); final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), p, absent, ImmutableSet.<Parcel>of(), 0, p1, ImmutableList.<Parcel>of()); final ImmutableSet<Parcel> available = ImmutableSet.of(p1); final GlobalStateObject state = GlobalStateObject.create(available, ImmutableList.of(vs1), 0, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, mock(RoadModelSnapshot.class)); SolverValidator.validateInputs(state); }
@Test public void validateNegativeRemainingTime() { final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), POINT, absent, ImmutableSet.of(p1), -1, p2, ImmutableList.<Parcel>of()); final GlobalStateObject state = GlobalStateObject.create( ImmutableSet.<Parcel>of(), ImmutableList.of(vs1), 0, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, mock(RoadModelSnapshot.class)); boolean fail = false; try { SolverValidator.validateInputs(state); } catch (final IllegalArgumentException e) { assertThat(e.getMessage()) .contains("Remaining service time must be >= 0"); fail = true; } assertThat(fail).isTrue(); }
/** * Parcel 2 occurs in two different routes. */ @Test(expected = IllegalArgumentException.class) public void validateInvalidCurrentRoute2() { final Point p = new Point(0, 0); final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), p, absent, ImmutableSet.<Parcel>of(), 0, p1, ImmutableList.of(p1, p2, p1, p2)); final VehicleStateObject vs2 = VehicleStateObject.create(vdto(), p, absent, ImmutableSet.<Parcel>of(), 0, null, ImmutableList.of(p2, p2)); final ImmutableSet<Parcel> available = ImmutableSet.of(p1, p2); final GlobalStateObject state = GlobalStateObject.create(available, ImmutableList.of(vs1, vs2), 0, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, mock(RoadModelSnapshot.class)); SolverValidator.validateInputs(state); }
/** * Valid routes. */ @Test public void validateValidCurrentRoutes() { final ImmutableSet<Parcel> empty = ImmutableSet.of(); final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), POINT, absent, ImmutableSet.of(p1), 0, p1, ImmutableList.of(p1)); final VehicleStateObject vs2 = VehicleStateObject.create(vdto(), POINT, absent, ImmutableSet.of(p2), 0, null, ImmutableList.of(p2)); final VehicleStateObject vs3 = VehicleStateObject.create(vdto(), POINT, absent, empty, 0, p3, ImmutableList.<Parcel>of(p3, p3)); final ImmutableSet<Parcel> available = ImmutableSet.of(p3); final GlobalStateObject state = GlobalStateObject.create(available, ImmutableList.of(vs1, vs2, vs3), 0, SI.SECOND, SI.METERS_PER_SECOND, SI.CENTIMETER, mock(RoadModelSnapshot.class)); SolverValidator.validateInputs(state); }
/** * One route is present, one is not. */ @Test(expected = IllegalArgumentException.class) public void validateInvalidCurrentRoute1() { final Point p = new Point(0, 0); final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), p, absent, ImmutableSet.of(p1), 0, p1, ImmutableList.of(p1)); final VehicleStateObject vs2 = VehicleStateObject.create(vdto(), p, absent, ImmutableSet.of(p2), 0, null, null); final ImmutableSet<Parcel> available = ImmutableSet.of(p3); final GlobalStateObject state = GlobalStateObject.create(available, ImmutableList.of(vs1, vs2), 0, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, mock(RoadModelSnapshot.class)); SolverValidator.validateInputs(state); }
@SuppressWarnings("null") @Test public void validateCorrectInputs() { final ImmutableSet<Parcel> empty = ImmutableSet.of(); final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), POINT, absent, ImmutableSet.of(p1), 0, p1, null); final VehicleStateObject vs2 = VehicleStateObject.create(vdto(), POINT, absent, ImmutableSet.of(p2), 0, null, null); final VehicleStateObject vs3 = VehicleStateObject.create(vdto(), POINT, absent, empty, 0, p3, null); final ImmutableSet<Parcel> available = ImmutableSet.of(p3); final GlobalStateObject state = GlobalStateObject.create(available, ImmutableList.of(vs1, vs2, vs3), 0, SI.SECOND, SI.METERS_PER_SECOND, SI.CENTIMETER, mock(RoadModelSnapshot.class)); SolverValidator.validateInputs(state); }