mirror of
https://github.com/correl/mage.git
synced 2024-11-14 11:09:31 +00:00
tests: added assert method for emblems, added test for wrong emblem's playable mark in GUI
This commit is contained in:
parent
afe89a1056
commit
7a33ca812c
3 changed files with 142 additions and 4 deletions
|
@ -33,6 +33,7 @@ import mage.game.GameImpl;
|
|||
import mage.game.Graveyard;
|
||||
import mage.game.Table;
|
||||
import mage.game.combat.CombatGroup;
|
||||
import mage.game.command.CommandObject;
|
||||
import mage.game.draft.Draft;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.match.Match;
|
||||
|
@ -885,6 +886,13 @@ public class TestPlayer implements Player {
|
|||
wasProccessed = true;
|
||||
}
|
||||
|
||||
// check emblem count: emblem name, count
|
||||
if (params[0].equals(CHECK_COMMAND_EMBLEM_COUNT) && params.length == 3) {
|
||||
assertEmblemCount(action, game, computerPlayer, params[1], Integer.parseInt(params[2]));
|
||||
actions.remove(action);
|
||||
wasProccessed = true;
|
||||
}
|
||||
|
||||
// check color: card name, colors, must have
|
||||
if (params[0].equals(CHECK_COMMAND_COLOR) && params.length == 4) {
|
||||
assertColor(action, game, computerPlayer, params[1], params[2], Boolean.parseBoolean(params[3]));
|
||||
|
@ -1146,16 +1154,28 @@ public class TestPlayer implements Player {
|
|||
|
||||
private void printCards(List<Card> cards, boolean sorted) {
|
||||
System.out.println("Total cards: " + cards.size());
|
||||
printObjectsInner(cards, sorted);
|
||||
}
|
||||
|
||||
private void printObjects(List<MageObject> objects) {
|
||||
printObjects(objects, true);
|
||||
}
|
||||
|
||||
private void printObjects(List<MageObject> objects, boolean sorted) {
|
||||
System.out.println("Total objects: " + objects.size());
|
||||
printObjectsInner(objects, sorted);
|
||||
}
|
||||
|
||||
private void printObjectsInner(List<? extends MageObject> objects, boolean sorted) {
|
||||
List<String> data;
|
||||
if (sorted) {
|
||||
data = cards.stream()
|
||||
.map(Card::getIdName)
|
||||
data = objects.stream()
|
||||
.map(MageObject::getIdName)
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
data = cards.stream()
|
||||
.map(Card::getIdName)
|
||||
data = objects.stream()
|
||||
.map(MageObject::getIdName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
@ -1499,6 +1519,26 @@ public class TestPlayer implements Player {
|
|||
}
|
||||
}
|
||||
|
||||
private void assertEmblemCount(PlayerAction action, Game game, Player player, String emblemName, int count) {
|
||||
int realCount = 0;
|
||||
List<MageObject> realList = new ArrayList<>();
|
||||
for (CommandObject commandObject : game.getState().getCommand()) {
|
||||
if (commandObject.getControllerId().equals(player.getId())) {
|
||||
realList.add(commandObject);
|
||||
if (hasObjectTargetNameOrAlias(commandObject, emblemName)) {
|
||||
realCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (realCount != count) {
|
||||
printStart(game, "Emblems of " + player.getName());
|
||||
printObjects(realList);
|
||||
printEnd();
|
||||
Assert.fail(action.getActionName() + " - must have " + count + " emblems with name " + emblemName + ", but found " + realCount);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertColor(PlayerAction action, Game game, Player player, String permanentName, String colors, boolean mustHave) {
|
||||
Assert.assertNotEquals(action.getActionName() + " - must setup colors", "", colors);
|
||||
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
package org.mage.test.serverside;
|
||||
|
||||
import mage.MageItem;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.SimpleActivatedAbility;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.effects.common.GetEmblemTargetPlayerEffect;
|
||||
import mage.constants.CommanderCardType;
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.command.Emblem;
|
||||
import mage.game.command.emblems.MomirEmblem;
|
||||
import mage.target.TargetPlayer;
|
||||
import mage.view.GameView;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestCommander4Players;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author JayDi85
|
||||
*/
|
||||
public class PlayableEmblemsTest extends CardTestCommander4Players {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
// TODO: must fix, GUI don't have playable mark for emblems due different object ids in playable ability and emblem
|
||||
public void test_EmblemMustBePlayableInGUI() {
|
||||
// possible bug: different emblem's id in commander zone and playable list
|
||||
Ability ability = new SimpleActivatedAbility(new GetEmblemTargetPlayerEffect(new MomirEmblem()), new ManaCostsImpl<>(""));
|
||||
ability.addTarget(new TargetPlayer());
|
||||
addCustomCardWithAbility("test", playerA, ability);
|
||||
|
||||
addCard(Zone.COMMAND, playerA, "Balduvian Bears", 1); // {1}{G}, 2/2, commander
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Forest", 2);
|
||||
//
|
||||
addCard(Zone.COMMAND, playerA, "Goblin Arsonist", 1); // {R}, commander
|
||||
//
|
||||
addCard(Zone.HAND, playerA, "Mountain", 1); // for emblem's ability
|
||||
|
||||
// prepare emblem
|
||||
checkPlayableAbility("before", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "{X}, Discard", false);
|
||||
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "target player gets");
|
||||
addTarget(playerA, playerA);
|
||||
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
|
||||
checkEmblemCount("after", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Emblem Momir", 1);
|
||||
checkPlayableAbility("after", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "{X}, Discard", true);
|
||||
checkPlayableAbility("after", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Balduvian Bears", true);
|
||||
checkPlayableAbility("after", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Goblin Arsonist", false);
|
||||
|
||||
runCode("check playable", 1, PhaseStep.PRECOMBAT_MAIN, playerA, (info, player, game) -> {
|
||||
// check GUI related code (must run at runtime cause it needs real playable objects)
|
||||
GameView gameView = getGameView(playerA);
|
||||
|
||||
// playable commander
|
||||
UUID needObjectId = game.getCommandersIds(playerA, CommanderCardType.COMMANDER_OR_OATHBREAKER, false)
|
||||
.stream()
|
||||
.filter(id -> game.getObject(id).getName().equals("Balduvian Bears"))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
Assert.assertNotNull(needObjectId);
|
||||
Assert.assertTrue("commander must be playable", gameView.getCanPlayObjects().containsObject(needObjectId));
|
||||
|
||||
// non playable commander
|
||||
needObjectId = game.getCommandersIds(playerA, CommanderCardType.COMMANDER_OR_OATHBREAKER, false)
|
||||
.stream()
|
||||
.filter(id -> game.getObject(id).getName().equals("Goblin Arsonist"))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
Assert.assertNotNull(needObjectId);
|
||||
Assert.assertFalse("commander must not be playable", gameView.getCanPlayObjects().containsObject(needObjectId));
|
||||
|
||||
// playable emblem
|
||||
needObjectId = game.getState().getCommand()
|
||||
.stream()
|
||||
.filter(obj -> obj instanceof Emblem)
|
||||
.filter(obj -> obj.isControlledBy(playerA.getId()))
|
||||
.filter(obj -> obj.getName().equals("Emblem Momir"))
|
||||
.map(MageItem::getId)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
Assert.assertNotNull(needObjectId);
|
||||
Assert.assertFalse("emblem must be playable", gameView.getCanPlayObjects().containsObject(needObjectId));
|
||||
});
|
||||
|
||||
setStrictChooseMode(true);
|
||||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
}
|
||||
}
|
|
@ -95,6 +95,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
public static final String CHECK_COMMAND_HAND_COUNT = "HAND_COUNT";
|
||||
public static final String CHECK_COMMAND_HAND_CARD_COUNT = "HAND_CARD_COUNT";
|
||||
public static final String CHECK_COMMAND_COMMAND_CARD_COUNT = "COMMAND_CARD_COUNT";
|
||||
public static final String CHECK_COMMAND_EMBLEM_COUNT = "EMBLEM_COUNT";
|
||||
public static final String CHECK_COMMAND_COLOR = "COLOR";
|
||||
public static final String CHECK_COMMAND_TYPE = "TYPE";
|
||||
public static final String CHECK_COMMAND_SUBTYPE = "SUBTYPE";
|
||||
|
@ -446,6 +447,11 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
check(checkName, turnNum, step, player, CHECK_COMMAND_COMMAND_CARD_COUNT, cardName, count.toString());
|
||||
}
|
||||
|
||||
public void checkEmblemCount(String checkName, int turnNum, PhaseStep step, TestPlayer player, String emblemName, Integer count) {
|
||||
//Assert.assertNotEquals("", emblemName);
|
||||
check(checkName, turnNum, step, player, CHECK_COMMAND_EMBLEM_COUNT, emblemName, count.toString());
|
||||
}
|
||||
|
||||
public void checkColor(String checkName, int turnNum, PhaseStep step, TestPlayer player, String permanentName, String colors, Boolean mustHave) {
|
||||
//Assert.assertNotEquals("", permanentName);
|
||||
check(checkName, turnNum, step, player, CHECK_COMMAND_COLOR, permanentName, colors, mustHave.toString());
|
||||
|
|
Loading…
Reference in a new issue