* Added some tests.

This commit is contained in:
LevelX2 2015-09-07 16:14:57 +02:00
parent 94c0e05891
commit 9aa14cdba8
6 changed files with 305 additions and 52 deletions

View file

@ -382,4 +382,39 @@ public class ZoneChangeReplacementTest extends CardTestPlayerBase {
}
/**
* I was using Anafenza, the Foremost as Commander. She attacked and traded
* with two creatures. I moved Anafenza to the Command Zone, but the
* opponent's creatures "when {this} dies" abilities triggered. Since
* Anafenza and those creatures all received lethal damage at the same time,
* the creatures should have been exiled due to Anafenza's replacement
* effect, but I guess since the logic asks if you want to use the Command
* Zone replacement effect first, that it doesn't see her leaving the
* battlefield at the same time as the other creatures.
*
* http://blogs.magicjudges.org/rulestips/2015/05/anafenza-vs-deathmist-raptor/
*/
@Test
public void testAnafenzaExileInCombat() {
// Whenever Anafenza, the Foremost attacks, put a +1/+1 counter on another target tapped creature you control.
// If a creature card would be put into an opponent's graveyard from anywhere, exile it instead.
addCard(Zone.BATTLEFIELD, playerA, "Anafenza, the Foremost"); // 4/4
// Reach (This creature can block creatures with flying.)
addCard(Zone.BATTLEFIELD, playerB, "Skyraker Giant"); // 4/3
attack(2, playerB, "Skyraker Giant");
block(2, playerA, "Anafenza, the Foremost", "Skyraker Giant");
setStopAt(2, PhaseStep.POSTCOMBAT_MAIN);
execute();
assertLife(playerA, 20);
assertLife(playerB, 20);
assertExileCount("Skyraker Giant", 1);
assertPermanentCount(playerA, "Anafenza, the Foremost", 0);
assertGraveyardCount(playerA, "Anafenza, the Foremost", 1);
}
}

View file

@ -0,0 +1,95 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package org.mage.test.commander.duel;
import java.io.FileNotFoundException;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.GameException;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestCommanderDuelBase;
/**
*
* @author LevelX2
*/
public class AnafenzaTest extends CardTestCommanderDuelBase {
@Override
protected Game createNewGameAndPlayers() throws GameException, FileNotFoundException {
setDecknamePlayerA("CommanderAnafenza_WBG.dck"); // Commander = Anafenza, the Foremost
return super.createNewGameAndPlayers();
}
/**
* I was using Anafenza, the Foremost as Commander. She attacked and traded
* with two creatures. I moved Anafenza to the Command Zone, but the
* opponent's creatures "when {this} dies" abilities triggered. Since
* Anafenza and those creatures all received lethal damage at the same time,
* the creatures should have been exiled due to Anafenza's replacement
* effect, but I guess since the logic asks if you want to use the Command
* Zone replacement effect first, that it doesn't see her leaving the
* battlefield at the same time as the other creatures.
*
* http://blogs.magicjudges.org/rulestips/2015/05/anafenza-vs-deathmist-raptor/
*/
@Test
public void testAnafenzaExileInCombat() {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 1);
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 1);
addCard(Zone.BATTLEFIELD, playerA, "Forest", 1);
// When Runed Servitor dies, each player draws a card.
addCard(Zone.BATTLEFIELD, playerB, "Runed Servitor", 2);
// Whenever Anafenza, the Foremost attacks, put a +1/+1 counter on another target tapped creature you control.
// If a creature card would be put into an opponent's graveyard from anywhere, exile it instead.
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Anafenza, the Foremost");
attack(3, playerA, "Anafenza, the Foremost");
block(3, playerB, "Runed Servitor", "Anafenza, the Foremost");
block(3, playerB, "Runed Servitor", "Anafenza, the Foremost");
setStopAt(3, PhaseStep.POSTCOMBAT_MAIN);
execute();
assertLife(playerA, 40);
assertLife(playerB, 40);
assertExileCount("Runed Servitor", 2);
assertCommandZoneCount(playerA, "Anafenza, the Foremost", 1);
assertGraveyardCount(playerA, "Anafenza, the Foremost", 0);
assertHandCount(playerA, 1); // turn 3 draw
assertHandCount(playerB, 1); // turn 2 draw
}
}

View file

@ -8,8 +8,6 @@ import mage.filter.Filter;
import mage.players.Player;
import org.mage.test.player.TestPlayer;
/**
* Interface for all test initialization and assertion operations.
*/
@ -19,21 +17,23 @@ public interface CardTestAPI {
* Types of game result.
*/
public enum GameResult {
WON,
LOST,
DRAW
}
//******* INITIALIZATION METHODS *******/
/**
* Default game initialization params for red player (that plays with Mountains)
* Default game initialization params for red player (that plays with
* Mountains)
*/
void useRedDefault();
/**
* Removes all cards from player's library from the game.
* Usually this should be used once before initialization to form the library in certain order.
* Removes all cards from player's library from the game. Usually this
* should be used once before initialization to form the library in certain
* order.
*
* @param player {@link Player} to remove all library cards from.
*/
@ -43,7 +43,8 @@ public interface CardTestAPI {
* Add a card to specified zone of specified player.
*
* @param gameZone {@link mage.constants.Zone} to add cards to.
* @param player {@link Player} to add cards for. Use either playerA or playerB.
* @param player {@link Player} to add cards for. Use either playerA or
* playerB.
* @param cardName Card name in string format.
*/
void addCard(Zone gameZone, TestPlayer player, String cardName);
@ -52,9 +53,10 @@ public interface CardTestAPI {
* Add any amount of cards to specified zone of specified player.
*
* @param gameZone {@link mage.constants.Zone} to add cards to.
* @param player {@link Player} to add cards for. Use either playerA or playerB.
* @param player {@link Player} to add cards for. Use either playerA or
* playerB.
* @param cardName Card name in string format.
* @param count Amount of cards to be added.
* @param count Amount of cards to be added.
*/
void addCard(Zone gameZone, TestPlayer player, String cardName, int count);
@ -62,11 +64,13 @@ public interface CardTestAPI {
* Add any amount of cards to specified zone of specified player.
*
* @param gameZone {@link mage.constants.Zone} to add cards to.
* @param player {@link Player} to add cards for. Use either playerA or playerB.
* @param player {@link Player} to add cards for. Use either playerA or
* playerB.
* @param cardName Card name in string format.
* @param count Amount of cards to be added.
* @param tapped In case gameZone is Battlefield, determines whether permanent should be tapped.
* In case gameZone is other than Battlefield, {@link IllegalArgumentException} is thrown
* @param count Amount of cards to be added.
* @param tapped In case gameZone is Battlefield, determines whether
* permanent should be tapped. In case gameZone is other than Battlefield,
* {@link IllegalArgumentException} is thrown
*/
void addCard(Zone gameZone, TestPlayer player, String cardName, int count, boolean tapped);
@ -74,27 +78,27 @@ public interface CardTestAPI {
* Set player's initial life count.
*
* @param player {@link Player} to set life count for.
* @param life Life count to set.
* @param life Life count to set.
*/
void setLife(TestPlayer player, int life);
//******* GAME OPTIONS *******/
/**
* Define turn number to stop the game on.
*
* @param turn
*/
void setStopOnTurn(int turn);
/**
* Define the turn number and step to stop the game on.
*
* @param turn
* @param step
*/
void setStopAt(int turn, PhaseStep step);
//******* ASSERT METHODS *******/
/**
* Assert turn number after test execution.
*
@ -114,26 +118,26 @@ public interface CardTestAPI {
* Assert player's life count after test execution.
*
* @param player {@link Player} to get life for comparison.
* @param life Expected player's life to compare with.
* @param life Expected player's life to compare with.
*/
void assertLife(Player player, int life) throws AssertionError;
/**
* Assert creature's power and toughness by card name.
* <p/>
* Throws {@link AssertionError} in the following cases:
* 1. no such player
* 2. no such creature under player's control
* 3. depending on comparison scope:
* 3a. any: no creature under player's control with the specified p\t params
* 3b. all: there is at least one creature with the cardName with the different p\t params
* Throws {@link AssertionError} in the following cases: 1. no such player
* 2. no such creature under player's control 3. depending on comparison
* scope: 3a. any: no creature under player's control with the specified p\t
* params 3b. all: there is at least one creature with the cardName with the
* different p\t params
*
* @param player {@link Player} to get creatures for comparison.
* @param cardName Card name to compare with.
* @param power Expected power to compare with.
* @param player {@link Player} to get creatures for comparison.
* @param cardName Card name to compare with.
* @param power Expected power to compare with.
* @param toughness Expected toughness to compare with.
* @param scope {@link Filter.ComparisonScope} Use ANY, if you want "at least one creature with given name should have specified p\t"
* Use ALL, if you want "all creature with gived name should have specified p\t"
* @param scope {@link Filter.ComparisonScope} Use ANY, if you want "at
* least one creature with given name should have specified p\t" Use ALL, if
* you want "all creature with gived name should have specified p\t"
*/
void assertPowerToughness(Player player, String cardName, int power, int toughness, Filter.ComparisonScope scope)
throws AssertionError;
@ -141,13 +145,12 @@ public interface CardTestAPI {
/**
* Assert creature's abilities.
* <p/>
* Throws {@link AssertionError} in the following cases:
* 1. no such player
* 2. no such creature under player's control
* 3. there is more than one creature with such name
* Throws {@link AssertionError} in the following cases: 1. no such player
* 2. no such creature under player's control 3. there is more than one
* creature with such name
*
* @param player {@link Player} to get creatures for comparison.
* @param cardName Card name to compare with.
* @param player {@link Player} to get creatures for comparison.
* @param cardName Card name to compare with.
* @param abilities Expected abilities
*/
void assertAbilities(Player player, String cardName, List<Ability> abilities)
@ -157,7 +160,7 @@ public interface CardTestAPI {
* Assert permanent count under player's control.
*
* @param player {@link Player} which permanents should be counted.
* @param count Expected count.
* @param count Expected count.
*/
void assertPermanentCount(Player player, int count) throws AssertionError;
@ -166,7 +169,26 @@ public interface CardTestAPI {
*
* @param player {@link Player} which permanents should be counted.
* @param cardName Name of the cards that should be counted.
* @param count Expected count.
* @param count Expected count.
*/
void assertPermanentCount(Player player, String cardName, int count) throws AssertionError;
/**
* Assert command zone object count in player's command zone
*
* @param player {@link Player} which permanents should be counted.
* @param commandZoneObjectName Name of the commander or emblem that should
* be counted.
* @param count Expected count.
*/
void assertCommandZoneCount(Player player, String commandZoneObjectName, int count) throws AssertionError;
/**
* Assert emblem count under player's control
*
* @param player
* @param count
* @throws AssertionError
*/
void assertEmblemCount(Player player, int count) throws AssertionError;
}

View file

@ -577,6 +577,17 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
Assert.assertEquals("(Battlefield) Card counts are not equal (" + cardName + ")", count, actualCount);
}
@Override
public void assertCommandZoneCount(Player player, String commandZoneObjectName, int count) throws AssertionError {
int actualCount = 0;
for (CommandObject commandObject : currentGame.getState().getCommand()) {
if (commandObject.getControllerId().equals(player.getId()) && commandObject.getName().equals(commandZoneObjectName)) {
actualCount++;
}
}
Assert.assertEquals("(Battlefield) Card counts are not equal (" + commandZoneObjectName + ")", count, actualCount);
}
/**
* Assert emblem count under player's control
*
@ -584,6 +595,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
* @param count
* @throws AssertionError
*/
@Override
public void assertEmblemCount(Player player, int count) throws AssertionError {
int actualCount = 0;
for (CommandObject commandObject : currentGame.getState().getCommand()) {