CollisionPlaneRoadModel extends PlaneRoadModel { @Override public void addObjectAt(RoadUser obj, Point pos) { if (obj instanceof MovingRoadUser) { checkArgument(!isOccupied(pos), "Cannot add an object on an occupied position: %s.", pos); blockingRegistry.addAt((MovingRoadUser) obj, pos); } super.addObjectAt(obj, pos); } protected  CollisionPlaneRoadModel(CollisionPlaneRMB b, Clock c); double getObjectRadius(); boolean isOccupied(Point pos); Point getRandomUnoccupiedPosition(RandomGenerator rng); @Override void addObjectAt(RoadUser obj, Point pos);  }
@Test public void addObjectAtOccupiedPosition() { boolean fail = false; model.addObjectAt(ru1, new Point(1, 1)); try { model.addObjectAt(ru2, new Point(1, 1)); } catch (final IllegalArgumentException e) { fail = true; assertThat(e.getMessage()) .contains("Cannot add an object on an occupied position:"); } assertThat(fail).isTrue(); }
@Test public void addRUatOccupiedPosition() { final Point loc1 = new Point(1, 1); model.addObjectAt(ru1, loc1); final ParcelRU p1 = new ParcelRU(); final ParcelRU p2 = new ParcelRU(); final ParcelRU p3 = new ParcelRU(); model.addObjectAt(p1, loc1); model.addObjectAt(p2, loc1); model.addObjectAt(p3, loc1); assertThat(model.getPosition(ru1)).isEqualTo(loc1); assertThat(model.getPosition(p1)).isEqualTo(loc1); assertThat(model.getPosition(p2)).isEqualTo(loc1); assertThat(model.getPosition(p3)).isEqualTo(loc1); assertThat(ImmutableSet.copyOf(model.getObjectPositions())).hasSize(1); }
@Test public void moveToOccupiedPosition() { model.addObjectAt(ru1, new Point(1, 1)); model.addObjectAt(ru2, new Point(2.5, 1)); final MoveProgress mp = model.moveTo(ru1, new Point(2, 1), tick()); assertThat(Point.distance(model.getPosition(ru1), new Point(1.25, 1))) .isAtMost(PlaneRoadModel.DELTA); assertThat(mp.distance().doubleValue(SI.METER)) .isWithin(PlaneRoadModel.DELTA).of(.25); final MoveProgress mp2 = model.moveTo(ru1, new Point(2, 1), tick()); assertThat(Point.distance(model.getPosition(ru1), new Point(1.5, 1))) .isAtMost(PlaneRoadModel.DELTA); assertThat(mp2.distance().doubleValue(SI.METER)) .isWithin(PlaneRoadModel.DELTA).of(.25); final MoveProgress mp1c = model.moveTo(ru1, new Point(2, 1), tick()); assertThat(Point.distance(model.getPosition(ru1), new Point(1.5, 1))) .isAtMost(PlaneRoadModel.DELTA); assertThat(mp1c.distance().doubleValue(SI.METER)) .isWithin(PlaneRoadModel.DELTA).of(0); model.addObjectAt(ru3, new Point(3.5, 2)); model.moveTo(ru3, new Point(2.5, 1), tick()); assertThat(Point.distance(model.getPosition(ru3), model.getPosition(ru2))) .isGreaterThan(1d); model.moveTo(ru3, new Point(2.5, 1), tick()); assertThat(Point.distance(model.getPosition(ru3), model.getPosition(ru2))) .isWithin(PlaneRoadModel.DELTA).of(1d); final MoveProgress mp3 = model.moveTo(ru3, new Point(2.5, 1), tick()); assertThat(mp3.distance().doubleValue(SI.METER)) .isWithin(PlaneRoadModel.DELTA).of(0d); assertThat(Point.distance(model.getPosition(ru3), model.getPosition(ru2))) .isWithin(PlaneRoadModel.DELTA).of(1d); final MoveProgress mp4 = model.moveTo(ru1, new Point(1, 1), tick()); }