Fixing several tests. Working towards enabling assertAllCommandsUsed() inside execute().

This commit is contained in:
Alex Vasile 2022-05-15 10:51:38 -06:00
parent e955d47821
commit 2497e44182
12 changed files with 201 additions and 78 deletions

View file

@ -28,7 +28,7 @@ public class ChangelingTest extends CardTestPlayerBase {
addCard(Zone.BATTLEFIELD, playerA, "Long-Forgotten Gohei");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Woodland Changeling");
checkPlayableAbility("before", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Woodlan", false);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();

View file

@ -62,21 +62,22 @@ public class CyclingTest extends CardTestPlayerBase {
}
/**
* Cycle from graveyard or battlefield may not work
* Cycle from graveyard or battlefield should not work.
*/
@Test
public void cycleFromGraveyard() {
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 5);
// Destroy all creatures. They can't be regenerated. Draw a card for each creature destroyed this way.
// Cycling {3}{B}{B}
// When you cycle Decree of Pain, all creatures get -2/-2 until end of turn.
addCard(Zone.GRAVEYARD, playerA, "Decree of Pain");
// Protection from black
// Cycling {2} ({2}, Discard this card: Draw a card.)
addCard(Zone.BATTLEFIELD, playerB, "Disciple of Grace");
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cycling {3}{B}{B}");
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Cycling {2}");
checkPlayableAbility("before", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cycling", false);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();

View file

@ -2,6 +2,7 @@ package org.mage.test.cards.mana;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Assert;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
@ -18,22 +19,28 @@ public class ManaSourceTest extends CardTestPlayerBase {
@Test
public void testCantCastWithCreatureCard() {
// Exile Simian Spirit Guide from your hand: Add {R}.
addCard(Zone.HAND, playerB, "Simian Spirit Guide", 1);
addCard(Zone.HAND, playerA, "Simian Spirit Guide", 1);
// Spend only mana produced by creatures to cast Myr Superion.
addCard(Zone.HAND, playerB, "Myr Superion", 1); // {2}
addCard(Zone.HAND, playerA, "Myr Superion", 1); // {2}
addCard(Zone.BATTLEFIELD, playerB, "Manakin", 1);
addCard(Zone.BATTLEFIELD, playerA, "Manakin", 1);
activateManaAbility(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Exile");
castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Myr Superion");
activateManaAbility(2, PhaseStep.PRECOMBAT_MAIN, playerA, "Exile");
castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerA, "Myr Superion");
setStopAt(2, PhaseStep.BEGIN_COMBAT);
try {
execute();
assertExileCount("Simian Spirit Guide", 1);
assertPermanentCount(playerB, "Myr Superion", 0);
assertHandCount(playerB, "Myr Superion", 1);
assertPermanentCount(playerA, "Myr Superion", 0);
assertHandCount(playerA, "Myr Superion", 1);
} catch (Throwable e) {
if (!e.getMessage().contains("Player PlayerA must have 0 actions but found 1")) {
Assert.fail("must not have throw error about bad targets, but got:\n" + e.getMessage());
}
}
}
}

View file

@ -2,36 +2,51 @@ package org.mage.test.cards.replacement.canttarget;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Assert;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
* DenseFoliage: Creatures can't be the targets of spells.
* {@link mage.cards.d.DenseFoliage Dense Foliage}
* {2}{G}
* Enchantment
* Creatures can't be the targets of spells.
*
* @author Quercitron
*/
public class DenseFoliageTest extends CardTestPlayerBase {
/**
* Test spell
* Test tagrgeting spell, it shouldn't work.
*/
@Test
public void testSpellCantTarget() {
addCard(Zone.BATTLEFIELD, playerA, "Dense Foliage");
addCard(Zone.HAND, playerA, "Lightning Bolt");
addCard(Zone.BATTLEFIELD, playerA, "Dense Foliage");
addCard(Zone.BATTLEFIELD, playerA, "Mountain");
addCard(Zone.BATTLEFIELD, playerB, "Eager Cadet");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", "Eager Cadet");
// setStrictChooseMode(true);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt");
addTarget(playerA, "Eager Cadet");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
try {
execute();
assertPermanentCount(playerB, "Eager Cadet", 1);
Assert.fail("must throw exception on execute");
} catch (Throwable e) {
if (!e.getMessage().contains("setup good targets")) {
Assert.fail("must throw error about bad targets, but got:\n" + e.getMessage());
}
}
}
/**
* Tests activated ability
* Tests targeting activated ability, it should work.
*/
@Test
public void testAbilityCanTarget() {

View file

@ -4,6 +4,7 @@ import mage.constants.EmptyNames;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.counters.CounterType;
import org.junit.Assert;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
@ -13,12 +14,13 @@ import org.mage.test.serverside.base.CardTestPlayerBase;
public class CantCastTest extends CardTestPlayerBase {
/**
* I control Void Winnower. But my opponent can cast Jayemdae Tome (that's
* converted mana cost is even) They can cast other even spell. Test casting
* cost 4
* I control Void Winnower.
* But my opponent can cast Jayemdae Tome (that's converted mana cost is even).
* They can cast other even spell.
* Test casting cost 4.
*/
@Test
public void testVoidWinnower1() {
public void testVoidWinnowerEvenSpell() {
// Your opponent can't cast spells with even converted mana costs. (Zero is even.)
// Your opponents can't block with creatures with even converted mana costs.
addCard(Zone.BATTLEFIELD, playerB, "Void Winnower");
@ -30,19 +32,27 @@ public class CantCastTest extends CardTestPlayerBase {
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Jayemdae Tome"); // {4}
setStopAt(1, PhaseStep.BEGIN_COMBAT);
try {
execute();
assertAllCommandsUsed();
assertHandCount(playerA, "Jayemdae Tome", 1);
assertPermanentCount(playerA, "Jayemdae Tome", 0);
Assert.fail("must throw exception on execute");
} catch (Throwable e) {
if (!e.getMessage().contains("Player PlayerA must have 0 actions but found 1")) {
Assert.fail("must not have throw error about bad targets, but got:\n" + e.getMessage());
}
}
}
/**
* Test with X=3
* Test Blaze ({X}{R}) with X=3 so that it's total cost is even.
*/
@Test
public void testVoidWinnower2() {
public void testVoidWinnowerEvenSpellWithX() {
// Your opponent can't cast spells with even converted mana costs. (Zero is even.)
// Your opponents can't block with creatures with even converted mana costs.
addCard(Zone.BATTLEFIELD, playerB, "Void Winnower");
@ -56,19 +66,30 @@ public class CantCastTest extends CardTestPlayerBase {
setChoice(playerA, "X=3");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
// TODO: Replace these with checkPlayableAbility when the effect has been implemented so that the card is no
// longer shown as castable.
try {
execute();
assertAllCommandsUsed();
assertHandCount(playerA, "Blaze", 1);
assertLife(playerB, 20);
Assert.fail("must throw exception on execute");
} catch (Throwable e) {
if (!e.getMessage().contains("Player PlayerA must have 0 actions but found 1")) {
Assert.fail("must not have throw error about bad targets, but got:\n" + e.getMessage());
}
}
}
/**
* Test with X=4
* Test Blaze ({X}{R}) with X=4 so that it's total cost is odd.
*/
@Test
public void testVoidWinnower3() {
public void testVoidWinnowerUnevenSpellWithX() {
// Your opponent can't cast spells with even converted mana costs. (Zero is even.)
// Your opponents can't block with creatures with even converted mana costs.
addCard(Zone.BATTLEFIELD, playerB, "Void Winnower");
@ -91,6 +112,9 @@ public class CantCastTest extends CardTestPlayerBase {
}
/**
* Test mmorphing a creature.
*/
@Test
public void testVoidWinnowerWithMorph() {
// Your opponent can't cast spells with even converted mana costs. (Zero is even.)
@ -110,11 +134,17 @@ public class CantCastTest extends CardTestPlayerBase {
setChoice(playerA, true); // cast it face down as 2/2 creature
setStopAt(1, PhaseStep.BEGIN_COMBAT);
try {
execute();
assertPermanentCount(playerA, EmptyNames.FACE_DOWN_CREATURE.toString(), 0);
assertHandCount(playerA, "Pine Walker", 1);
} catch (Throwable e) {
if (!e.getMessage().contains("Player PlayerA must have 0 actions but found 1")) {
Assert.fail("must not have throw error about bad targets, but got:\n" + e.getMessage());
}
}
}
/**
@ -132,12 +162,16 @@ public class CantCastTest extends CardTestPlayerBase {
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Mox Opal");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
try {
execute();
assertHandCount(playerA, "Mox Opal", 1);
assertLife(playerB, 20);
} catch (Throwable e) {
if (!e.getMessage().contains("Player PlayerA must have 0 actions but found 1")) {
Assert.fail("must not have throw error about bad targets, but got:\n" + e.getMessage());
}
}
}
/**
@ -165,7 +199,6 @@ public class CantCastTest extends CardTestPlayerBase {
assertHandCount(playerA, "Panic", 3);
assertHandCount(playerA, 4);
assertGraveyardCount(playerA, "Panic", 1);
}
/**

View file

@ -5,9 +5,16 @@ import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
* {@link mage.cards.p.PowerWordKill Power Word Kill}
* {1}{B}
* Instant
* Destroy target non-Angel, non-Demon, non-Devil, non-Dragon creature.
*
* @author Ingmar Goudt
*/
public class PowerWordKillTest extends CardTestPlayerBase {
// Destroy target non-Angel, non-Demon, non-Devil, non-Dragon creature.
private final String powerWordKill = "Power Word Kill";
@Test
@ -28,9 +35,11 @@ public class PowerWordKillTest extends CardTestPlayerBase {
public void canNotTargetChangeling(){
addCard(Zone.HAND, playerA, powerWordKill);
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
addCard(Zone.BATTLEFIELD, playerB, "Avian Changeling");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, powerWordKill, "Avian Changeling");
checkPlayableAbility("before", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Power", false);
setStopAt(1, PhaseStep.POSTCOMBAT_MAIN);
execute();
assertPermanentCount(playerB, "Avian Changeling", 1);

View file

@ -2,10 +2,18 @@ package org.mage.test.cards.single.arb;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Assert;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
* Sen Triplets
* {2}{W}{U}{B}
* Legendary Artifact Creature Human Wizard
* At the beginning of your upkeep, choose target opponent.
* This turn, that player cant cast spells or activate abilities and plays with their hand revealed.
* You may play lands and cast spells from that players hand this turn.
*
* @author TheElk801
*/
public class SenTripletsTest extends CardTestPlayerBase {
@ -17,12 +25,19 @@ public class SenTripletsTest extends CardTestPlayerBase {
private void initTriplets() {
addCard(Zone.BATTLEFIELD, playerA, triplets);
addCard(Zone.BATTLEFIELD, playerA, "Mountain");
addCard(Zone.BATTLEFIELD, playerB, "Taiga");
addCard(Zone.HAND, playerB, bolt);
addCard(Zone.HAND, playerB, relic);
addCard(Zone.HAND, playerB, "Island");
assertAllCommandsUsed();
}
/**
* Player who cast Sen Triplets must still be able to cast spells this turn, it's only playerB who can't.
*/
@Test
public void testCastSpell() {
initTriplets();
@ -43,6 +58,9 @@ public class SenTripletsTest extends CardTestPlayerBase {
assertLife(playerB, 20 - 3);
}
/**
* Target player (playerB) can't activate abilities on turn 1 since Sen Triplets was just cast.
*/
@Test
public void testCantActivate() {
initTriplets();
@ -50,11 +68,24 @@ public class SenTripletsTest extends CardTestPlayerBase {
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerB, "{T}");
setStopAt(1, PhaseStep.END_TURN);
try {
execute();
assertAllCommandsUsed();
Assert.fail("must throw exception on execute");
} catch (Throwable e) {
if (!e.getMessage().contains("Player PlayerB must have 0 actions but found 1")) {
Assert.fail("must throw error about bad targets, but got:\n" + e.getMessage());
}
}
assertTapped("Taiga", false);
}
/**
* Target player (playerB) can't cast a spell on turn 1 since Sen Triplets was just cast.
*/
@Test
public void testCantCast() {
initTriplets();
@ -62,7 +93,17 @@ public class SenTripletsTest extends CardTestPlayerBase {
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, bolt, playerA);
setStopAt(1, PhaseStep.END_TURN);
try {
execute();
assertAllCommandsUsed();
Assert.fail("must throw exception on execute");
} catch (Throwable e) {
if (!e.getMessage().contains("Player PlayerB must have 0 actions but found 1")) {
Assert.fail("must throw error about bad targets, but got:\n" + e.getMessage());
}
}
assertHandCount(playerB, bolt, 1);
assertLife(playerA, 20);

View file

@ -30,7 +30,8 @@ public class ChampionOfLambholtTest extends CardTestPlayerBase {
addCard(Zone.BATTLEFIELD, playerB, "Plains", 5);
addCard(Zone.HAND, playerB, "Increasing Devotion");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Increasing Devotion");
checkPlayableAbility("before", 1, PhaseStep.PRECOMBAT_MAIN, playerB, "Cast Increasing", false);
// castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Increasing Devotion");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();

View file

@ -6,15 +6,21 @@ import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
* {@link mage.cards.g.GrafdiggersCage Grafdigger's Cage}
* {1}
* Artifact
* Creature cards in graveyards and libraries cant enter the battlefield.
* Players cant cast spells from graveyards or libraries.
*
* @author BetaSteward
*/
public class GrafdiggersCageTest extends CardTestPlayerBase {
/**
* Test that the flashback ability can't be used.
*/
@Test
public void testCard1() {
// Creature cards can't enter the battlefield from graveyards or libraries.
// Players can't cast cards in graveyards or libraries.
public void testFlashback() {
addCard(Zone.BATTLEFIELD, playerA, "Grafdigger's Cage");
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
@ -22,30 +28,32 @@ public class GrafdiggersCageTest extends CardTestPlayerBase {
// Flashback {1}{B}
addCard(Zone.GRAVEYARD, playerA, "Lingering Souls");
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Flashback {1}{B}");
checkPlayableAbility("flashback", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Flashback", false);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertLife(playerA, 20);
assertLife(playerB, 20);
assertPermanentCount(playerA, "Spirit Token", 0);
assertGraveyardCount(playerA, "Lingering Souls", 1);
}
/**
* Test that a creature can't be put onto the battlefield from the graveyard.
*/
@Test
public void testCard2() {
public void testBeingPutOnBattlefieldFromGraveyard() {
addCard(Zone.BATTLEFIELD, playerA, "Grafdigger's Cage");
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 5);
// Put target creature card from a graveyard onto the battlefield under your control.
// That creature is a black Zombie in addition to its other colors and types.
addCard(Zone.HAND, playerA, "Rise from the Grave", 1);
addCard(Zone.GRAVEYARD, playerA, "Craw Wurm");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Rise from the Grave", "Craw Wurm");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertLife(playerA, 20);
assertLife(playerB, 20);
assertPermanentCount(playerA, "Craw Wurm", 0);
assertGraveyardCount(playerA, "Craw Wurm", 1);
assertGraveyardCount(playerA, "Rise from the Grave", 1);
}
@ -59,24 +67,17 @@ public class GrafdiggersCageTest extends CardTestPlayerBase {
* Same thing goes for cards like Ethersworn Canonist, assuming that the flashback isn't the first non-artifact spell for the turn.
*/
@Test
public void testCard3() {
// Creature cards can't enter the battlefield from graveyards or libraries.
// Players can't cast cards in graveyards or libraries.
public void testFlashbackNonPermanent() {
addCard(Zone.BATTLEFIELD, playerA, "Grafdigger's Cage");
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 2);
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1);
// Name a nonland card. Target player reveals their hand and discards all cards with that name.
// Flashback-Sacrifice a creature. (You may cast this card from your graveyard for its flashback cost. Then exile it.)
// Flashback - Sacrifice a creature. (You may cast this card from your graveyard for its flashback cost. Then exile it.)
addCard(Zone.GRAVEYARD, playerA, "Cabal Therapy");
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Flashback");
checkPlayableAbility("flashback", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Flashback", false);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertLife(playerA, 20);
assertLife(playerB, 20);
assertPermanentCount(playerA, "Silvercoat Lion", 2);
assertGraveyardCount(playerA, "Cabal Therapy", 1);
}
}

View file

@ -61,7 +61,6 @@ public class KeranosGodOfStormsTest extends CardTestPlayerBase {
castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Keranos, God of Storms");
castSpell(2, PhaseStep.POSTCOMBAT_MAIN, playerB, "Peek", playerA); // you won't do damage because it's not the first draw this turn - Draw in draw phase was the first
addTarget(playerB, playerA); // not needed if it works correct
setStopAt(2, PhaseStep.END_TURN);
execute();

View file

@ -439,6 +439,24 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
check(checkName, turnNum, step, player, CHECK_COMMAND_ABILITY, permanentName, abilityClass.getName(), mustHave.toString());
}
/**
* Checks whether or not a given playable ability (someting that lets you cast a card) is available.
* This function will only check IF the ability is available or not, it does not check the number of times that it's available.
*
* If using with mustHave = false be very careful about spelling and options, otherwise you may get a false negative.
* It is reccomended that you set up the test so that the ability is available at the point you wish to check it,
* check it with checkPlayableAbility(..., mustHave = true), then add whatever condition would stop you from being
* able to activat the abiltiy
*
* TODO: Currently does not work
*
* @param checkName String to show up if the check fails, for display purposes only.
* @param turnNum The turn number to check on.
* @param step The step to check the ability on.
* @param player The player to be checked for the ability.
* @param abilityStartText The starting portion of the ability name.
* @param mustHave Whether the ability should be activatable of not
*/
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());
}

View file

@ -17,12 +17,10 @@ public class ProtectionFromColorTest extends CardTestPlayerBase {
// tapped White Knight with Protection from Black
addCard(Zone.BATTLEFIELD, playerB, "White Knight", 1, true);
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Destroy target tapped creature.", "White Knight");
checkPlayableAbility("test", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}", false);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
// no one should be destroyed
assertPermanentCount(playerB, "White Knight", 1);
}
@Test