From 6d005bae1d4239501b57fee693dc614f621d77e4 Mon Sep 17 00:00:00 2001 From: dilnu Date: Thu, 6 Feb 2020 18:55:33 -0500 Subject: [PATCH] Add tests by JayDi85 and fix TestPlayer's Targetting code so it triggers Targetted Events. --- .../mage/test/cards/copy/CopySpellTest.java | 102 ++++++++++++++---- .../java/org/mage/test/player/TestPlayer.java | 14 +-- 2 files changed, 88 insertions(+), 28 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/copy/CopySpellTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/copy/CopySpellTest.java index e43903d8eab..c780fbef4ca 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/copy/CopySpellTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/copy/CopySpellTest.java @@ -78,38 +78,98 @@ public class CopySpellTest extends CardTestPlayerBase { } @Test - public void BonecrusherGiantChangeTargets() { - // 4/3 Creature - // Whenever Bonecrusher Giant becomes the target of a spell, Bonecrusher Giant deals 2 damage to that spell's - // controller. + public void BonecrusherGiantChangeTargets_BoneTargetBoth() { + // Whenever Bonecrusher Giant becomes the target of a spell, Bonecrusher Giant deals 2 damage to that spell’s controller. addCard(Zone.BATTLEFIELD, playerA, "Bonecrusher Giant"); - // 2/2 Creature - addCard(Zone.BATTLEFIELD, playerA, "Grizzly Bears"); - // 2/1 Creature - addCard(Zone.BATTLEFIELD, playerA, "Savannah Lions"); - addCard(Zone.BATTLEFIELD, playerA, "Plains"); + // // Target creature gets +2/+2 until end of turn. - // Conspire (As you cast this spell, you may tap two untapped creatures you control that share a color with it. - // When you do, copy it and you may choose a new target for the copy.) + // Conspire (As you cast this spell, you may tap two untapped creatures you control that share a color with it. When you do, copy it and you may choose a new target for the copy.) addCard(Zone.HAND, playerA, "Barkshell Blessing"); + addCard(Zone.BATTLEFIELD, playerA, "Plains"); + addCard(Zone.BATTLEFIELD, playerA, "Grizzly Bears"); + addCard(Zone.BATTLEFIELD, playerA, "Savannah Lions"); castSpell(1, PhaseStep.UPKEEP, playerA, "Barkshell Blessing"); - addTarget(playerA, "Grizzly Bears"); - setChoice(playerA, "Yes"); - setChoice(playerA, "Grizzly Bears"); - setChoice(playerA, "Savannah Lions"); - setChoice(playerA, "Yes"); - addTarget(playerA, "Bonecrusher Giant"); + setChoice(playerA, "Yes"); // use Conspire + addTarget(playerA, "Bonecrusher Giant"); // target bone + setChoice(playerA, "Grizzly Bears"); // pay for conspire + setChoice(playerA, "Savannah Lions"); // pay for conspire + setChoice(playerA, "When you pay"); // Put Conspire on the stack first. + setChoice(playerA, "No"); // both spells target bone setStrictChooseMode(true); - setStopAt(1, PhaseStep.END_COMBAT); + setStopAt(1, PhaseStep.PRECOMBAT_MAIN); execute(); assertAllCommandsUsed(); - assertPowerToughness(playerA, "Bonecrusher Giant", 6, 5); - assertPowerToughness(playerA, "Grizzly Bears", 4, 4); + assertPowerToughness(playerA, "Bonecrusher Giant", 4 + 2 * 2, 3 + 2 * 2); + assertPowerToughness(playerA, "Grizzly Bears", 2, 2); assertPowerToughness(playerA, "Savannah Lions", 2, 1); - assertLife(playerA, 18); + assertLife(playerA, 20 - 2 * 2); // bone trigger from both spells + } + + @Test + public void BonecrusherGiantChangeTargets_BoneTargetFirst() { + // Whenever Bonecrusher Giant becomes the target of a spell, Bonecrusher Giant deals 2 damage to that spell’s controller. + addCard(Zone.BATTLEFIELD, playerA, "Bonecrusher Giant"); + // + // Target creature gets +2/+2 until end of turn. + // Conspire (As you cast this spell, you may tap two untapped creatures you control that share a color with it. When you do, copy it and you may choose a new target for the copy.) + addCard(Zone.HAND, playerA, "Barkshell Blessing"); + addCard(Zone.BATTLEFIELD, playerA, "Plains"); + addCard(Zone.BATTLEFIELD, playerA, "Grizzly Bears"); + addCard(Zone.BATTLEFIELD, playerA, "Savannah Lions"); + + castSpell(1, PhaseStep.UPKEEP, playerA, "Barkshell Blessing"); + setChoice(playerA, "Yes"); // use Conspire + addTarget(playerA, "Bonecrusher Giant"); // target bone + setChoice(playerA, "Grizzly Bears"); // pay for conspire + setChoice(playerA, "Savannah Lions"); // pay for conspire + setChoice(playerA, "When you pay"); // Put Conspire on the stack first. + setChoice(playerA, "Yes"); // new target for copy: bear + addTarget(playerA, "Grizzly Bears"); + + setStrictChooseMode(true); + setStopAt(1, PhaseStep.PRECOMBAT_MAIN); + execute(); + assertAllCommandsUsed(); + + assertPowerToughness(playerA, "Bonecrusher Giant", 4 + 2, 3 + 2); + assertPowerToughness(playerA, "Grizzly Bears", 2 + 2, 2 + 2); + assertPowerToughness(playerA, "Savannah Lions", 2, 1); + assertLife(playerA, 20 - 2); // one trigger + } + + @Test + public void BonecrusherGiantChangeTargets_BoneTargetSecond() { + // Whenever Bonecrusher Giant becomes the target of a spell, Bonecrusher Giant deals 2 damage to that spell’s controller. + addCard(Zone.BATTLEFIELD, playerA, "Bonecrusher Giant"); + // + // Target creature gets +2/+2 until end of turn. + // Conspire (As you cast this spell, you may tap two untapped creatures you control that share a color with it. When you do, copy it and you may choose a new target for the copy.) + addCard(Zone.HAND, playerA, "Barkshell Blessing"); + addCard(Zone.BATTLEFIELD, playerA, "Plains"); + addCard(Zone.BATTLEFIELD, playerA, "Grizzly Bears"); + addCard(Zone.BATTLEFIELD, playerA, "Savannah Lions"); + + castSpell(1, PhaseStep.UPKEEP, playerA, "Barkshell Blessing"); + setChoice(playerA, "Yes"); // use Conspire + addTarget(playerA, "Grizzly Bears"); // target bear + setChoice(playerA, "Grizzly Bears"); // pay for conspire + setChoice(playerA, "Savannah Lions"); // pay for conspire + setChoice(playerA, "Yes"); // new target for copy: bone + addTarget(playerA, "Bonecrusher Giant"); + // setChoice(playerA, "When {this} becomes the target of a spell"); // must be one trigger from bone, not two + + setStrictChooseMode(true); + setStopAt(1, PhaseStep.PRECOMBAT_MAIN); + execute(); + assertAllCommandsUsed(); + + assertPowerToughness(playerA, "Bonecrusher Giant", 4 + 2, 3 + 2); + assertPowerToughness(playerA, "Grizzly Bears", 2 + 2, 2 + 2); + assertPowerToughness(playerA, "Savannah Lions", 2, 1); + assertLife(playerA, 20 - 2); // one trigger } /* diff --git a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java index 1c2a68c2414..f5736810ca9 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java @@ -1883,7 +1883,7 @@ public class TestPlayer implements Player { for (Player player : game.getPlayers().values()) { if (player.getName().equals(playerName) && target.canTarget(computerPlayer.getId(), player.getId(), source, game)) { - target.add(player.getId(), game); + target.addTarget(player.getId(), source, game); targets.remove(targetDefinition); return true; } @@ -1932,7 +1932,7 @@ public class TestPlayer implements Player { if (isObjectHaveTargetNameOrAlias(permanent, targetName) || (permanent.getName() + '-' + permanent.getExpansionSetCode()).equals(targetName)) { // TODO: remove exp code search? if (target.canTarget(abilityControllerId, permanent.getId(), source, game) && !target.getTargets().contains(permanent.getId())) { if ((permanent.isCopy() && !originOnly) || (!permanent.isCopy() && !copyOnly)) { - target.add(permanent.getId(), game); + target.addTarget(permanent.getId(), source, game); targetFound = true; break; // return to for (String targetName } @@ -1957,7 +1957,7 @@ public class TestPlayer implements Player { for (Card card : computerPlayer.getHand().getCards(((TargetCardInHand) target.getOriginalTarget()).getFilter(), game)) { if (isObjectHaveTargetNameOrAlias(card, targetName) || (card.getName() + '-' + card.getExpansionSetCode()).equals(targetName)) { // TODO: remove set code search? if (target.canTarget(abilityControllerId, card.getId(), source, game) && !target.getTargets().contains(card.getId())) { - target.add(card.getId(), game); + target.addTarget(card.getId(), source, game); targetFound = true; break; // return to for (String targetName } @@ -1982,7 +1982,7 @@ public class TestPlayer implements Player { for (Card card : game.getExile().getCards(targetFull.getFilter(), game)) { if (isObjectHaveTargetNameOrAlias(card, targetName) || (card.getName() + '-' + card.getExpansionSetCode()).equals(targetName)) { // TODO: remove set code search? if (target.canTarget(abilityControllerId, card.getId(), source, game) && !target.getTargets().contains(card.getId())) { - target.add(card.getId(), game); + target.addTarget(card.getId(), source, game); targetFound = true; break; // return to for (String targetName } @@ -2057,7 +2057,7 @@ public class TestPlayer implements Player { for (Card card : player.getGraveyard().getCards(targetFull.getFilter(), game)) { if (isObjectHaveTargetNameOrAlias(card, targetName) || (card.getName() + '-' + card.getExpansionSetCode()).equals(targetName)) { // TODO: remove set code search? if (target.canTarget(abilityControllerId, card.getId(), source, game) && !target.getTargets().contains(card.getId())) { - target.add(card.getId(), game); + target.addTarget(card.getId(), source, game); targetFound = true; break IterateGraveyards; // return to for (String targetName } @@ -2084,7 +2084,7 @@ public class TestPlayer implements Player { for (StackObject stackObject : game.getStack()) { if (isObjectHaveTargetNameOrAlias(stackObject, targetName)) { if (target.canTarget(abilityControllerId, stackObject.getId(), source, game) && !target.getTargets().contains(stackObject.getId())) { - target.add(stackObject.getId(), game); + target.addTarget(stackObject.getId(), source, game); targetFound = true; break; // return to for (String targetName } @@ -2133,7 +2133,7 @@ public class TestPlayer implements Player { for (String targetName : targetList) { for (Card card : cards.getCards(game)) { if (isObjectHaveTargetNameOrAlias(card, targetName) && !target.getTargets().contains(card.getId())) { - target.add(card.getId(), game); + target.addTarget(card.getId(), source, game); targetFound = true; break; }