Tests: added realtime checks for life and exile (#4936)

This commit is contained in:
Oleg Agafonov 2018-11-13 03:38:54 +04:00
parent a4ed0f0c3b
commit cfb51def3d
2 changed files with 45 additions and 0 deletions

View file

@ -43,9 +43,11 @@ import mage.player.ai.ComputerPlayer;
import mage.players.Library;
import mage.players.ManaPool;
import mage.players.Player;
import mage.players.PlayerList;
import mage.players.net.UserData;
import mage.target.*;
import mage.target.common.*;
import org.apache.log4j.Logger;
import org.junit.Assert;
import org.junit.Ignore;
@ -64,6 +66,8 @@ import static org.mage.test.serverside.base.impl.CardTestPlayerAPIImpl.*;
@Ignore
public class TestPlayer implements Player {
private static final Logger logger = Logger.getLogger(TestPlayer.class);
private int maxCallsWithoutAction = 100;
private int foundNoAction = 0;
private boolean AIPlayer;
@ -524,6 +528,13 @@ public class TestPlayer implements Player {
checkProccessed = true;
}
// check PT: life
if (params[0].equals(CHECK_COMMAND_LIFE) && params.length == 2) {
assertLife(action, game, computerPlayer, Integer.parseInt(params[1]));
actions.remove(action);
checkProccessed = true;
}
// check ability: card name, ability class, must have
if (params[0].equals(CHECK_COMMAND_ABILITY) && params.length == 4) {
assertAbility(action, game, computerPlayer, params[1], params[2], Boolean.parseBoolean(params[3]));
@ -538,6 +549,13 @@ public class TestPlayer implements Player {
checkProccessed = true;
}
// check exile count: card name, count
if (params[0].equals(CHECK_COMMAND_EXILE_COUNT) && params.length == 3) {
assertExileCount(action, game, computerPlayer, params[1], Integer.parseInt(params[2]));
actions.remove(action);
checkProccessed = true;
}
// check hand count: count
if (params[0].equals(CHECK_COMMAND_HAND_COUNT) && params.length == 2) {
assertHandCount(action, game, computerPlayer, Integer.parseInt(params[1]));
@ -610,6 +628,11 @@ public class TestPlayer implements Player {
Toughness, perm.getToughness().getValue());
}
private void assertLife(PlayerAction action, Game game, Player player, int Life) {
Assert.assertEquals(action.getActionName() + " - " + player.getName() + " have wrong life: " + player.getLife() + " <> " + Life,
Life, player.getLife());
}
private void assertAbility(PlayerAction action, Game game, Player player, String permanentName, String abilityClass, boolean mustHave) {
Permanent perm = findPermanentWithAssert(action, game, player, permanentName);
@ -639,6 +662,17 @@ public class TestPlayer implements Player {
Assert.assertEquals(action.getActionName() + " - permanent " + permanentName + " must exists in " + count + " instances", count, foundedCount);
}
private void assertExileCount(PlayerAction action, Game game, Player player, String permanentName, int count) {
int foundedCount = 0;
for (Card card : game.getExile().getAllCards(game)) {
if (card.getName().equals(permanentName) && card.isOwnedBy(player.getId())) {
foundedCount++;
}
}
Assert.assertEquals(action.getActionName() + " - card " + permanentName + " must exists in exile zone with " + count + " instances", count, foundedCount);
}
private void assertHandCount(PlayerAction action, Game game, Player player, int count) {
Assert.assertEquals(action.getActionName() + " - hand must contain " + count, count, player.getHand().size());
}
@ -1092,6 +1126,7 @@ public class TestPlayer implements Player {
}
}
}
return computerPlayer.choose(outcome, target, sourceId, game, options);
}

View file

@ -49,8 +49,10 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
public static final String NO_TARGET = "NO_TARGET";
public static final String CHECK_COMMAND_PT = "PT";
public static final String CHECK_COMMAND_LIFE = "LIFE";
public static final String CHECK_COMMAND_ABILITY = "ABILITY";
public static final String CHECK_COMMAND_PERMANENT_COUNT = "PERMANENT_COUNT";
public static final String CHECK_COMMAND_EXILE_COUNT = "EXILE_COUNT";
public static final String CHECK_COMMAND_HAND_COUNT = "HAND_COUNT";
public static final String CHECK_COMMAND_COLOR = "COLOR";
public static final String CHECK_COMMAND_SUBTYPE = "SUBTYPE";
@ -240,6 +242,10 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
check(checkName, turnNum, step, player, CHECK_COMMAND_PT, permanentName, power.toString(), toughness.toString());
}
public void checkLife(String checkName, int turnNum, PhaseStep step, TestPlayer player, Integer life) {
check(checkName, turnNum, step, player, CHECK_COMMAND_LIFE, life.toString());
}
public void checkAbility(String checkName, int turnNum, PhaseStep step, TestPlayer player, String permanentName, Class<?> abilityClass, Boolean mustHave) {
check(checkName, turnNum, step, player, CHECK_COMMAND_ABILITY, permanentName, abilityClass.getName(), mustHave.toString());
}
@ -248,6 +254,10 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
check(checkName, turnNum, step, player, CHECK_COMMAND_PERMANENT_COUNT, permanentName, count.toString());
}
public void checkExileCount(String checkName, int turnNum, PhaseStep step, TestPlayer player, String permanentName, Integer count) {
check(checkName, turnNum, step, player, CHECK_COMMAND_EXILE_COUNT, permanentName, count.toString());
}
public void checkHandCount(String checkName, int turnNum, PhaseStep step, TestPlayer player, Integer count) {
check(checkName, turnNum, step, player, CHECK_COMMAND_HAND_COUNT, count.toString());
}