more tests + some fixes

This commit is contained in:
BetaSteward 2012-02-25 23:24:06 -05:00
parent 868d51f924
commit 9ae7ff87ea
15 changed files with 325 additions and 55 deletions

View file

@ -12,15 +12,75 @@ public class TestHomicidalBrute extends CardTestPlayerBase {
@Test
public void testCard() {
removeAllCardsFromHand(playerA);
removeAllCardsFromLibrary(playerA);
addCard(Constants.Zone.BATTLEFIELD, playerA, "Civilized Scholar");
addCard(Constants.Zone.LIBRARY, playerA, "Sejiri Merfolk");
setStopAt(2, Constants.PhaseStep.BEGIN_COMBAT);
activateAbility(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Draw a card, then discard a card. ");
setStopAt(1, Constants.PhaseStep.BEGIN_COMBAT);
execute();
assertLife(playerA, 20);
assertLife(playerB, 20);
assertPermanentCount(playerA, "Civilized Scholar", 0);
assertPermanentCount(playerA, "Homicidal Brute", 1);
assertTapped("Homicidal Brute", false);
}
@Test
public void testCardNegative() {
removeAllCardsFromHand(playerA);
removeAllCardsFromLibrary(playerA);
addCard(Constants.Zone.BATTLEFIELD, playerA, "Civilized Scholar");
addCard(Constants.Zone.LIBRARY, playerA, "Lightning Bolt");
activateAbility(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Draw a card, then discard a card. ");
setStopAt(1, Constants.PhaseStep.BEGIN_COMBAT);
execute();
assertLife(playerA, 20);
assertLife(playerB, 20);
assertPermanentCount(playerA, "Civilized Scholar", 1);
assertTapped("Civilized Scholar", true);
assertPermanentCount(playerA, "Homicidal Brute", 0);
}
@Test
public void testCardTransform() {
removeAllCardsFromHand(playerA);
removeAllCardsFromLibrary(playerA);
addCard(Constants.Zone.BATTLEFIELD, playerA, "Civilized Scholar");
addCard(Constants.Zone.LIBRARY, playerA, "Sejiri Merfolk");
activateAbility(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Draw a card, then discard a card. ");
setStopAt(2, Constants.PhaseStep.UPKEEP);
execute();
assertLife(playerA, 20);
assertLife(playerB, 20);
assertPermanentCount(playerA, "Civilized Scholar", 1);
assertTapped("Civilized Scholar", true);
assertPermanentCount(playerA, "Homicidal Brute", 0);
}
@Test
public void testCardNotTransform() {
removeAllCardsFromHand(playerA);
removeAllCardsFromLibrary(playerA);
addCard(Constants.Zone.BATTLEFIELD, playerA, "Civilized Scholar");
addCard(Constants.Zone.LIBRARY, playerA, "Sejiri Merfolk", 2);
activateAbility(3, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Draw a card, then discard a card. ");
attack(3, playerA, "Homicidal Brute");
setStopAt(4, Constants.PhaseStep.UPKEEP);
execute();
assertLife(playerA, 20);
assertLife(playerB, 15);
assertPermanentCount(playerA, "Civilized Scholar", 0);
assertPermanentCount(playerA, "Homicidal Brute", 1);
assertTapped("Homicidal Brute", true);
}
}

View file

@ -0,0 +1,59 @@
package org.mage.test.cards;
import mage.Constants;
import org.junit.Ignore;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* also tests triggered abilities that switch from one permanent to another
*
* @author BetaSteward
*
*/
public class TestNecroticPlague extends CardTestPlayerBase {
@Test
public void testCard1() {
addCard(Constants.Zone.BATTLEFIELD, playerA, "Swamp", 4);
addCard(Constants.Zone.HAND, playerA, "Necrotic Plague");
addCard(Constants.Zone.BATTLEFIELD, playerB, "Sejiri Merfolk");
castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Necrotic Plague", "Sejiri Merfolk");
setStopAt(2, Constants.PhaseStep.PRECOMBAT_MAIN);
execute();
assertLife(playerA, 20);
assertLife(playerB, 20);
assertPermanentCount(playerB, "Sejiri Merfolk", 0);
assertGraveyardCount(playerA, "Necrotic Plague", 1);
assertGraveyardCount(playerB, 1);
assertGraveyardCount(playerB, "Sejiri Merfolk", 1);
}
@Test
public void testCard2() {
addCard(Constants.Zone.BATTLEFIELD, playerA, "Swamp", 4);
addCard(Constants.Zone.BATTLEFIELD, playerA, "Goblin Deathraiders");
addCard(Constants.Zone.HAND, playerA, "Necrotic Plague");
addCard(Constants.Zone.BATTLEFIELD, playerB, "Sejiri Merfolk");
castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Necrotic Plague", "Sejiri Merfolk");
setStopAt(3, Constants.PhaseStep.PRECOMBAT_MAIN);
execute();
assertLife(playerA, 20);
assertLife(playerB, 20);
assertPermanentCount(playerA, "Goblin Deathraiders", 0);
assertPermanentCount(playerB, "Sejiri Merfolk", 0);
assertGraveyardCount(playerA, 2);
assertGraveyardCount(playerA, "Necrotic Plague", 1);
assertGraveyardCount(playerA, "Goblin Deathraiders", 1);
assertGraveyardCount(playerB, 1);
assertGraveyardCount(playerB, "Sejiri Merfolk", 1);
}
}

View file

@ -0,0 +1,61 @@
package org.mage.test.cards;
import mage.Constants;
import mage.counters.CounterType;
import mage.filter.Filter;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* also tests triggered abilities that are added to permanents
*
* @author BetaSteward
*/
public class TestTurnToFrog extends CardTestPlayerBase {
@Test
public void testCard() {
addCard(Constants.Zone.BATTLEFIELD, playerA, "Mountain", 3);
addCard(Constants.Zone.BATTLEFIELD, playerA, "Forest", 1);
addCard(Constants.Zone.BATTLEFIELD, playerA, "Raging Ravine");
addCard(Constants.Zone.BATTLEFIELD, playerB, "Island", 2);
addCard(Constants.Zone.HAND, playerB, "Turn to Frog");
activateAbility(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "{2}{R}{G}: until end of turn {this} becomes a 3/3 red and green Elemental creature with \"Whenever this creature attacks, put a +1/+1 counter on it.\" that's still a land. ");
castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerB, "Turn to Frog", "Raging Ravine");
attack(1, playerA, "Raging Ravine");
setStopAt(1, Constants.PhaseStep.END_COMBAT);
execute();
assertLife(playerA, 20);
assertLife(playerB, 19);
assertPowerToughness(playerA, "Raging Ravine", 1, 1, Filter.ComparisonScope.Any);
assertCounterCount("Raging Ravine", CounterType.P1P1, 0);
}
@Test
public void testCard2() {
addCard(Constants.Zone.BATTLEFIELD, playerA, "Mountain", 3);
addCard(Constants.Zone.BATTLEFIELD, playerA, "Forest", 1);
addCard(Constants.Zone.BATTLEFIELD, playerA, "Raging Ravine");
addCard(Constants.Zone.BATTLEFIELD, playerB, "Island", 2);
addCard(Constants.Zone.HAND, playerB, "Turn to Frog");
activateAbility(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "{2}{R}{G}: until end of turn {this} becomes a 3/3 red and green Elemental creature with \"Whenever this creature attacks, put a +1/+1 counter on it.\" that's still a land. ");
castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerB, "Turn to Frog", "Raging Ravine");
activateAbility(3, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "{2}{R}{G}: until end of turn {this} becomes a 3/3 red and green Elemental creature with \"Whenever this creature attacks, put a +1/+1 counter on it.\" that's still a land. ");
attack(3, playerA, "Raging Ravine");
setStopAt(3, Constants.PhaseStep.END_COMBAT);
execute();
assertLife(playerA, 20);
assertLife(playerB, 16);
assertPowerToughness(playerA, "Raging Ravine", 4, 4, Filter.ComparisonScope.Any);
assertCounterCount("Raging Ravine", CounterType.P1P1, 1);
}
}

View file

@ -29,6 +29,7 @@ public class TestPlayRandomGame extends MageTestBase {
private static List<String> colorChoices = Arrays.asList("bu", "bg", "br", "bw", "ug", "ur", "uw", "gr", "gw", "rw", "bur", "buw", "bug", "brg", "brw", "bgw", "wur", "wug", "wrg", "rgu");
@Test
@Ignore
public void playGames() throws GameException, FileNotFoundException {
for (int i = 1; i < 100; i++) {
logger.info("Playing game: " + i);

View file

@ -82,6 +82,20 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
}
/**
* Removes all cards from player's hand from the game.
* Usually this should be used once before initialization to set the players hand.
*
* @param player {@link Player} to remove all cards from hand.
*/
public void removeAllCardsFromHand(Player player) {
if (player.equals(playerA)) {
commandsA.put(Constants.Zone.HAND, "clear");
} else if (player.equals(playerB)) {
commandsB.put(Constants.Zone.HAND, "clear");
}
}
/**
* Add a card to specified zone of specified player.
*
* @param gameZone {@link Constants.Zone} to add cards to.
@ -361,16 +375,38 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
* @param count Expected count.
*/
public void assertCounterCount(String cardName, CounterType type, int count) throws AssertionError {
int actualCount = 0;
for (Permanent permanent : currentGame.getBattlefield().getAllPermanents()) {
if (permanent.getName().equals(cardName)) {
actualCount += permanent.getCounters().getCount(type);
}
Permanent found = null;
for (Permanent permanent : currentGame.getBattlefield().getAllActivePermanents()) {
if (permanent.getName().equals(cardName)) {
found = permanent;
}
}
Assert.assertEquals("(Battlefield) Counter counts are not equal (" + cardName + ":" + type + ")", count, actualCount);
Assert.assertNotNull("There is no such permanent on the battlefield, cardName=" + cardName, found);
Assert.assertEquals("(Battlefield) Counter counts are not equal (" + cardName + ":" + type + ")", count, found.getCounters().getCount(type));
}
/**
* Assert whether a permanent is tapped or not
*
* @param cardName Name of the permanent that should be checked.
* @param tapped Whether the permanent is tapped or not
*/
public void assertTapped(String cardName, boolean tapped) throws AssertionError {
Permanent found = null;
for (Permanent permanent : currentGame.getBattlefield().getAllActivePermanents()) {
if (permanent.getName().equals(cardName)) {
found = permanent;
}
}
Assert.assertNotNull("There is no such permanent on the battlefield, cardName=" + cardName, found);
Assert.assertEquals("(Battlefield) Tapped state is not equal (" + cardName + ")", tapped, found.isTapped());
}
/**
* Assert card count in player's hand.
*
* @param player {@link Player} who's hand should be counted.
@ -442,6 +478,10 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
player.addAction(turnNum, step, "activate:Cast " + cardName + ";target=" + targetName);
}
public void activateAbility(int turnNum, PhaseStep step, TestPlayer player, String ability) {
player.addAction(turnNum, step, "activate:" + ability);
}
public void activateAbility(int turnNum, PhaseStep step, TestPlayer player, String ability, Player target) {
player.addAction(turnNum, step, "activate:" + ability + ";target=" + target.getName());
}