From e2792881d57bd47e248767fa9b8c08378a11a7bb Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Sun, 5 Jul 2020 06:24:21 +0400 Subject: [PATCH] Test framework: added realtime command to check tapped status (checkPermanentTapped) --- .../java/org/mage/test/player/TestPlayer.java | 35 +++++++++++++++++-- .../base/impl/CardTestPlayerAPIImpl.java | 11 +++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java index 9cf06e3bfc..090884d812 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java @@ -772,6 +772,13 @@ public class TestPlayer implements Player { wasProccessed = true; } + // check permanent tapped count: target player, card name, tapped status, count + if (params[0].equals(CHECK_COMMAND_PERMANENT_TAPPED) && params.length == 5) { + assertPermanentTapped(action, game, game.getPlayer(UUID.fromString(params[1])), params[2], Boolean.parseBoolean(params[3]), Integer.parseInt(params[4])); + actions.remove(action); + wasProccessed = true; + } + // check permanent counters: card name, counter type, count if (params[0].equals(CHECK_COMMAND_PERMANENT_COUNTERS) && params.length == 4) { assertPermanentCounters(action, game, computerPlayer, params[1], CounterType.findByName(params[2]), Integer.parseInt(params[3])); @@ -1241,7 +1248,31 @@ public class TestPlayer implements Player { } } - Assert.assertEquals(action.getActionName() + " - permanent " + permanentName + " must exists in " + count + " instances", count, foundedCount); + if (foundedCount != count) { + printStart("Permanents of " + player.getName()); + printPermanents(game, game.getBattlefield().getAllActivePermanents(player.getId())); + printEnd(); + Assert.fail(action.getActionName() + " - permanent " + permanentName + " must exists in " + count + " instances"); + } + } + + private void assertPermanentTapped(PlayerAction action, Game game, Player player, String permanentName, boolean tapped, int count) { + int foundedCount = 0; + for (Permanent perm : game.getBattlefield().getAllPermanents()) { + if (hasObjectTargetNameOrAlias(perm, permanentName) + && perm.getControllerId().equals(player.getId()) + && perm.isTapped() == tapped) { + foundedCount++; + } + } + + if (foundedCount != count) { + printStart("Permanents of " + player.getName()); + printPermanents(game, game.getBattlefield().getAllActivePermanents(player.getId())); + printEnd(); + Assert.fail(action.getActionName() + " - must have " + count + (tapped ? " tapped " : " untapped ") + + "permanents with name " + permanentName + ", but founded " + foundedCount); + } } private void assertPermanentCounters(PlayerAction action, Game game, Player player, String permanentName, CounterType counterType, int count) { @@ -2039,7 +2070,7 @@ public class TestPlayer implements Player { // ignore player select if (!target.getMessage().equals("Select a starting player")) { - this.chooseStrictModeFailed("choice", game, getInfo(game.getObject(sourceId)) + "; " + getInfo(target)); + this.chooseStrictModeFailed("choice", game, getInfo(game.getObject(sourceId)) + ";\n" + getInfo(target)); } return computerPlayer.choose(outcome, target, sourceId, game, options); } diff --git a/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java b/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java index 1b1e1460a9..abb4c38c4b 100644 --- a/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java +++ b/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java @@ -92,6 +92,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement public static final String CHECK_COMMAND_ABILITY = "ABILITY"; public static final String CHECK_COMMAND_PLAYABLE_ABILITY = "PLAYABLE_ABILITY"; public static final String CHECK_COMMAND_PERMANENT_COUNT = "PERMANENT_COUNT"; + public static final String CHECK_COMMAND_PERMANENT_TAPPED = "PERMANENT_TAPPED"; public static final String CHECK_COMMAND_PERMANENT_COUNTERS = "PERMANENT_COUNTERS"; public static final String CHECK_COMMAND_EXILE_COUNT = "EXILE_COUNT"; public static final String CHECK_COMMAND_GRAVEYARD_COUNT = "GRAVEYARD_COUNT"; @@ -104,7 +105,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement public static final String CHECK_COMMAND_MANA_POOL = "MANA_POOL"; public static final String CHECK_COMMAND_ALIAS_ZONE = "ALIAS_ZONE"; public static final String CHECK_COMMAND_PLAYER_IN_GAME = "PLAYER_IN_GAME"; - public static final String CHECK_COMMAND_STACK_SIZE = "STACK_COUNT"; + public static final String CHECK_COMMAND_STACK_SIZE = "STACK_SIZE"; public static final String CHECK_COMMAND_STACK_OBJECT = "STACK_OBJECT"; // TODO: add target player param to commands @@ -374,6 +375,14 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement check(checkName, turnNum, step, player, CHECK_COMMAND_PERMANENT_COUNT, targetPlayer.getId().toString(), permanentName, count.toString()); } + public void checkPermanentTapped(String checkName, int turnNum, PhaseStep step, TestPlayer player, String permanentName, Boolean tapped, Integer count) { + checkPermanentTapped(checkName, turnNum, step, player, player, permanentName, tapped, count); + } + + public void checkPermanentTapped(String checkName, int turnNum, PhaseStep step, TestPlayer player, TestPlayer targetPlayer, String permanentName, Boolean tapped, Integer count) { + check(checkName, turnNum, step, player, CHECK_COMMAND_PERMANENT_TAPPED, targetPlayer.getId().toString(), permanentName, tapped.toString(), count.toString()); + } + public void checkPermanentCounters(String checkName, int turnNum, PhaseStep step, TestPlayer player, String permanentName, CounterType counterType, Integer count) { check(checkName, turnNum, step, player, CHECK_COMMAND_PERMANENT_COUNTERS, permanentName, counterType.toString(), count.toString()); }