@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof MoveProgress) { MoveProgress that = (MoveProgress) o; return (this.distance.equals(that.distance())) && (this.time.equals(that.time())) && (this.travelledNodes.equals(that.travelledNodes())); } return false; }
static void checkNoMovement(MoveProgress mp) { assertTrue(mp.travelledNodes().isEmpty()); assertEquals(0L, mp.time().getValue().longValue()); assertEquals(0d, mp.distance().getValue().doubleValue(), 0); } }
/** * Situation: <code>SW ->- tru1 ->- SE </code><br> * tru1 wants to move directly to SW, which should throw an exception since * moving backward over an directed connection is not allowed. */ @Test(expected = IllegalArgumentException.class) public void followPathFailIllegalPath1() { final TestRoadUser testRoadUser = new TestRoadUser(); model.addObjectAt(testRoadUser, SW); final Queue<Point> p = new LinkedList<Point>(Arrays.asList(SW, SE)); final MoveProgress progress = model.followPath(testRoadUser, p, timeLength(3600000)); assertEquals(1.0, progress.distance().getValue(), EPSILON); assertEquals(asList(SE), p); assertEquals(3600000, progress.time().getValue().longValue()); assertEquals(asList(SW), progress.travelledNodes()); model.followPath(testRoadUser, asPath(SW), timeLength(1)); }
.doubleValue()); totalDistance += me.pathProgress.distance().getValue().doubleValue(); totalTime += me.pathProgress.time().getValue();
.doubleValue()); totalDistance += me.pathProgress.distance().getValue().doubleValue(); totalTime += me.pathProgress.time().getValue();
.toExDistMeasure(correctedDist); mp = MoveProgress.create(distTraveled, mp.time(), mp.travelledNodes());
/** * Follow path */ @Test public void followPathAllAtOnce() { final SpeedyRoadUser agent = new SpeedyRoadUser(18000000d); // sc.from(5, TimeUnit.MS) // .to(TimeUnit.H)); model.addObjectAt(agent, SW); assertEquals(SW, model.getPosition(agent)); final Queue<Point> path = asPath(SW, SE, NE); final MoveProgress travelled = model.followPath(agent, path, timeLength(5)); assertEquals(20, travelled.distance().getValue(), EPSILON); assertEquals(4, travelled.time().getValue().longValue()); assertEquals(0, path.size()); assertEquals(NE, model.getPosition(agent)); }
@Test public void followPathAllAtOnce() { final int timeNeeded = DoubleMath.roundToInt(pathLength / speed * 1.5, RoundingMode.CEILING); final TimeLapse timeLapse = TimeLapseFactory.create(NonSI.HOUR, 0, timeNeeded); final SpeedyRoadUser agent = new SpeedyRoadUser(speed); model.addObjectAt(agent, new Point(0, 0)); assertEquals(new Point(0, 0), model.getPosition(agent)); assertEquals(5, path.size()); final MoveProgress travelled = model.followPath(agent, path, timeLapse); assertTrue(timeLapse.hasTimeLeft()); assertEquals(pathLength, travelled.distance().getValue(), DELTA); assertTrue("time spend < timeNeeded", timeNeeded > travelled.time().getValue()); assertEquals(0, path.size()); assertEquals(new Point(5, 15), model.getPosition(agent)); }
@Test public void followLongPath() { final Point A = new Point(10, 20); final Point B = new Point(10, 22); final Point C = new Point(0, 15); Graphs.addPath(graph, NE, A, B, C); final TestRoadUser ab = new TestRoadUser(); model.addObjectAt(ab, A); model.followPath(ab, asPath(B), hour()); assertEquals(A, model.getConnection(ab).get().from()); assertEquals(B, model.getConnection(ab).get().to()); final TestRoadUser bc = new TestRoadUser(); model.addObjectAt(bc, B); model.followPath(bc, asPath(C), hour()); assertEquals(B, model.getConnection(bc).get().from()); assertEquals(C, model.getConnection(bc).get().to()); final Queue<Point> path = asPath(SW, SE, NE, A, model.getPosition(ab), B, model.getPosition(bc), C); assertEquals(8, path.size()); final TestRoadUser driver1 = new TestRoadUser(); model.addObjectAt(driver1, SW); final MoveProgress pp = model.followPath(driver1, path, hour(44)); assertEquals(hour(44).getTickLength(), pp.time().getValue().longValue()); assertEquals(44, pp.distance().getValue(), EPSILON); assertEquals(asList(SW, SE, NE, A, B), pp.travelledNodes()); }
progress.time()); assertEquals(0, path.size()); assertEquals(new Point(10, 10), model.getPosition(agent));
@Test public void followPath() { final MovingRoadUser mru = new TestRoadUser(); model.addObjectAt(mru, new Point(0, 0)); final Queue<Point> path = asPath(new Point(0, 0), new Point(5, 0), new Point( 5, 5)); final MoveProgress pp = model.followPath(mru, path, hour()); assertEquals(asPath(new Point(5, 0), new Point(5, 5)), path); assertEquals(1, pp.distance().getValue(), EPSILON); assertEquals(hour().getTickLength(), pp.time().getValue(), EPSILON); assertEquals(asList(new Point(0, 0)), pp.travelledNodes()); assertTrue( Point.distance(new Point(1, 0), model.getPosition(mru)) < EPSILON); final MoveProgress pp2 = model.followPath(mru, path, hour(5)); assertEquals(asPath(new Point(5, 5)), path); assertEquals(5, pp2.distance().getValue(), EPSILON); assertEquals(hour(5).getTickLength(), pp2.time().getValue(), EPSILON); assertEquals(asList(new Point(5, 0)), pp2.travelledNodes()); assertTrue( Point.distance(new Point(5, 1), model.getPosition(mru)) < EPSILON); final MoveProgress pp3 = model.followPath(mru, path, hour(50)); assertTrue(path.isEmpty()); assertEquals(4, pp3.distance().getValue(), EPSILON); assertEquals(hour(4).getTickLength(), pp3.time().getValue(), EPSILON); assertEquals(asList(new Point(5, 5)), pp3.travelledNodes()); assertTrue( Point.distance(new Point(5, 5), model.getPosition(mru)) < EPSILON); }
pp1.toString(); assertEquals(1, pp1.distance().getValue(), EPSILON); assertEquals(hour().getTickLength(), pp1.time().getValue().longValue()); final MoveProgress pp2 = model.followPath(agent2, asPath(SW), hour(2)); assertEquals(2, pp2.distance().getValue(), EPSILON); assertEquals(hour(2).getTickLength(), pp2.time().getValue().longValue());
assertEquals(10d, progress.distance().getValue(), DELTA); assertEquals(Measure.valueOf(time, NonSI.HOUR).to(SI.MILLI(SI.SECOND)), progress.time()); assertEquals(1, path.size()); assertEquals(D, model.getPosition(agent)); assertEquals(RoadTestUtil.km(5), progress.distance()); assertEquals(Measure.valueOf(time, NonSI.HOUR).to(SI.MILLI(SI.SECOND)), progress.time()); assertEquals(0, path.size()); assertEquals(E, model.getPosition(agent));