mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
added test for continuous effects + modified tests to stop on specified turn and step
This commit is contained in:
parent
79be305eb9
commit
4fd59f9e8c
9 changed files with 101 additions and 6 deletions
|
@ -6,6 +6,7 @@ import mage.filter.Filter;
|
|||
import mage.players.Player;
|
||||
|
||||
import java.util.List;
|
||||
import mage.Constants.PhaseStep;
|
||||
|
||||
/**
|
||||
* Interface for all test initialization and assertion operations.
|
||||
|
@ -82,7 +83,12 @@ public interface CardTestAPI {
|
|||
*/
|
||||
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.
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.mage.test.serverside.base.impl.CardTestAPIImpl;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import mage.Constants.PhaseStep;
|
||||
|
||||
/**
|
||||
* Base class for testing single cards and effects.
|
||||
|
@ -92,6 +93,7 @@ public abstract class CardTestBase extends CardTestAPIImpl {
|
|||
currentGame = game;
|
||||
|
||||
stopOnTurn = 2;
|
||||
stopAtStep = PhaseStep.UNTAP;
|
||||
handCardsA.clear();
|
||||
handCardsB.clear();
|
||||
battlefieldCardsA.clear();
|
||||
|
@ -176,6 +178,7 @@ public abstract class CardTestBase extends CardTestAPIImpl {
|
|||
GameOptions gameOptions = new GameOptions();
|
||||
gameOptions.testMode = true;
|
||||
gameOptions.stopOnTurn = stopOnTurn;
|
||||
gameOptions.stopAtStep = stopAtStep;
|
||||
currentGame.start(activePlayer.getId(), gameOptions);
|
||||
long t2 = System.nanoTime();
|
||||
logger.info("Winner: " + currentGame.getWinner());
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.io.FilenameFilter;
|
|||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import mage.Constants.PhaseStep;
|
||||
|
||||
/**
|
||||
* Base class for all tests.
|
||||
|
@ -69,6 +70,8 @@ public abstract class MageTestBase {
|
|||
protected static Player activePlayer = null;
|
||||
|
||||
protected Integer stopOnTurn;
|
||||
|
||||
protected PhaseStep stopAtStep = PhaseStep.UNTAP;
|
||||
|
||||
protected enum ParserState {
|
||||
INIT,
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.mage.test.serverside.base.MageTestBase;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.Constants.PhaseStep;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.mage.test.serverside.cards.effects;
|
||||
|
||||
import mage.Constants;
|
||||
import mage.Constants.PhaseStep;
|
||||
import mage.filter.Filter;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
@ -21,4 +23,45 @@ public class BoostContinuousEffectTest extends CardTestBase {
|
|||
checkPermanentPT(playerA, "Tine Shrike", 3, 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ public interface Game extends MageItem, Serializable {
|
|||
public Collection<Card> getCards();
|
||||
public Object getCustomData();
|
||||
public void setCustomData(Object data);
|
||||
public GameOptions getOptions();
|
||||
public MageObject getObject(UUID objectId);
|
||||
public UUID getControllerId(UUID objectId);
|
||||
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 fireGetModeEvent(UUID playerId, String message, Map<UUID, String> modes);
|
||||
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 fireUpdatePlayersEvent();
|
||||
public void informPlayers(String message);
|
||||
|
|
|
@ -181,6 +181,11 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
public void setCustomData(Object data) {
|
||||
this.customData = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameOptions getOptions() {
|
||||
return gameOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
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() {
|
||||
if (gameOptions.stopOnTurn != null) {
|
||||
if (gameOptions.stopOnTurn != null && gameOptions.stopAtStep == PhaseStep.UNTAP) {
|
||||
if (gameOptions.stopOnTurn.equals(state.getTurnNum())) {
|
||||
winnerId = null; //DRAW
|
||||
saveState();
|
||||
|
@ -432,7 +437,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected void init(UUID choosingPlayerId, boolean testMode) {
|
||||
for (Player player: state.getPlayers().values()) {
|
||||
player.beginTurn(this);
|
||||
|
@ -1025,7 +1030,13 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
if (simulation) return;
|
||||
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
|
||||
public void informPlayers(String message) {
|
||||
if (simulation) return;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package mage.game;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.Constants.PhaseStep;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public Integer stopOnTurn = null;
|
||||
|
||||
/**
|
||||
* Stop at the end of the turn if true otherwise stop at the beginning
|
||||
*/
|
||||
public PhaseStep stopAtStep = PhaseStep.UNTAP;
|
||||
|
||||
}
|
||||
|
|
|
@ -102,10 +102,12 @@ public abstract class Phase<T extends Phase<T>> implements Serializable {
|
|||
if (beginPhase(game, activePlayerId)) {
|
||||
|
||||
for (Step step: steps) {
|
||||
currentStep = step;
|
||||
if (!game.isSimulation())
|
||||
checkStopOnStepOption(game);
|
||||
if (game.isPaused() || game.isGameOver())
|
||||
return false;
|
||||
currentStep = step;
|
||||
if (!game.getState().getTurnMods().skipStep(activePlayerId, currentStep.getType()))
|
||||
if (!game.getState().getTurnMods().skipStep(activePlayerId, getStep().getType()))
|
||||
playStep(game);
|
||||
}
|
||||
if (game.isPaused() || game.isGameOver())
|
||||
|
@ -117,6 +119,14 @@ public abstract class Phase<T extends Phase<T>> implements Serializable {
|
|||
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) {
|
||||
if (game.isPaused() || game.isGameOver())
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue