mirror of
https://github.com/magefree/mage.git
synced 2025-12-23 03:51:58 -08:00
Test framework: added realtime check for playable ability
This commit is contained in:
parent
04f78500eb
commit
cac761e45d
3 changed files with 121 additions and 7 deletions
|
|
@ -10,6 +10,10 @@ import org.junit.Test;
|
||||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||||
|
|
||||||
public class AdventureCardsTest extends CardTestPlayerBase {
|
public class AdventureCardsTest extends CardTestPlayerBase {
|
||||||
|
|
||||||
|
String abilityBrazenBorrowerMainCast = "Cast Brazen Borrower";
|
||||||
|
String abilityBrazenBorrowerAdventureCast = "Cast Petty Theft";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCastTreatsToShare() {
|
public void testCastTreatsToShare() {
|
||||||
/*
|
/*
|
||||||
|
|
@ -532,4 +536,78 @@ public class AdventureCardsTest extends CardTestPlayerBase {
|
||||||
assertExileCount(playerA, "Curious Pair", 1);
|
assertExileCount(playerA, "Curious Pair", 1);
|
||||||
assertGraveyardCount(playerA, 0);
|
assertGraveyardCount(playerA, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_PlayableAbiities_NoneByMana() {
|
||||||
|
|
||||||
|
addCard(Zone.HAND, playerA, "Brazen Borrower", 1);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Island", 1);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 1);
|
||||||
|
|
||||||
|
// no playable by mana
|
||||||
|
checkPlayableAbility("main", 1, PhaseStep.PRECOMBAT_MAIN, playerA, abilityBrazenBorrowerMainCast, false);
|
||||||
|
checkPlayableAbility("adventure", 1, PhaseStep.PRECOMBAT_MAIN, playerA, abilityBrazenBorrowerAdventureCast, false);
|
||||||
|
|
||||||
|
setStrictChooseMode(true);
|
||||||
|
setStopAt(1, PhaseStep.POSTCOMBAT_MAIN);
|
||||||
|
execute();
|
||||||
|
assertAllCommandsUsed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_PlayableAbiities_NoneByTarget() {
|
||||||
|
// Brazen Borrower {1}{U}{U}
|
||||||
|
// Petty Theft {1}{U} Return target nonland permanent an opponent controls to its owner’s hand.
|
||||||
|
|
||||||
|
addCard(Zone.HAND, playerA, "Brazen Borrower", 1);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Island", 2);
|
||||||
|
//addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 1);
|
||||||
|
|
||||||
|
// no playable by wrong target
|
||||||
|
checkPlayableAbility("main", 1, PhaseStep.PRECOMBAT_MAIN, playerA, abilityBrazenBorrowerMainCast, false);
|
||||||
|
checkPlayableAbility("adventure", 1, PhaseStep.PRECOMBAT_MAIN, playerA, abilityBrazenBorrowerAdventureCast, false);
|
||||||
|
|
||||||
|
setStrictChooseMode(true);
|
||||||
|
setStopAt(1, PhaseStep.POSTCOMBAT_MAIN);
|
||||||
|
execute();
|
||||||
|
assertAllCommandsUsed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_PlayableAbiities_OnlyAdventure() {
|
||||||
|
// Brazen Borrower {1}{U}{U}
|
||||||
|
// Petty Theft {1}{U} Return target nonland permanent an opponent controls to its owner’s hand.
|
||||||
|
|
||||||
|
addCard(Zone.HAND, playerA, "Brazen Borrower", 1);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Island", 2);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 1);
|
||||||
|
|
||||||
|
// only adventure
|
||||||
|
checkPlayableAbility("main", 1, PhaseStep.PRECOMBAT_MAIN, playerA, abilityBrazenBorrowerMainCast, false);
|
||||||
|
checkPlayableAbility("adventure", 1, PhaseStep.PRECOMBAT_MAIN, playerA, abilityBrazenBorrowerAdventureCast, true);
|
||||||
|
|
||||||
|
setStrictChooseMode(true);
|
||||||
|
setStopAt(1, PhaseStep.POSTCOMBAT_MAIN);
|
||||||
|
execute();
|
||||||
|
assertAllCommandsUsed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_PlayableAbiities_All() {
|
||||||
|
// Brazen Borrower {1}{U}{U}
|
||||||
|
// Petty Theft {1}{U} Return target nonland permanent an opponent controls to its owner’s hand.
|
||||||
|
|
||||||
|
addCard(Zone.HAND, playerA, "Brazen Borrower", 1);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Island", 3);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 1);
|
||||||
|
|
||||||
|
// all
|
||||||
|
checkPlayableAbility("main", 1, PhaseStep.PRECOMBAT_MAIN, playerA, abilityBrazenBorrowerMainCast, true);
|
||||||
|
checkPlayableAbility("adventure", 1, PhaseStep.PRECOMBAT_MAIN, playerA, abilityBrazenBorrowerAdventureCast, true);
|
||||||
|
|
||||||
|
setStrictChooseMode(true);
|
||||||
|
setStopAt(1, PhaseStep.POSTCOMBAT_MAIN);
|
||||||
|
execute();
|
||||||
|
assertAllCommandsUsed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import mage.counters.Counters;
|
||||||
import mage.designations.Designation;
|
import mage.designations.Designation;
|
||||||
import mage.designations.DesignationType;
|
import mage.designations.DesignationType;
|
||||||
import mage.filter.Filter;
|
import mage.filter.Filter;
|
||||||
|
import mage.filter.FilterMana;
|
||||||
import mage.filter.FilterPermanent;
|
import mage.filter.FilterPermanent;
|
||||||
import mage.filter.StaticFilters;
|
import mage.filter.StaticFilters;
|
||||||
import mage.filter.common.*;
|
import mage.filter.common.*;
|
||||||
|
|
@ -59,7 +60,6 @@ import java.util.*;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import mage.filter.FilterMana;
|
|
||||||
|
|
||||||
import static org.mage.test.serverside.base.impl.CardTestPlayerAPIImpl.*;
|
import static org.mage.test.serverside.base.impl.CardTestPlayerAPIImpl.*;
|
||||||
|
|
||||||
|
|
@ -652,6 +652,13 @@ public class TestPlayer implements Player {
|
||||||
wasProccessed = true;
|
wasProccessed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check playable ability: ability text, must have
|
||||||
|
if (params[0].equals(CHECK_COMMAND_PLAYABLE_ABILITY) && params.length == 3) {
|
||||||
|
assertPlayableAbility(action, game, computerPlayer, params[1], Boolean.parseBoolean(params[2]));
|
||||||
|
actions.remove(action);
|
||||||
|
wasProccessed = true;
|
||||||
|
}
|
||||||
|
|
||||||
// check battlefield count: target player, card name, count
|
// check battlefield count: target player, card name, count
|
||||||
if (params[0].equals(CHECK_COMMAND_PERMANENT_COUNT) && params.length == 4) {
|
if (params[0].equals(CHECK_COMMAND_PERMANENT_COUNT) && params.length == 4) {
|
||||||
assertPermanentCount(action, game, game.getPlayer(UUID.fromString(params[1])), params[2], Integer.parseInt(params[3]));
|
assertPermanentCount(action, game, game.getPlayer(UUID.fromString(params[1])), params[2], Integer.parseInt(params[3]));
|
||||||
|
|
@ -1000,6 +1007,30 @@ public class TestPlayer implements Player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertPlayableAbility(PlayerAction action, Game game, Player player, String abilityStartText, boolean mustHave) {
|
||||||
|
boolean founded = false;
|
||||||
|
for (Ability ability : computerPlayer.getPlayable(game, true)) {
|
||||||
|
if (ability.toString().startsWith(abilityStartText)) {
|
||||||
|
founded = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mustHave && !founded) {
|
||||||
|
printStart(action.getActionName());
|
||||||
|
printAbilities(game, computerPlayer.getPlayable(game, true));
|
||||||
|
printEnd();
|
||||||
|
Assert.fail("Must have playable ability, but not found: " + abilityStartText);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mustHave && founded) {
|
||||||
|
printStart(action.getActionName());
|
||||||
|
printAbilities(game, computerPlayer.getPlayable(game, true));
|
||||||
|
printEnd();
|
||||||
|
Assert.fail("Must not have playable ability, but found: " + abilityStartText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void assertPermanentCount(PlayerAction action, Game game, Player player, String permanentName, int count) {
|
private void assertPermanentCount(PlayerAction action, Game game, Player player, String permanentName, int count) {
|
||||||
int foundedCount = 0;
|
int foundedCount = 0;
|
||||||
for (Permanent perm : game.getBattlefield().getAllPermanents()) {
|
for (Permanent perm : game.getBattlefield().getAllPermanents()) {
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
||||||
public static final String CHECK_COMMAND_DAMAGE = "DAMAGE";
|
public static final String CHECK_COMMAND_DAMAGE = "DAMAGE";
|
||||||
public static final String CHECK_COMMAND_LIFE = "LIFE";
|
public static final String CHECK_COMMAND_LIFE = "LIFE";
|
||||||
public static final String CHECK_COMMAND_ABILITY = "ABILITY";
|
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_COUNT = "PERMANENT_COUNT";
|
||||||
public static final String CHECK_COMMAND_PERMANENT_COUNTERS = "PERMANENT_COUNTERS";
|
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_EXILE_COUNT = "EXILE_COUNT";
|
||||||
|
|
@ -318,6 +319,10 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
||||||
check(checkName, turnNum, step, player, CHECK_COMMAND_ABILITY, permanentName, abilityClass.getName(), mustHave.toString());
|
check(checkName, turnNum, step, player, CHECK_COMMAND_ABILITY, permanentName, abilityClass.getName(), mustHave.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void checkPlayableAbility(String checkName, int turnNum, PhaseStep step, TestPlayer player, String abilityStartText, Boolean mustHave) {
|
||||||
|
check(checkName, turnNum, step, player, CHECK_COMMAND_PLAYABLE_ABILITY, abilityStartText, mustHave.toString());
|
||||||
|
}
|
||||||
|
|
||||||
public void checkPermanentCount(String checkName, int turnNum, PhaseStep step, TestPlayer player, String permanentName, Integer count) {
|
public void checkPermanentCount(String checkName, int turnNum, PhaseStep step, TestPlayer player, String permanentName, Integer count) {
|
||||||
//Assert.assertNotEquals("", permanentName);
|
//Assert.assertNotEquals("", permanentName);
|
||||||
checkPermanentCount(checkName, turnNum, step, player, player, permanentName, count);
|
checkPermanentCount(checkName, turnNum, step, player, player, permanentName, count);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue