mirror of
https://github.com/correl/mage.git
synced 2025-04-14 09:09:38 -09:00
Test framework: add new real time check command to assert hand cards count;
This commit is contained in:
parent
8700da94d7
commit
4484527d04
2 changed files with 28 additions and 4 deletions
Mage.Tests/src/test/java/org/mage/test
|
@ -580,6 +580,13 @@ public class TestPlayer implements Player {
|
|||
wasProccessed = true;
|
||||
}
|
||||
|
||||
// check hand card count: card name, count
|
||||
if (params[0].equals(CHECK_COMMAND_HAND_CARD_COUNT) && params.length == 3) {
|
||||
assertHandCardCount(action, game, computerPlayer, params[1], Integer.parseInt(params[2]));
|
||||
actions.remove(action);
|
||||
wasProccessed = true;
|
||||
}
|
||||
|
||||
// check color: card name, colors, must have
|
||||
if (params[0].equals(CHECK_COMMAND_COLOR) && params.length == 4) {
|
||||
assertColor(action, game, computerPlayer, params[1], params[2], Boolean.parseBoolean(params[3]));
|
||||
|
@ -754,12 +761,12 @@ public class TestPlayer implements Player {
|
|||
List<String> data = abilities.stream()
|
||||
.map(a -> (
|
||||
a.getZone() + " -> "
|
||||
+ a.getSourceObject(game).getIdName() + " -> "
|
||||
+ (a.getRule().length() > 0
|
||||
+ a.getSourceObject(game).getIdName() + " -> "
|
||||
+ (a.getRule().length() > 0
|
||||
? a.getRule().substring(0, Math.min(20, a.getRule().length()) - 1)
|
||||
: a.getClass().getSimpleName())
|
||||
+ "..."
|
||||
))
|
||||
))
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
@ -826,6 +833,18 @@ public class TestPlayer implements Player {
|
|||
Assert.assertEquals(action.getActionName() + " - hand must contain " + count, count, player.getHand().size());
|
||||
}
|
||||
|
||||
private void assertHandCardCount(PlayerAction action, Game game, Player player, String cardName, int count) {
|
||||
int realCount = 0;
|
||||
for (UUID cardId : player.getHand()) {
|
||||
Card card = game.getCard(cardId);
|
||||
if (card != null && card.getName().equals(cardName)) {
|
||||
realCount++;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.assertEquals(action.getActionName() + " - hand must contain " + count + " cards of " + cardName, count, realCount);
|
||||
}
|
||||
|
||||
private void assertColor(PlayerAction action, Game game, Player player, String permanentName, String colors, boolean mustHave) {
|
||||
Assert.assertNotEquals(action.getActionName() + " - must setup colors", "", colors);
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
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_HAND_CARD_COUNT = "HAND_CARD_COUNT";
|
||||
public static final String CHECK_COMMAND_COLOR = "COLOR";
|
||||
public static final String CHECK_COMMAND_SUBTYPE = "SUBTYPE";
|
||||
public static final String CHECK_COMMAND_MANA_POOL = "MANA_POOL";
|
||||
|
@ -282,6 +283,10 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
check(checkName, turnNum, step, player, CHECK_COMMAND_HAND_COUNT, count.toString());
|
||||
}
|
||||
|
||||
public void checkHandCardCount(String checkName, int turnNum, PhaseStep step, TestPlayer player, String cardName, Integer count) {
|
||||
check(checkName, turnNum, step, player, CHECK_COMMAND_HAND_CARD_COUNT, cardName, count.toString());
|
||||
}
|
||||
|
||||
public void checkColor(String checkName, int turnNum, PhaseStep step, TestPlayer player, String permanentName, String colors, Boolean mustHave) {
|
||||
check(checkName, turnNum, step, player, CHECK_COMMAND_COLOR, permanentName, colors, mustHave.toString());
|
||||
}
|
||||
|
@ -1141,7 +1146,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
}
|
||||
|
||||
public void assertAllCommandsUsed() throws AssertionError {
|
||||
for(Player player : currentGame.getPlayers().values()) {
|
||||
for (Player player : currentGame.getPlayers().values()) {
|
||||
TestPlayer testPlayer = (TestPlayer) player;
|
||||
assertActionsCount(testPlayer, 0);
|
||||
assertChoicesCount(testPlayer, 0);
|
||||
|
|
Loading…
Add table
Reference in a new issue