mirror of
https://github.com/magefree/mage.git
synced 2026-01-20 10:20:00 -08:00
Mana updates
+ calling subtraction will now throw an exception if you try and use more mana than is available. This is better than setting it to 0. Setting to 0 impose that you should still be allowed to perform the action. + updated subtraction test to check for exception + subtractionCost() will not allow using mana that is not available, same as subtract()
This commit is contained in:
parent
1f5638539f
commit
2c617a6aaf
2 changed files with 101 additions and 25 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package org.mage.test.mana;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import mage.Mana;
|
||||
import mage.constants.ColoredManaSymbol;
|
||||
import mage.constants.ManaType;
|
||||
|
|
@ -434,6 +435,8 @@ public class ManaTest {
|
|||
@Test
|
||||
public void shouldNotSubtractLessThan0() {
|
||||
// given
|
||||
expectedException.expect(ArithmeticException.class);
|
||||
expectedException.expectMessage("You can not subtract below 0");
|
||||
Mana thisMana = new Mana(2, 2, 2, 2, 2, 2, 2);
|
||||
Mana thatMana = new Mana(10, 1, 1, 1, 10, 1, 1);
|
||||
|
||||
|
|
@ -441,13 +444,57 @@ public class ManaTest {
|
|||
thisMana.subtract(thatMana);
|
||||
|
||||
// then
|
||||
assertEquals(-8, thisMana.getRed());
|
||||
assertEquals(1, thisMana.getGreen());
|
||||
assertEquals(1, thisMana.getBlue());
|
||||
assertEquals(1, thisMana.getWhite());
|
||||
assertEquals(-8, thisMana.getBlack());
|
||||
assertEquals(1, thisMana.getColorless());
|
||||
assertEquals(1, thisMana.getAny());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldNotAllowMinusSubtractionCost() {
|
||||
// given
|
||||
expectedException.expect(ArithmeticException.class);
|
||||
expectedException.expectMessage("You can not subtract below 0");
|
||||
Mana thisMana = new Mana(2, 2, 2, 2, 2, 2, 2);
|
||||
Mana thatMana = new Mana(10, 1, 1, 1, 10, 1, 1);
|
||||
|
||||
// when
|
||||
thisMana.subtractCost(thatMana);
|
||||
|
||||
// then
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldUseExistingManaToPayColorless() {
|
||||
// given
|
||||
Mana available = new Mana();
|
||||
available.setRed(7);
|
||||
|
||||
Mana cost = new Mana();
|
||||
cost.setRed(4);
|
||||
cost.setColorless(2);
|
||||
|
||||
// when
|
||||
available.subtractCost(cost);
|
||||
|
||||
// then
|
||||
assertEquals(1, available.getRed());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldThrowExceptionOnUnavailableColorless() {
|
||||
// given
|
||||
expectedException.expect(ArithmeticException.class);
|
||||
expectedException.expectMessage("Not enough mana to pay colorless");
|
||||
Mana available = new Mana();
|
||||
available.setRed(4);
|
||||
|
||||
Mana cost = new Mana();
|
||||
cost.setRed(4);
|
||||
cost.setColorless(2);
|
||||
|
||||
// when
|
||||
available.subtractCost(cost);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue