TorusAgent implements ILocated2D { public double shortestYOffset(TorusAgent torusAgent) { if (torusAgent == null) { return world.height(); } return world.shortestYOffset(y, torusAgent.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 testShortestYOffset() { TorusAgent[] preys = new TorusAgent[3]; TorusAgent[] preds = new TorusAgent[3]; preds[0] = new TorusAgent(new TorusWorld(100, 100), 10, 10, 0); preds[1] = new TorusAgent(new TorusWorld(100, 100), 20, 20, 0); preds[2] = new TorusAgent(new TorusWorld(100, 100), 30, 30, 0); preys[0] = new TorusAgent(new TorusWorld(100, 100), 40, 50, 1); preys[1] = new TorusAgent(new TorusWorld(100, 100), 95, 5, 1); preys[2] = new TorusAgent(new TorusWorld(100, 100), 70, 60, 1); assertEquals(prey.shortestYOffset(prey), 0.0, doubleThreshold); assertEquals(prey.shortestYOffset(pred), 0.0, doubleThreshold); assertEquals(pred.shortestYOffset(pred), 0.0, doubleThreshold); assertEquals(pred.shortestYOffset(prey), 0.0, doubleThreshold); assertEquals(pred.shortestYOffset(preds[0]), 10.0, doubleThreshold); assertEquals(pred.shortestYOffset(preds[1]), 20.0, doubleThreshold); assertEquals(pred.shortestYOffset(preds[2]), 30.0, doubleThreshold); assertEquals(pred.shortestYOffset(preys[0]), -50.0, doubleThreshold); assertEquals(pred.shortestYOffset(preys[1]), 5.0, doubleThreshold); assertEquals(pred.shortestYOffset(preys[2]), -40.0, doubleThreshold); assertEquals(prey.shortestYOffset(preds[0]), 10.0, doubleThreshold); assertEquals(prey.shortestYOffset(preds[1]), 20.0, doubleThreshold); assertEquals(prey.shortestYOffset(preds[2]), 30.0, doubleThreshold); assertEquals(prey.shortestYOffset(preys[0]), -50.0, doubleThreshold); assertEquals(prey.shortestYOffset(preys[1]), 5.0, doubleThreshold); assertEquals(prey.shortestYOffset(preys[2]), -40.0, doubleThreshold); }