From 4526d50e43a1ae301b5c310295da8d91e9853879 Mon Sep 17 00:00:00 2001 From: magenoxx <magenoxx@gmail> Date: Tue, 1 May 2012 12:07:06 +0400 Subject: [PATCH] Added tests for cost modification effects based on Arcane Melee card. One test fails because of bug in core. --- .../cost/modification/ArcaneMeleeTest.java | 116 ++++++++++++++++++ .../abilities/effects/ContinuousEffects.java | 9 +- 2 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/ArcaneMeleeTest.java diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/ArcaneMeleeTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/ArcaneMeleeTest.java new file mode 100644 index 0000000000..3dde294863 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/cost/modification/ArcaneMeleeTest.java @@ -0,0 +1,116 @@ +package org.mage.test.cards.cost.modification; + +import mage.Constants; +import mage.cards.Card; +import org.junit.Assert; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +import java.util.UUID; + +/** + * Arcane Melee: + * Enchantment + * Instant and sorcery spells cost {2} less to cast. + * + * @author noxx + */ +public class ArcaneMeleeTest extends CardTestPlayerBase { + + /** + * While on battlefield, "Arcane Melee" should reduce cost. + * So one Island would be enough to cast "Divination" that can be checked by playerA's card count + */ + @Test + public void testOnBattlefield() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Island", 4); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Arcane Melee", 1); + addCard(Constants.Zone.HAND, playerA, "Flow of Ideas", 1); + + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Flow of Ideas"); + + setStopAt(1, Constants.PhaseStep.BEGIN_COMBAT); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + // by default players don't draw 7 cards at startup in tests (it can be changed through command though) + // 6 Islands => draw 6 cards + assertHandCount(playerA, 4); + } + + + /** + * "Arcane Melee" shouldn't cause any affect while being in hand + */ + @Test + public void testInHand() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Island", 4); + addCard(Constants.Zone.HAND, playerA, "Arcane Melee", 1); + addCard(Constants.Zone.HAND, playerA, "Flow of Ideas", 1); + + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Flow of Ideas"); + + setStopAt(1, Constants.PhaseStep.BEGIN_COMBAT); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + // by default players don't draw 7 cards at startup in tests (it can be changed through command though) + // 2 cards: 1 Flow of Ideas (not enough mana to cast) + 1 Arcane Melee + assertHandCount(playerA, 2); + } + + /** + * Test cumulative effect of cost reduction effects + */ + @Test + public void testMultiArcaneMelee() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Island", 1); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Arcane Melee", 3); + addCard(Constants.Zone.HAND, playerA, "Flow of Ideas", 1); + + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Flow of Ideas"); + + setStopAt(1, Constants.PhaseStep.BEGIN_COMBAT); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + // by default players don't draw 7 cards at startup in tests (it can be changed through command though) + // 1 card: Flow of Ideas should be cast and one card should be drawn + assertHandCount(playerA, 1); + + // check there is 'Flow of Ideas' in graveyard + boolean found = false; + for (UUID cardId : playerA.getGraveyard()) { + Card card = currentGame.getCard(cardId); + if (card.getName().equals("Flow of Ideas")) { + found = true; + break; + } + } + Assert.assertTrue("Flow of Ideas wasn't found in graveyard, means it wasn't cast", found); + } + + /** + * Tests that "Arcane Melee" doesn't affect creature card + */ + @Test + public void testNonInstantAndSorcery() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Island", 1); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Arcane Melee", 1); + addCard(Constants.Zone.HAND, playerA, "Merfolk Looter", 1); + + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Merfolk Looter"); + + setStopAt(1, Constants.PhaseStep.BEGIN_COMBAT); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + // by default players don't draw 7 cards at startup in tests (it can be changed through command though) + // 1 card: Merfolk Looter (Arcane Melee doesn't affect creatures' costs) + assertHandCount(playerA, 1); + } +} diff --git a/Mage/src/mage/abilities/effects/ContinuousEffects.java b/Mage/src/mage/abilities/effects/ContinuousEffects.java index d75cd71770..5047708711 100644 --- a/Mage/src/mage/abilities/effects/ContinuousEffects.java +++ b/Mage/src/mage/abilities/effects/ContinuousEffects.java @@ -28,8 +28,6 @@ package mage.abilities.effects; -import java.io.Serializable; -import java.util.*; import mage.Constants.AsThoughEffectType; import mage.Constants.Duration; import mage.Constants.Layer; @@ -41,6 +39,9 @@ import mage.game.events.GameEvent; import mage.game.permanent.Permanent; import mage.players.Player; +import java.io.Serializable; +import java.util.*; + /** * @@ -241,7 +242,9 @@ public class ContinuousEffects implements Serializable { * @return */ public void costModification ( Ability abilityToModify, Game game ) { - for ( CostModificationEffect effect : costModificationEffects ) { + //List<CostModificationEffect> costEffects = getApplicableCostModificationEffects(game); + + for ( CostModificationEffect effect : costModificationEffects) { if ( effect.applies(abilityToModify, costModificationEffects.getAbility(effect.getId()), game) ) { effect.apply(game, costModificationEffects.getAbility(effect.getId()), abilityToModify); }