test for ai tapping itself

This commit is contained in:
magenoxx 2011-06-06 22:34:36 +04:00
parent eb91d50f26
commit 82716349db
2 changed files with 68 additions and 2 deletions

View file

@ -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());
}
}

View file

@ -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;
}
}