mirror of
https://github.com/correl/mage.git
synced 2024-11-25 03:00:11 +00:00
parent
71f24a03bf
commit
213b5fddc6
1 changed files with 47 additions and 64 deletions
|
@ -2,22 +2,22 @@ package mage;
|
||||||
|
|
||||||
import mage.abilities.SpellAbility;
|
import mage.abilities.SpellAbility;
|
||||||
import mage.abilities.costs.mana.ManaCost;
|
import mage.abilities.costs.mana.ManaCost;
|
||||||
import mage.abilities.costs.mana.ManaCostImpl;
|
|
||||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||||
import mage.constants.ColoredManaSymbol;
|
import mage.constants.ColoredManaSymbol;
|
||||||
import mage.constants.ManaType;
|
import mage.constants.ManaType;
|
||||||
import mage.filter.FilterMana;
|
import mage.filter.FilterMana;
|
||||||
import mage.util.CardUtil;
|
import mage.util.CardUtil;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom unit tests for {@link Mana}.
|
* Custom unit tests for {@link Mana}.
|
||||||
|
@ -26,18 +26,16 @@ import static org.junit.Assert.*;
|
||||||
*/
|
*/
|
||||||
public class ManaTest {
|
public class ManaTest {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException expectedException = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotAllowNullCopyConstructor() {
|
public void shouldNotAllowNullCopyConstructor() {
|
||||||
// given
|
|
||||||
expectedException.expect(NullPointerException.class);
|
|
||||||
expectedException.expectMessage("The passed in mana can not be null");
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
|
NullPointerException expectedException = assertThrows(NullPointerException.class, () -> {
|
||||||
Mana nullMana = null;
|
Mana nullMana = null;
|
||||||
new Mana(nullMana);
|
new Mana(nullMana);
|
||||||
|
});
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertEquals("The passed in mana can not be null", expectedException.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -139,19 +137,18 @@ public class ManaTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotCreateManaFromNullColoredManaSymbol() {
|
public void shouldNotCreateManaFromNullColoredManaSymbol() {
|
||||||
// given
|
|
||||||
ColoredManaSymbol nullSymbol = null;
|
|
||||||
|
|
||||||
expectedException.expect(NullPointerException.class);
|
|
||||||
expectedException.expectMessage("The passed in ColoredManaSymbol can not be null");
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
|
NullPointerException exception = assertThrows(NullPointerException.class, () -> {
|
||||||
|
ColoredManaSymbol nullSymbol = null;
|
||||||
new Mana(nullSymbol);
|
new Mana(nullSymbol);
|
||||||
|
});
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertEquals("The passed in ColoredManaSymbol can not be null", exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateManaFromIntegers() {
|
public void shouldCreateManaFromIntegers() {
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Mana mana = new Mana(4, 3, 5, 1, 2, 6, 7, 8);
|
Mana mana = new Mana(4, 3, 5, 1, 2, 6, 7, 8);
|
||||||
|
|
||||||
|
@ -168,8 +165,6 @@ public class ManaTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotAllowNegativeIntegers() {
|
public void shouldNotAllowNegativeIntegers() {
|
||||||
// given
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Mana mana = new Mana(4, 3, 5, -1, 2, 6, 7, 0);
|
Mana mana = new Mana(4, 3, 5, -1, 2, 6, 7, 0);
|
||||||
|
|
||||||
|
@ -179,7 +174,6 @@ public class ManaTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateRedMana() {
|
public void shouldCreateRedMana() {
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Mana mana = Mana.RedMana(1);
|
Mana mana = Mana.RedMana(1);
|
||||||
|
|
||||||
|
@ -189,7 +183,6 @@ public class ManaTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateGreenMana() {
|
public void shouldCreateGreenMana() {
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Mana mana = Mana.GreenMana(1);
|
Mana mana = Mana.GreenMana(1);
|
||||||
|
|
||||||
|
@ -199,7 +192,6 @@ public class ManaTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateBlueMana() {
|
public void shouldCreateBlueMana() {
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Mana mana = Mana.BlueMana(1);
|
Mana mana = Mana.BlueMana(1);
|
||||||
|
|
||||||
|
@ -209,7 +201,6 @@ public class ManaTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateWhiteMana() {
|
public void shouldCreateWhiteMana() {
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Mana mana = Mana.WhiteMana(1);
|
Mana mana = Mana.WhiteMana(1);
|
||||||
|
|
||||||
|
@ -219,7 +210,6 @@ public class ManaTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateBlackMana() {
|
public void shouldCreateBlackMana() {
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Mana mana = Mana.BlackMana(1);
|
Mana mana = Mana.BlackMana(1);
|
||||||
|
|
||||||
|
@ -229,7 +219,6 @@ public class ManaTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateGenericMana() {
|
public void shouldCreateGenericMana() {
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Mana mana = Mana.GenericMana(1);
|
Mana mana = Mana.GenericMana(1);
|
||||||
|
|
||||||
|
@ -239,7 +228,6 @@ public class ManaTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateColorlessMana() {
|
public void shouldCreateColorlessMana() {
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Mana mana = Mana.ColorlessMana(1);
|
Mana mana = Mana.ColorlessMana(1);
|
||||||
|
|
||||||
|
@ -249,19 +237,15 @@ public class ManaTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotAllowNegativeRedMana() {
|
public void shouldNotAllowNegativeRedMana() {
|
||||||
// given
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Mana mana = Mana.RedMana(-1);
|
Mana mana = Mana.RedMana(-1);
|
||||||
|
|
||||||
//then
|
// then
|
||||||
assertEquals(0, mana.getRed());
|
assertEquals(0, mana.getRed());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotAllowNegativeGreenMana() {
|
public void shouldNotAllowNegativeGreenMana() {
|
||||||
// given
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Mana mana = Mana.GreenMana(-1);
|
Mana mana = Mana.GreenMana(-1);
|
||||||
|
|
||||||
|
@ -271,8 +255,6 @@ public class ManaTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotAllowNegativeBlueMana() {
|
public void shouldNotAllowNegativeBlueMana() {
|
||||||
// given
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Mana mana = Mana.BlueMana(-1);
|
Mana mana = Mana.BlueMana(-1);
|
||||||
|
|
||||||
|
@ -282,8 +264,6 @@ public class ManaTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotAllowNegativeWhiteMana() {
|
public void shouldNotAllowNegativeWhiteMana() {
|
||||||
// given
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Mana mana = Mana.WhiteMana(-1);
|
Mana mana = Mana.WhiteMana(-1);
|
||||||
|
|
||||||
|
@ -293,23 +273,19 @@ public class ManaTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotAllowNegativeBlackMana() {
|
public void shouldNotAllowNegativeBlackMana() {
|
||||||
// given
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Mana mana = Mana.BlackMana(-1);
|
Mana mana = Mana.BlackMana(-1);
|
||||||
|
|
||||||
//then
|
// then
|
||||||
assertEquals(0, mana.getBlack());
|
assertEquals(0, mana.getBlack());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotAllowNegativeColorlessMana() {
|
public void shouldNotAllowNegativeColorlessMana() {
|
||||||
// given
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Mana mana = Mana.GenericMana(-1);
|
Mana mana = Mana.GenericMana(-1);
|
||||||
|
|
||||||
//then
|
// then
|
||||||
assertEquals(0, mana.getGeneric());
|
assertEquals(0, mana.getGeneric());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,8 +439,6 @@ public class ManaTest {
|
||||||
@Test
|
@Test
|
||||||
public void shouldThrowExceptionOnUnavailableColorless() {
|
public void shouldThrowExceptionOnUnavailableColorless() {
|
||||||
// given
|
// given
|
||||||
expectedException.expect(ArithmeticException.class);
|
|
||||||
expectedException.expectMessage("Not enough mana to pay colorless");
|
|
||||||
Mana available = new Mana();
|
Mana available = new Mana();
|
||||||
available.setRed(4);
|
available.setRed(4);
|
||||||
|
|
||||||
|
@ -473,7 +447,12 @@ public class ManaTest {
|
||||||
cost.setGeneric(2);
|
cost.setGeneric(2);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
|
ArithmeticException exception = assertThrows(ArithmeticException.class, () -> {
|
||||||
available.subtractCost(cost);
|
available.subtractCost(cost);
|
||||||
|
});
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertEquals("Not enough mana to pay colorless", exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -819,8 +798,8 @@ public class ManaTest {
|
||||||
// 1. A color of WUBURG is not more valuable than any other
|
// 1. A color of WUBURG is not more valuable than any other
|
||||||
for (Mana coloredMana1 : coloredManas) {
|
for (Mana coloredMana1 : coloredManas) {
|
||||||
for (Mana coloredMana2 : coloredManas) {
|
for (Mana coloredMana2 : coloredManas) {
|
||||||
assertNull(coloredMana1 + " and " + coloredMana2 + " should not be comparable.", Mana.getMoreValuableMana(coloredMana1, coloredMana2));
|
assertNull(Mana.getMoreValuableMana(coloredMana1, coloredMana2), String.format("%s and %s should not be comparable.", coloredMana1, coloredMana2));
|
||||||
assertNull(coloredMana1 + " and " + coloredMana2 + " should not be comparable.", Mana.getMoreValuableMana(coloredMana2, coloredMana1));
|
assertNull(Mana.getMoreValuableMana(coloredMana2, coloredMana1), String.format("%s and %s should not be comparable.", coloredMana1, coloredMana2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -900,10 +879,9 @@ public class ManaTest {
|
||||||
*/
|
*/
|
||||||
private void testManaNeeded(Mana available, Mana cost, Mana neededExpected) {
|
private void testManaNeeded(Mana available, Mana cost, Mana neededExpected) {
|
||||||
Mana neededActual = cost.needed(available);
|
Mana neededActual = cost.needed(available);
|
||||||
Assert.assertTrue(
|
assertTrue(
|
||||||
"The mana needed to pay " + cost + " given " + available
|
neededActual.equalManaValue(neededExpected),
|
||||||
+ " should have been " + neededExpected + " but was calculate to be " + neededActual,
|
String.format("The mana needed to pay %s given %s should have been %s but was calculated to be %s", cost, available, neededExpected, neededActual)
|
||||||
neededActual.equalManaValue(neededExpected)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -921,9 +899,15 @@ public class ManaTest {
|
||||||
Mana manaAvailable = costAvailable.getMana();
|
Mana manaAvailable = costAvailable.getMana();
|
||||||
manaAvailable.setAny(availablyAny);
|
manaAvailable.setAny(availablyAny);
|
||||||
if (expected) {
|
if (expected) {
|
||||||
Assert.assertTrue("The available Mana " + costAvailable.getText() + " should be enough to pay the costs " + unpaid.getText(), unpaid.getMana().enough(manaAvailable));
|
assertTrue(
|
||||||
|
unpaid.getMana().enough(manaAvailable),
|
||||||
|
String.format("The available Mana %s should be enough to pay the costs %s", costAvailable.getText(), unpaid.getText())
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
Assert.assertFalse("The available Mana " + costAvailable.getText() + " shouldn't be enough to pay the costs " + unpaid.getText(), unpaid.getMana().enough(manaAvailable));
|
assertFalse(
|
||||||
|
unpaid.getMana().enough(manaAvailable),
|
||||||
|
String.format("The available Mana %s shouldn't be enough to pay the costs %s", costAvailable.getText(), unpaid.getText())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -937,11 +921,10 @@ public class ManaTest {
|
||||||
private void assertManaReduction(String manaCostsToPay, String manaToReduce, String restMana) {
|
private void assertManaReduction(String manaCostsToPay, String manaToReduce, String restMana) {
|
||||||
SpellAbility spellAbility = new SpellAbility(new ManaCostsImpl<>(manaCostsToPay), "Test");
|
SpellAbility spellAbility = new SpellAbility(new ManaCostsImpl<>(manaCostsToPay), "Test");
|
||||||
CardUtil.adjustCost(spellAbility, new ManaCostsImpl<>(manaToReduce), true);
|
CardUtil.adjustCost(spellAbility, new ManaCostsImpl<>(manaToReduce), true);
|
||||||
Assert.assertEquals(
|
assertEquals(
|
||||||
"The mana cost to pay " + manaCostsToPay + " reduced by " + manaToReduce +
|
|
||||||
" should left " + restMana + " but the rest was " + spellAbility.getManaCostsToPay(),
|
|
||||||
spellAbility.getManaCostsToPay().getText(),
|
spellAbility.getManaCostsToPay().getText(),
|
||||||
restMana
|
restMana,
|
||||||
|
String.format("The mana cost to pay %s reduced by %s should have left %s but the rest was %s", manaCostsToPay,manaToReduce, restMana, spellAbility.getManaCostsToPay() )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue