StringBuilder formula) { Entity closest = findClosestEnemy(movingUnit, movingUnit.getPosition(), game); Coords toFace = closest == null ?
/** * Gives the distance to the closest enemy unit, or zero if none exist * * @param me Entity who has enemies * @param position Coords from which the closest enemy is found * @param game IGame that we're playing */ public double distanceToClosestEnemy(Entity me, Coords position, IGame game) { final String METHOD_NAME = "distanceToClosestEnemy(Entity, Coords, IGame)"; getOwner().methodBegin(BasicPathRanker.class, METHOD_NAME); try { Entity closest = findClosestEnemy(me, position, game); if (closest == null) { return 0; } return closest.getPosition().distance(position); } finally { getOwner().methodEnd(BasicPathRanker.class, METHOD_NAME); } }
Entity actual = testRanker.findClosestEnemy(me, position, mockGame); Assert.assertEquals(expected, actual); enemyList.add(unmovedMech); expected = enemyMech; actual = testRanker.findClosestEnemy(me, position, mockGame); Assert.assertEquals(expected, actual); enemyList.add(mockAero); expected = enemyMech; actual = testRanker.findClosestEnemy(me, position, mockGame); Assert.assertEquals(expected, actual);
Mockito.doReturn(mockEnemyMech1) .when(testRanker) .findClosestEnemy(Mockito.eq(mockMover), Mockito.nullable(Coords.class), Mockito.any(IGame.class)); .findClosestEnemy(Mockito.eq(mockMover), Mockito.nullable(Coords.class), Mockito.any(IGame.class)); expected = new RankedPath(-51.25, mockPath, "Calculation: " + "{fall mod [" + LOG_DECIMAL.format(0) + " = " + LOG_DECIMAL Mockito.doReturn(mockEnemyMech1) .when(testRanker) .findClosestEnemy(Mockito.eq(mockMover), Mockito.nullable(Coords.class), Mockito.any(IGame.class));