added test for continuous effects + modified tests to stop on specified turn and step

This commit is contained in:
BetaSteward 2012-02-06 10:06:25 -05:00
parent 79be305eb9
commit 4fd59f9e8c
9 changed files with 101 additions and 6 deletions

View file

@ -6,6 +6,7 @@ import mage.filter.Filter;
import mage.players.Player; import mage.players.Player;
import java.util.List; import java.util.List;
import mage.Constants.PhaseStep;
/** /**
* Interface for all test initialization and assertion operations. * Interface for all test initialization and assertion operations.
@ -82,7 +83,12 @@ public interface CardTestAPI {
*/ */
void setStopOnTurn(int turn); void setStopOnTurn(int turn);
//******* ASSERT METHODS *******/ /**
* Define the turn number and step to stop the game on.
*/
void setStopAt(int turn, PhaseStep step);
//******* ASSERT METHODS *******/
/** /**
* Assert turn number after test execution. * Assert turn number after test execution.

View file

@ -17,6 +17,7 @@ import org.mage.test.serverside.base.impl.CardTestAPIImpl;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import mage.Constants.PhaseStep;
/** /**
* Base class for testing single cards and effects. * Base class for testing single cards and effects.
@ -92,6 +93,7 @@ public abstract class CardTestBase extends CardTestAPIImpl {
currentGame = game; currentGame = game;
stopOnTurn = 2; stopOnTurn = 2;
stopAtStep = PhaseStep.UNTAP;
handCardsA.clear(); handCardsA.clear();
handCardsB.clear(); handCardsB.clear();
battlefieldCardsA.clear(); battlefieldCardsA.clear();
@ -176,6 +178,7 @@ public abstract class CardTestBase extends CardTestAPIImpl {
GameOptions gameOptions = new GameOptions(); GameOptions gameOptions = new GameOptions();
gameOptions.testMode = true; gameOptions.testMode = true;
gameOptions.stopOnTurn = stopOnTurn; gameOptions.stopOnTurn = stopOnTurn;
gameOptions.stopAtStep = stopAtStep;
currentGame.start(activePlayer.getId(), gameOptions); currentGame.start(activePlayer.getId(), gameOptions);
long t2 = System.nanoTime(); long t2 = System.nanoTime();
logger.info("Winner: " + currentGame.getWinner()); logger.info("Winner: " + currentGame.getWinner());

View file

@ -27,6 +27,7 @@ import java.io.FilenameFilter;
import java.util.*; import java.util.*;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import mage.Constants.PhaseStep;
/** /**
* Base class for all tests. * Base class for all tests.
@ -69,6 +70,8 @@ public abstract class MageTestBase {
protected static Player activePlayer = null; protected static Player activePlayer = null;
protected Integer stopOnTurn; protected Integer stopOnTurn;
protected PhaseStep stopAtStep = PhaseStep.UNTAP;
protected enum ParserState { protected enum ParserState {
INIT, INIT,

View file

@ -14,6 +14,7 @@ import org.mage.test.serverside.base.MageTestBase;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.Constants.PhaseStep;
/** /**
* API for test initialization and asserting the test results. * API for test initialization and asserting the test results.
@ -187,6 +188,15 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP
*/ */
public void setStopOnTurn(int turn) { public void setStopOnTurn(int turn) {
stopOnTurn = turn == -1 ? null : Integer.valueOf(turn); stopOnTurn = turn == -1 ? null : Integer.valueOf(turn);
stopAtStep = PhaseStep.UNTAP;
}
/**
* Define turn number and step to stop the game on.
*/
public void setStopAt(int turn, PhaseStep step) {
stopOnTurn = turn == -1 ? null : Integer.valueOf(turn);
stopAtStep = step;
} }
/** /**

View file

@ -1,5 +1,7 @@
package org.mage.test.serverside.cards.effects; package org.mage.test.serverside.cards.effects;
import mage.Constants;
import mage.Constants.PhaseStep;
import mage.filter.Filter; import mage.filter.Filter;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -21,4 +23,45 @@ public class BoostContinuousEffectTest extends CardTestBase {
checkPermanentPT(playerA, "Tine Shrike", 3, 2, Filter.ComparisonScope.Any); checkPermanentPT(playerA, "Tine Shrike", 3, 2, Filter.ComparisonScope.Any);
checkPermanentPT(playerA, "Runeclaw Bear", 2, 2, Filter.ComparisonScope.Any); checkPermanentPT(playerA, "Runeclaw Bear", 2, 2, Filter.ComparisonScope.Any);
} }
@Test
public void testHonorOfThePoor2() {
addCard(Constants.Zone.BATTLEFIELD, playerA, "Honor of the Pure");
addCard(Constants.Zone.BATTLEFIELD, playerA, "White Knight");
addCard(Constants.Zone.BATTLEFIELD, playerA, "Black Knight");
setStopAt(1, PhaseStep.CLEANUP);
execute();
assertPowerToughness(playerA, "White Knight", 3, 3, Filter.ComparisonScope.Any);
assertPowerToughness(playerA, "Black Knight", 2, 2, Filter.ComparisonScope.Any);
}
@Test
public void testHonorOfThePoor3() {
addCard(Constants.Zone.BATTLEFIELD, playerA, "Honor of the Pure");
addCard(Constants.Zone.BATTLEFIELD, playerA, "White Knight");
addCard(Constants.Zone.BATTLEFIELD, playerA, "Black Knight");
setStopAt(2, PhaseStep.CLEANUP);
execute();
assertPowerToughness(playerA, "White Knight", 3, 3, Filter.ComparisonScope.Any);
assertPowerToughness(playerA, "Black Knight", 2, 2, Filter.ComparisonScope.Any);
}
@Test
public void testGiantGrowth() {
addCard(Constants.Zone.BATTLEFIELD, playerA, "Forest");
addCard(Constants.Zone.BATTLEFIELD, playerA, "White Knight");
addCard(Constants.Zone.BATTLEFIELD, playerA, "Black Knight");
addCard(Constants.Zone.HAND, playerA, "Giant Growth");
castSpell(playerA, "Giant Growth");
addFixedTarget(playerA, "Giant Growth", "White Knight");
setStopAt(1, PhaseStep.CLEANUP);
execute();
assertPowerToughness(playerA, "White Knight", 5, 5, Filter.ComparisonScope.Any);
assertPowerToughness(playerA, "Black Knight", 2, 2, Filter.ComparisonScope.Any);
}
} }

View file

@ -78,6 +78,7 @@ public interface Game extends MageItem, Serializable {
public Collection<Card> getCards(); public Collection<Card> getCards();
public Object getCustomData(); public Object getCustomData();
public void setCustomData(Object data); public void setCustomData(Object data);
public GameOptions getOptions();
public MageObject getObject(UUID objectId); public MageObject getObject(UUID objectId);
public UUID getControllerId(UUID objectId); public UUID getControllerId(UUID objectId);
public Permanent getPermanent(UUID permanentId); public Permanent getPermanent(UUID permanentId);
@ -135,6 +136,7 @@ public interface Game extends MageItem, Serializable {
public void fireGetChoiceEvent(UUID playerId, String message, Collection<? extends ActivatedAbility> choices); public void fireGetChoiceEvent(UUID playerId, String message, Collection<? extends ActivatedAbility> choices);
public void fireGetModeEvent(UUID playerId, String message, Map<UUID, String> modes); public void fireGetModeEvent(UUID playerId, String message, Map<UUID, String> modes);
public void fireGetAmountEvent(UUID playerId, String message, int min, int max); public void fireGetAmountEvent(UUID playerId, String message, int min, int max);
public void fireChoosePileEvent(UUID playerId, List<? extends Card> pile1, List<? extends Card> pile2);
public void fireInformEvent(String message); public void fireInformEvent(String message);
public void fireUpdatePlayersEvent(); public void fireUpdatePlayersEvent();
public void informPlayers(String message); public void informPlayers(String message);

View file

@ -181,6 +181,11 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
public void setCustomData(Object data) { public void setCustomData(Object data) {
this.customData = data; this.customData = data;
} }
@Override
public GameOptions getOptions() {
return gameOptions;
}
@Override @Override
public void loadCards(Set<Card> cards, UUID ownerId) { public void loadCards(Set<Card> cards, UUID ownerId) {
@ -423,7 +428,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
} }
private boolean checkStopOnTurnOption() { private boolean checkStopOnTurnOption() {
if (gameOptions.stopOnTurn != null) { if (gameOptions.stopOnTurn != null && gameOptions.stopAtStep == PhaseStep.UNTAP) {
if (gameOptions.stopOnTurn.equals(state.getTurnNum())) { if (gameOptions.stopOnTurn.equals(state.getTurnNum())) {
winnerId = null; //DRAW winnerId = null; //DRAW
saveState(); saveState();
@ -432,7 +437,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
} }
return false; return false;
} }
protected void init(UUID choosingPlayerId, boolean testMode) { protected void init(UUID choosingPlayerId, boolean testMode) {
for (Player player: state.getPlayers().values()) { for (Player player: state.getPlayers().values()) {
player.beginTurn(this); player.beginTurn(this);
@ -1025,7 +1030,13 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
if (simulation) return; if (simulation) return;
playerQueryEventSource.choose(playerId, choice.getMessage(), choice.getChoices()); playerQueryEventSource.choose(playerId, choice.getMessage(), choice.getChoices());
} }
@Override
public void fireChoosePileEvent(UUID playerId, List<? extends Card> pile1, List<? extends Card> pile2) {
if (simulation) return;
//playerQueryEventSource.choosePile(playerId, pile1, pile2);
}
@Override @Override
public void informPlayers(String message) { public void informPlayers(String message) {
if (simulation) return; if (simulation) return;

View file

@ -1,6 +1,7 @@
package mage.game; package mage.game;
import java.io.Serializable; import java.io.Serializable;
import mage.Constants.PhaseStep;
/** /**
* Game options for Mage game. * Game options for Mage game.
@ -26,4 +27,10 @@ public class GameOptions implements Serializable {
* By default, is null meaning that game shouldn't stop on any specific turn. * By default, is null meaning that game shouldn't stop on any specific turn.
*/ */
public Integer stopOnTurn = null; public Integer stopOnTurn = null;
/**
* Stop at the end of the turn if true otherwise stop at the beginning
*/
public PhaseStep stopAtStep = PhaseStep.UNTAP;
} }

View file

@ -102,10 +102,12 @@ public abstract class Phase<T extends Phase<T>> implements Serializable {
if (beginPhase(game, activePlayerId)) { if (beginPhase(game, activePlayerId)) {
for (Step step: steps) { for (Step step: steps) {
currentStep = step;
if (!game.isSimulation())
checkStopOnStepOption(game);
if (game.isPaused() || game.isGameOver()) if (game.isPaused() || game.isGameOver())
return false; return false;
currentStep = step; if (!game.getState().getTurnMods().skipStep(activePlayerId, getStep().getType()))
if (!game.getState().getTurnMods().skipStep(activePlayerId, currentStep.getType()))
playStep(game); playStep(game);
} }
if (game.isPaused() || game.isGameOver()) if (game.isPaused() || game.isGameOver())
@ -117,6 +119,14 @@ public abstract class Phase<T extends Phase<T>> implements Serializable {
return false; return false;
} }
private void checkStopOnStepOption(Game game) {
if (game.getOptions().stopOnTurn != null && game.getOptions().stopAtStep == getStep().getType()) {
if (game.getOptions().stopOnTurn.equals(game.getState().getTurnNum())) {
game.pause();
}
}
}
public boolean resumePlay(Game game, PhaseStep stepType, boolean wasPaused) { public boolean resumePlay(Game game, PhaseStep stepType, boolean wasPaused) {
if (game.isPaused() || game.isGameOver()) if (game.isPaused() || game.isGameOver())
return false; return false;