protected static TimeLapse hour(double multiplier) { return TimeLapseFactory.create(0, (long) (60 * 60 * 1000 * multiplier)); }
public static TimeLapse ms(long end) { return ms(0, end); }
/** * Test method when parcel is already in the available state. */ @Test public void isTooEarlyAvailableState() { tick(5, 6); assertFalse(d.isTooEarly(p1, time(2))); }
final TestRoadUser tru = new TestRoadUser(); model.addObjectAt(tru, SW); model.moveTo(tru, NW, hour(1)); model.moveTo(tru, NE, hour(1)); final MoveProgress mp = model.moveTo(tru, NE, hour(38)); assertEquals(38d, mp.distance().getValue().doubleValue(), GraphRoadModelImpl.DELTA); assertEquals(asList(NW, SW, SE, NE), mp.travelledNodes()); model.moveTo(tru, SE, hour(1)); model.moveTo(tru, SW, hour(1)); graph.addConnection(SW, X, LengthData.create(1d)); final MoveProgress mp2 = model.moveTo(tru, SW, hour(10)); assertEquals(SW, model.getPosition(tru)); model.moveTo(tru, NW, hour(10)); model.moveTo(tru, SW, hour(1)); model.moveTo(tru, SE, hour(1)); final MoveProgress mp3 = model.moveTo(tru, SE, hour(18));
/** * Test illegal argument: transition state. */ @Test(expected = IllegalArgumentException.class) public void isTooEarlyTransitionStateFail() { d.setRoute(asList(p1)); tick(3, 6); assertEquals(ParcelState.PICKING_UP, pm.getParcelState(p1)); d.isTooEarly(p1, time(2)); }
/** * Tests the removal of a connection which was previously occupied. */ @Test public void testRemovePrevOccupiedCon() { final MovingRoadUser user = new TestRoadUser(); model.addObjectAt(user, SW); model.moveTo(user, NW, hour(1)); assertTrue(model.hasRoadUserOn(SW, NW)); model.moveTo(user, NE, hour(10)); assertFalse(model.hasRoadUserOn(SW, NW)); assertTrue(model.hasRoadUserOn(NW, NE)); model.getGraph().removeConnection(SW, NW); }
public static TimeLapse hour(long start, long end) { return create(NonSI.HOUR, start, end); }
/** * Helper function that constructs {@link TimeLapse} instances that allow * traveling <code>n</code> meters. * @param m * @return */ static TimeLapse meter(double m) { return ms(DoubleMath.roundToLong(3600d * m, RoundingMode.HALF_UP)); }
/** * Test illegal argument: delivered state. */ @Test(expected = IllegalArgumentException.class) public void isTooEarlyDeliveredStateFail() { d.setRoute(asList(p1, p1)); tick(0, 60); assertEquals(ParcelState.DELIVERED, pm.getParcelState(p1)); d.isTooEarly(p1, time(2)); }
model.moveTo(car, NW, hour(1)); assertThat(model.hasRoadUserOn(SW, NW)).isTrue(); assertThat(model.getRoadUsersOn(SW, NW)).containsExactly(car);
static TimeLapse time(long t) { return TimeLapseFactory.create(NonSI.HOUR, 0, t); }
verify(clock, times(0)).switchToSimulatedTime(); model.afterTick(TimeLapseFactory.ms(0, 100)); final long start = System.nanoTime(); while (model.manager.isComputing()) { verify(clock, times(0)).switchToSimulatedTime(); model.manager.checkExceptions(); model.afterTick(TimeLapseFactory.ms(100, 200)); try { Thread.sleep(10); assertThat(duration).isIn(Range.open(0.9, 1.1)); model.afterTick(TimeLapseFactory.ms(100, 200)); verify(clock, times(3)).switchToRealTime(); verify(clock, times(0)).switchToSimulatedTime(); model.afterTick(TimeLapseFactory.ms(200, 300)); verify(clock, times(3)).switchToRealTime(); verify(clock, times(1)).switchToSimulatedTime();
/** * Test definition of isTooEarly. */ @Test public void testIsTooEarly() { // traveling 1km at 30km/h should take 2 minutes assertEquals(minute(2), d.computeTravelTimeTo(new Point(1, 2), SI.MILLI(SI.SECOND))); // if we start immediately we are too early assertTrue(d.isTooEarly(p1, time(0, 10))); assertTrue(d.isTooEarly(p1, time(minute(2), minute(3)))); assertFalse(d.isTooEarly(p1, time(minute(2) + 1, minute(3) + 1))); assertFalse(d.isTooEarly(p1, time(minute(3), minute(4)))); assertFalse(d.isTooEarly(p1, time(minute(4), minute(5)))); assertFalse(d.isTooEarly(p1, time(minute(10), minute(11)))); assertTrue(d.isTooEarly(p2, time(0, 10))); assertTrue(d.isTooEarly(p2, time(minute(10) + 10, minute(11) + 10))); assertFalse(d.isTooEarly(p2, time(minute(10) + 11, minute(11) + 11))); assertFalse(d.isTooEarly(p2, time(minute(11), minute(12)))); assertFalse(d.isTooEarly(p2, time(minute(12), minute(13)))); assertFalse(d.isTooEarly(p2, time(minute(20), minute(21)))); }
/** * Tests removals when a connection is occupied. */ @Test public void testRemoveConnectionOccupied() { final MovingRoadUser user = new TestRoadUser(); model.addObjectAt(user, SW); model.moveTo(user, NW, hour(1)); // remove everything except the connection with the user on it model.getGraph().removeConnection(NW, SW); model.getGraph().removeNode(NE); model.getGraph().removeNode(SE); assertEquals(1, model.getGraph().getConnections().size()); assertEquals(2, model.getGraph().getNodes().size()); // attempt removal of occupied conn, should fail boolean fail = false; try { model.getGraph().removeConnection(SW, NW); } catch (final IllegalStateException e) { fail = true; } assertThat(fail).isEqualTo(isGraphModCheckEnabled); }
public static TimeLapse time(long start, long end) { return create(start, end); }
/** * Test the correctness of end of day definition. */ @Test public void isEndOfDayTest() { // travel time = 0 rm.removeObject(d); rm.addObjectAtSamePosition(d, depot); assertFalse(d.isEndOfDay(time(minute(0), minute(1)))); assertFalse(d.isEndOfDay(time(minute(29), minute(30)))); assertTrue(d.isEndOfDay(time(minute(30), minute(31)))); // travel time = 4 minutes from the depot at (3,5) rm.removeObject(d); rm.addObjectAt(d, new Point(5, 5)); assertFalse(d.isEndOfDay(time(minute(25), minute(26)))); assertTrue(d.isEndOfDay(time(minute(26), minute(27)))); // travel time = 4.5 minutes from the depot rm.removeObject(d); rm.addObjectAt(d, new Point(5, 5.5)); assertFalse(d.isEndOfDay(time(minute(24), minute(25)))); assertTrue(d.isEndOfDay(time(minute(25), minute(26)))); }
public static TimeLapse time(long end) { return create(0, end); }
/** * */ @Test public void brokenWaitState() { d.setRoute(asList(p1)); tick(4, 5, 30); assertEquals(d.gotoState, d.stateMachine.getCurrentState()); if (allowDelayedRouteChanges) { d.setRoute(Arrays.<Parcel>asList()); rm.moveTo(d, p1, time(minute(0), minute(10))); assertTrue(rm.equalPosition(d, p1)); pm.pickup(d, p1, time(minute(16), minute(17))); assertEquals(VehicleState.PICKING_UP, pm.getVehicleState(d)); if (diversionIsAllowed) { boolean exception = false; try { tick(5, 6); } catch (final IllegalStateException e) { exception = true; } assertTrue(exception); } } }
protected static TimeLapse hour(long multiplier) { return TimeLapseFactory.create(0, 60 * 60 * 1000 * multiplier); }