From 82716349dbec0726030ca5dd8dd96a3c7b8b016d Mon Sep 17 00:00:00 2001 From: magenoxx Date: Mon, 6 Jun 2011 22:34:36 +0400 Subject: [PATCH] test for ai tapping itself --- .../test/serverside/ai/BugTapsItselfTest.java | 31 +++++++++++++++ .../serverside/base/impl/CardTestAPIImpl.java | 39 ++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/serverside/ai/BugTapsItselfTest.java diff --git a/Mage.Tests/src/test/java/org/mage/test/serverside/ai/BugTapsItselfTest.java b/Mage.Tests/src/test/java/org/mage/test/serverside/ai/BugTapsItselfTest.java new file mode 100644 index 0000000000..99e78f6b04 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/serverside/ai/BugTapsItselfTest.java @@ -0,0 +1,31 @@ +package org.mage.test.serverside.ai; + +import junit.framework.Assert; +import mage.Constants; +import mage.game.permanent.Permanent; + +import org.junit.Test; +import org.mage.test.serverside.base.CardTestBase; + +/** + * Should reproduce the bug with AI tapping itself with Blinding Mage. + * But it doesn't ^( + * + * @ayratn + */ +public class BugTapsItselfTest extends CardTestBase { + + @Test + public void testVersusInfectCreature() throws Exception { + useWhiteDefault(); + addCard(Constants.Zone.BATTLEFIELD, computerA, "Blinding Mage"); + addCard(Constants.Zone.BATTLEFIELD, computerB, "Myr Sire"); + + setStopOnTurn(4); + execute(); + + assertResult(computerA, GameResult.DRAW); + Permanent permanent = getPermanent("Blinding Mage", computerA.getId()); + Assert.assertFalse("Should have been untapped", permanent.isTapped()); + } +} diff --git a/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestAPIImpl.java b/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestAPIImpl.java index e84866d601..46e397eba8 100644 --- a/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestAPIImpl.java +++ b/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestAPIImpl.java @@ -1,5 +1,8 @@ package org.mage.test.serverside.base.impl; +import java.util.List; +import java.util.UUID; + import mage.Constants; import mage.cards.Card; import mage.filter.Filter; @@ -7,12 +10,11 @@ import mage.game.permanent.Permanent; import mage.game.permanent.PermanentCard; import mage.players.Player; import mage.sets.Sets; + import org.junit.Assert; import org.mage.test.serverside.base.CardTestAPI; import org.mage.test.serverside.base.MageTestBase; -import java.util.List; - /** * API for test initialization and asserting the test results. * @@ -44,6 +46,23 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP // library:ComputerB:Plains:10 addCard(Constants.Zone.LIBRARY, computerB, "Plains", 10); } + + /** + * Default game initialization params for white player (that plays with Plains) + */ + public void useWhiteDefault() { + // *** ComputerA *** + addCard(Constants.Zone.BATTLEFIELD, computerA, "Plains", 5); + addCard(Constants.Zone.HAND, computerA, "Plains", 5); + removeAllCardsFromLibrary(computerA); + addCard(Constants.Zone.LIBRARY, computerA, "Plains", 10); + + // *** ComputerB *** + addCard(Constants.Zone.BATTLEFIELD, computerB, "Plains", 2); + addCard(Constants.Zone.HAND, computerB, "Plains", 2); + removeAllCardsFromLibrary(computerB); + addCard(Constants.Zone.LIBRARY, computerB, "Plains", 10); + } /** * Removes all cards from player's library from the game. @@ -293,4 +312,20 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP } Assert.assertEquals("(Battlefield) Card counts are not equal (" + cardName + ")", count, actualCount); } + + public Permanent getPermanent(String cardName, UUID controller) { + Permanent permanent0 = null; + int count = 0; + for (Permanent permanent : currentGame.getBattlefield().getAllPermanents()) { + if (permanent.getControllerId().equals(controller)) { + if (permanent.getName().equals(cardName)) { + permanent0 = permanent; + count++; + } + } + } + Assert.assertNotNull("Couldn't find a card with specified name: " + cardName, permanent0); + Assert.assertEquals("More than one permanent was found: " + cardName + "(" + count + ")", 1, count); + return permanent0; + } }