TorusAgent implements ILocated2D { public boolean isCoLocated(TorusAgent other) { return other != null && this.x == other.x && this.y == other.y; } TorusAgent(TorusWorld world, int startX, int startY, int type); int getAgentType(); @Override Tuple2D getPosition(); @Override double distance(ILocated2D other); @Override double getX(); @Override double getY(); void move(int dx, int dy); Color getColor(); boolean isCoLocated(TorusAgent other); boolean isCoLocated(TorusAgent[] others); TorusAgent closestAgent(TorusAgent[] others); double[] distances(TorusAgent[] others); double shortestXOffset(TorusAgent torusAgent); double shortestYOffset(TorusAgent torusAgent);  }
@Test public void testIsCoLocated() { TorusAgent nullAgent = null; TorusAgent otherPred = new TorusAgent(new TorusWorld(100, 100), 48, 24, 0); TorusAgent otherPrey = new TorusAgent(new TorusWorld(100, 100), 79, 33, 1); assertTrue(prey.isCoLocated(prey)); assertTrue(prey.isCoLocated(pred)); prey.move(1, 0); assertFalse(prey.isCoLocated(pred)); prey.move(-1, 0); assertTrue(prey.isCoLocated(pred)); prey.move(0, 1); assertFalse(prey.isCoLocated(pred)); prey.move(0, -1); assertTrue(prey.isCoLocated(pred)); assertFalse(prey.isCoLocated(nullAgent)); assertFalse(prey.isCoLocated(otherPred)); assertFalse(prey.isCoLocated(otherPrey)); assertFalse(pred.isCoLocated(otherPred)); assertFalse(pred.isCoLocated(otherPrey)); }