public static TimeLapse time(long start, long end) { return create(start, end); }
protected static TimeLapse hour(double multiplier) { return TimeLapseFactory.create(0, (long) (60 * 60 * 1000 * multiplier)); }
public static TimeLapse hour(long start, long end) { return create(NonSI.HOUR, start, end); }
static TimeLapse time(long t) { return TimeLapseFactory.create(NonSI.HOUR, 0, t); }
@SuppressWarnings("unused") @Test(expected = IllegalArgumentException.class) public void constructorFail1() { create(-1, 0); }
static TimeLapse init() { final TimeLapse tl = TimeLapseFactory.create(0, 1); tl.consumeAll(); return tl; }
@SuppressWarnings("unused") @Test(expected = IllegalArgumentException.class) public void constructorFail2() { create(1, 0); }
public static TimeLapse create(long start, long end) { return create(SI.MILLI(SI.SECOND), start, end); }
@Test(expected = IllegalArgumentException.class) public void consumeFail2() { final TimeLapse tl = create(0, 10); tl.consume(11); }
@Test(expected = IllegalArgumentException.class) public void consumeFail1() { final TimeLapse tl = create(0, 10); tl.consume(-1); }
@Test public void followPathRoundingTimeCheck() { // FIXME fix this rounding time bug! final MovingRoadUser ru = new SpeedyRoadUser(1d); model.addObjectAt(ru, SW); model.followPath(ru, newLinkedList(asList(SE)), TimeLapseFactory.create(0, 36000000 - 1)); }
@Test(expected = IllegalArgumentException.class) public void testDeliverFail1() { // truck does not exist in roadmodel model.deliver(new TestVehicle(), null, TimeLapseFactory.create(0, 1)); }
public void compatibilityCheck(List<Point> t) { final MovingRoadUser truck = new TrivialRoadUser(); rm.addObjectAt(truck, t.get(0)); final double len = pathLength(t); // speed of trivial truck is 1 len per hour thus we need to travel 'len' // hours final MoveProgress progress = rm.followPath( truck, new LinkedList<Point>(t), TimeLapseFactory.create(NonSI.HOUR, 0, DoubleMath.roundToLong(len, RoundingMode.CEILING))); assertEquals(len, progress.distance().getValue(), EPSILON); }
@Test(expected = IllegalArgumentException.class) public void testPickupFail1() { // truck not in roadmodel final Vehicle truck = new TestVehicle( VehicleDTO.builder().build()); model.pickup(truck, null, TimeLapseFactory.create(0, 1)); }
static TimeLapse copy(TimeLapse tl) { final TimeLapse copy = TimeLapseFactory.create(tl.getTimeUnit(), tl.getStartTime(), tl.getEndTime()); if (tl.getTimeConsumed() > 0) { copy.consume(tl.getTimeConsumed()); } return copy; }
@Test public void moveToEventIssuerType() { final MovingRoadUser user = new TestRoadUser(); model.addObjectAt(user, SW); final ListenerEventHistory list = new ListenerEventHistory(); model.getEventAPI().addListener(list, RoadEventType.MOVE); assertTrue(list.getHistory().isEmpty()); model.moveTo(user, NW, TimeLapseFactory.create(0, 10)); assertEquals(1, list.getHistory().size()); assertEquals(RoadEventType.MOVE, list.getHistory().get(0).getEventType()); assertEquals(model, list.getHistory().get(0).getIssuer()); }
/** * Test for unreliable direct message. */ @Test public void testSendDirectMsgUnreliable() { final Agent unreliable = new Agent(new Point(5, 5), 0); model.register(unreliable); unreliable.device().send(Contents.YO, agent1); model.afterTick(TimeLapseFactory.create(0, 100)); assertTrue(agent1.device().getUnreadMessages().isEmpty()); agent1.device().send(Contents.YO, unreliable); model.afterTick(TimeLapseFactory.create(0, 100)); assertTrue(unreliable.device().getUnreadMessages().isEmpty()); }
@Test public void constructor() { final TimeLapse tl = create(0, 10); assertEquals(0, tl.getTime()); assertEquals(0, tl.getTimeConsumed()); assertEquals(10, tl.getTickLength()); assertEquals(10, tl.getTimeLeft()); assertTrue(tl.hasTimeLeft()); }
@Test(expected = IllegalArgumentException.class) public void testPickupFail2() { // package not in roadmodel final Vehicle truck = new TestVehicle( VehicleDTO.builder().startPosition(new Point(1, 1)).build()); rm.register(truck); final Parcel pack1 = Parcel.builder(new Point(0, 0), new Point(2, 2)) .neededCapacity(2d) .build(); model.pickup(truck, pack1, TimeLapseFactory.create(0, 1)); }
@Test(expected = IllegalArgumentException.class) public void testPickupFail4() { final Vehicle truck = new TestVehicle( VehicleDTO.builder().startPosition(new Point(1, 1)).build()); rm.register(truck); final Parcel pack1 = Parcel.builder(new Point(0, 0), new Point(2, 2)) .neededCapacity(2d) .build(); rm.register(pack1); rm.addObjectAtSamePosition(pack1, truck); model.register(pack1); model.pickup(truck, pack1, TimeLapseFactory.create(0, 1)); }