mirror of
https://github.com/correl/mage.git
synced 2025-01-11 11:05:23 +00:00
Removed minus subtraction limits
+ Removed minus subtraction limits to allow other areas of code to work
This commit is contained in:
parent
05b841577a
commit
56be135532
2 changed files with 23 additions and 49 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;
|
||||
|
@ -431,26 +432,10 @@ public class ManaTest {
|
|||
assertEquals(1, thisMana.getAny());
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
// when
|
||||
thisMana.subtract(thatMana);
|
||||
|
||||
// then
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldNotAllowMinusSubtractionCost() {
|
||||
public void shouldSubtractCost() {
|
||||
// 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);
|
||||
|
||||
|
@ -458,7 +443,13 @@ public class ManaTest {
|
|||
thisMana.subtractCost(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());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -270,30 +270,13 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
* @param mana mana values to subtract
|
||||
*/
|
||||
public void subtract(final Mana mana) throws ArithmeticException {
|
||||
red = validateSubtraction(red, mana.red);
|
||||
green = validateSubtraction(green, mana.green);
|
||||
blue = validateSubtraction(blue, mana.blue);
|
||||
white = validateSubtraction(white, mana.white);
|
||||
black = validateSubtraction(black, mana.black);
|
||||
colorless = validateSubtraction(colorless, mana.colorless);
|
||||
any = validateSubtraction(any, mana.any);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures subtraction will not result in a negative number.
|
||||
*
|
||||
* @param lhs left hand side operand
|
||||
* @param rhs right hand side operand
|
||||
* @return returns the non-negative subtraction result
|
||||
* @throws ArithmeticException thrown when the result of the subtraction
|
||||
* is less than 0.
|
||||
*/
|
||||
private int validateSubtraction(final int lhs, final int rhs) throws ArithmeticException {
|
||||
int result = lhs - rhs;
|
||||
if (result < 0) {
|
||||
throw new ArithmeticException("You can not subtract below 0");
|
||||
}
|
||||
return result;
|
||||
red -= mana.red;
|
||||
green -= mana.green;
|
||||
blue -= mana.blue;
|
||||
white -= mana.white;
|
||||
black -= mana.black;
|
||||
colorless -= mana.colorless;
|
||||
any -= mana.any;
|
||||
}
|
||||
|
||||
|
||||
|
@ -308,13 +291,13 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
* colored mana to make up the negative colorless cost
|
||||
*/
|
||||
public void subtractCost(final Mana mana) throws ArithmeticException {
|
||||
red = validateSubtraction(red, mana.red);
|
||||
green = validateSubtraction(green, mana.green);
|
||||
blue = validateSubtraction(blue, mana.blue);
|
||||
white = validateSubtraction(white, mana.white);
|
||||
black = validateSubtraction(black, mana.black);
|
||||
any = validateSubtraction(any, mana.any);
|
||||
colorless -= mana.colorless; // can be minus, will use remaining mana to pay
|
||||
red -= mana.red;
|
||||
green -= mana.green;
|
||||
blue -= mana.blue;
|
||||
white -= mana.white;
|
||||
black -= mana.black;
|
||||
any -= mana.any;
|
||||
colorless -= mana.colorless;
|
||||
|
||||
while (colorless < 0) {
|
||||
int oldColorless = colorless;
|
||||
|
|
Loading…
Reference in a new issue