mirror of
https://github.com/magefree/mage.git
synced 2025-12-21 19:11:59 -08:00
Added test for Mana.enough method.
This commit is contained in:
parent
7e58dc70d5
commit
8a133a43d0
2 changed files with 62 additions and 5 deletions
|
|
@ -3,6 +3,7 @@ package org.mage.test.utils;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import mage.Mana;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.costs.mana.ManaCost;
|
import mage.abilities.costs.mana.ManaCost;
|
||||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||||
|
|
@ -88,6 +89,42 @@ public class ManaUtilTest extends CardTestPlayerBase {
|
||||||
Assert.assertEquals("", ManaUtil.condenseManaCostString("{}"));
|
Assert.assertEquals("", ManaUtil.condenseManaCostString("{}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mana.enough is used to check if a spell can be cast with an given amount
|
||||||
|
* of avalable mana
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testManaEnough() {
|
||||||
|
testManaAvailEnough("{G}", 1, "", true);
|
||||||
|
testManaAvailEnough("{G}", 0, "{G}", true);
|
||||||
|
testManaAvailEnough("{R}", 0, "{G}", false);
|
||||||
|
testManaAvailEnough("{B}", 0, "{G}", false);
|
||||||
|
testManaAvailEnough("{U}", 0, "{G}", false);
|
||||||
|
testManaAvailEnough("{W}", 0, "{G}", false);
|
||||||
|
|
||||||
|
testManaAvailEnough("{R}", 1, "", true);
|
||||||
|
testManaAvailEnough("{R}", 0, "{R}", true);
|
||||||
|
testManaAvailEnough("{G}", 0, "{R}", false);
|
||||||
|
testManaAvailEnough("{B}", 0, "{R}", false);
|
||||||
|
testManaAvailEnough("{U}", 0, "{R}", false);
|
||||||
|
testManaAvailEnough("{W}", 0, "{R}", false);
|
||||||
|
|
||||||
|
testManaAvailEnough("{U}{B}{W}{G}{R}", 4, "{R}", true);
|
||||||
|
testManaAvailEnough("{U}{B}{W}{G}{R}", 3, "{R}{B}", true);
|
||||||
|
|
||||||
|
testManaAvailEnough("{U}{U}{U}{G}{G}{2}", 2, "{U}{U}{G}{R}{B}", true);
|
||||||
|
|
||||||
|
testManaAvailEnough("{2}{U}{U}", 0, "{U}{U}{U}{U}", true);
|
||||||
|
testManaAvailEnough("{2}{U}{U}", 0, "{4}", false);
|
||||||
|
testManaAvailEnough("{2}{U}{U}", 0, "{B}{B}{4}", false);
|
||||||
|
|
||||||
|
testManaAvailEnough("{G}", 0, "{G/W}", true);
|
||||||
|
testManaAvailEnough("{G}{W}", 0, "{G/W}{G/W}", true);
|
||||||
|
testManaAvailEnough("{W}{W}", 0, "{G/W}{G/W}", true);
|
||||||
|
testManaAvailEnough("{G}{G}", 0, "{G/W}{G/W}", true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common way to test ManaUtil.tryToAutoPay
|
* Common way to test ManaUtil.tryToAutoPay
|
||||||
*
|
*
|
||||||
|
|
@ -142,6 +179,26 @@ public class ManaUtilTest extends CardTestPlayerBase {
|
||||||
Assert.assertTrue("Wrong mana ability has been chosen", expectedChosen.isInstance(ability));
|
Assert.assertTrue("Wrong mana ability has been chosen", expectedChosen.isInstance(ability));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given available Mana is enough to pay a given mana cost
|
||||||
|
*
|
||||||
|
* @param manaCostsToPay
|
||||||
|
* @param availablyAny
|
||||||
|
* @param available
|
||||||
|
* @param expected
|
||||||
|
*/
|
||||||
|
private void testManaAvailEnough(String manaCostsToPay, int availablyAny, String available, boolean expected) {
|
||||||
|
ManaCost unpaid = new ManaCostsImpl(manaCostsToPay);
|
||||||
|
ManaCost costAvailable = new ManaCostsImpl(available);
|
||||||
|
Mana manaAvailable = costAvailable.getMana();
|
||||||
|
manaAvailable.setAny(availablyAny);
|
||||||
|
if (expected) {
|
||||||
|
Assert.assertTrue("The available Mana " + costAvailable.getText() + " should be enough to pay the costs " + unpaid.getText(), unpaid.getMana().enough(manaAvailable));
|
||||||
|
} else {
|
||||||
|
Assert.assertFalse("The available Mana " + costAvailable.getText() + " shouldn't be enough to pay the costs " + unpaid.getText(), unpaid.getMana().enough(manaAvailable));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts mana abilities from the card.
|
* Extracts mana abilities from the card.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -67,12 +67,12 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
|
||||||
public ManaCostsImpl(final ManaCostsImpl<T> costs) {
|
public ManaCostsImpl(final ManaCostsImpl<T> costs) {
|
||||||
this.id = costs.id;
|
this.id = costs.id;
|
||||||
for (T cost : costs) {
|
for (T cost : costs) {
|
||||||
this.add((T) cost.copy());
|
this.add(cost.copy());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean add(ManaCost cost) {
|
public final boolean add(ManaCost cost) {
|
||||||
if (cost instanceof ManaCosts) {
|
if (cost instanceof ManaCosts) {
|
||||||
for (ManaCost manaCost : (ManaCosts<T>) cost) {
|
for (ManaCost manaCost : (ManaCosts<T>) cost) {
|
||||||
super.add((T) manaCost);
|
super.add((T) manaCost);
|
||||||
|
|
@ -298,7 +298,7 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(String mana) {
|
public final void load(String mana) {
|
||||||
this.clear();
|
this.clear();
|
||||||
if (costs.containsKey(mana)) {
|
if (costs.containsKey(mana)) {
|
||||||
ManaCosts<T> savedCosts = costs.get(mana);
|
ManaCosts<T> savedCosts = costs.get(mana);
|
||||||
|
|
@ -433,7 +433,7 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
|
||||||
@Override
|
@Override
|
||||||
public boolean isPaid() {
|
public boolean isPaid() {
|
||||||
for (T cost : this) {
|
for (T cost : this) {
|
||||||
if (!((T) cost instanceof VariableManaCost) && !cost.isPaid()) {
|
if (!(cost instanceof VariableManaCost) && !cost.isPaid()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -465,7 +465,7 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ManaCosts<T> copy() {
|
public ManaCosts<T> copy() {
|
||||||
return new ManaCostsImpl(this);
|
return new ManaCostsImpl<>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue