From 71ed488c1e06d9739f37b52142bfd9ff719c3ef0 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 18 Feb 2018 18:31:10 +0100 Subject: [PATCH] * Some deck format tests changed/added. --- .../mage/sets/MasterpieceSeriesAmonkhet.java | 3 - .../serverside/deck/DeckValidatorTest.java | 179 ++++++++++++++++-- 2 files changed, 165 insertions(+), 17 deletions(-) diff --git a/Mage.Sets/src/mage/sets/MasterpieceSeriesAmonkhet.java b/Mage.Sets/src/mage/sets/MasterpieceSeriesAmonkhet.java index 291c6782fef..d526453921f 100644 --- a/Mage.Sets/src/mage/sets/MasterpieceSeriesAmonkhet.java +++ b/Mage.Sets/src/mage/sets/MasterpieceSeriesAmonkhet.java @@ -27,9 +27,7 @@ */ package mage.sets; -import mage.cards.CardGraphicInfo; import mage.cards.ExpansionSet; -import mage.cards.FrameStyle; import mage.constants.Rarity; import mage.constants.SetType; @@ -50,7 +48,6 @@ public class MasterpieceSeriesAmonkhet extends ExpansionSet { this.blockName = "Masterpiece Series"; this.hasBoosters = false; this.hasBasicLands = false; - CardGraphicInfo cardGraphicInfo = new CardGraphicInfo(FrameStyle.KLD_INVENTION, false); cards.add(new SetCardInfo("Aggravated Assault", 25, Rarity.SPECIAL, mage.cards.a.AggravatedAssault.class)); cards.add(new SetCardInfo("Armageddon", 31, Rarity.SPECIAL, mage.cards.a.Armageddon.class)); diff --git a/Mage.Tests/src/test/java/org/mage/test/serverside/deck/DeckValidatorTest.java b/Mage.Tests/src/test/java/org/mage/test/serverside/deck/DeckValidatorTest.java index f7bf2fe462e..38d002d5240 100644 --- a/Mage.Tests/src/test/java/org/mage/test/serverside/deck/DeckValidatorTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/serverside/deck/DeckValidatorTest.java @@ -27,24 +27,24 @@ */ package org.mage.test.serverside.deck; +import java.util.ArrayList; +import java.util.List; import mage.cards.decks.Deck; import mage.cards.decks.DeckValidator; import mage.cards.repository.CardInfo; import mage.cards.repository.CardRepository; import mage.deck.Limited; import mage.deck.Modern; +import mage.deck.Standard; import org.junit.Assert; import org.junit.Test; -import org.mage.test.serverside.base.CardTestPlayerBase; - -import java.util.ArrayList; -import java.util.List; +import org.mage.test.serverside.base.MageTestBase; /** * * @author LevelX2 */ -public class DeckValidatorTest extends CardTestPlayerBase { +public class DeckValidatorTest extends MageTestBase { static class CardNameAmount { @@ -84,6 +84,38 @@ public class DeckValidatorTest extends CardTestPlayerBase { } + @Test + public void testStandardValid() { + ArrayList deck = new ArrayList<>(); + + deck.add(new CardNameAmount("MPS-AKH", 28, 4)); // Rhonas the Indomitable + deck.add(new CardNameAmount("Built to Smash", 4)); + deck.add(new CardNameAmount("Heroic Intervention", 4)); + deck.add(new CardNameAmount("Mountain", 48)); + + DeckValidator validator = new Standard(); + boolean validationSuccessful = testDeckValid(validator, deck); + Assert.assertTrue(validator.getInvalid().toString(), validationSuccessful); + } + + @Test + public void testStandardNotValid() { + ArrayList deck = new ArrayList<>(); + + deck.add(new CardNameAmount("MPS-AKH", 28, 4)); // Rhonas the Indomitable + deck.add(new CardNameAmount("Built to Smash", 4)); + deck.add(new CardNameAmount("Heroic Intervention", 4)); + deck.add(new CardNameAmount("Mountain", 47)); + + ArrayList sideboard = new ArrayList<>(); + sideboard.add(new CardNameAmount("Mountain", 16)); + + DeckValidator validator = new Standard(); + testDeckValid(validator, deck, sideboard); + Assert.assertEquals("invalid message not correct", + "{Sideboard=Must contain no more than 15 cards : has 16 cards, Deck=Must contain at least 60 cards: has only 59 cards}", validator.getInvalid().toString()); + } + @Test public void testLimitedValid() { ArrayList deck = new ArrayList<>(); @@ -226,37 +258,156 @@ public class DeckValidatorTest extends CardTestPlayerBase { @Test public void testModernBanned() { ArrayList deckList = new ArrayList<>(); + DeckValidator validator = new Modern(); + deckList.add(new CardNameAmount("Ancestral Vision", 4)); + deckList.add(new CardNameAmount("Mountain", 56)); + boolean validationSuccessful = testDeckValid(validator, deckList); + Assert.assertTrue(validator.getInvalid().toString(), validationSuccessful); + validator.getInvalid().clear(); + + deckList.clear(); deckList.add(new CardNameAmount("Ancient Den", 4)); + deckList.add(new CardNameAmount("Mountain", 56)); + validationSuccessful = testDeckValid(validator, deckList); + Assert.assertFalse(validator.getInvalid().toString(), validationSuccessful); + validator.getInvalid().clear(); + deckList.add(new CardNameAmount("Birthing Pod", 4)); + deckList.add(new CardNameAmount("Mountain", 56)); + validationSuccessful = testDeckValid(validator, deckList); + Assert.assertFalse(validator.getInvalid().toString(), validationSuccessful); + validator.getInvalid().clear(); + + deckList.clear(); deckList.add(new CardNameAmount("Blazing Shoal", 4)); + deckList.add(new CardNameAmount("Mountain", 56)); + validationSuccessful = testDeckValid(validator, deckList); + Assert.assertFalse(validator.getInvalid().toString(), validationSuccessful); + validator.getInvalid().clear(); + + deckList.clear(); deckList.add(new CardNameAmount("Bloodbraid Elf", 4)); + deckList.add(new CardNameAmount("Mountain", 56)); + validationSuccessful = testDeckValid(validator, deckList); + Assert.assertTrue(validator.getInvalid().toString(), validationSuccessful); + validator.getInvalid().clear(); + + deckList.clear(); deckList.add(new CardNameAmount("Chrome Mox", 4)); + deckList.add(new CardNameAmount("Mountain", 56)); + validationSuccessful = testDeckValid(validator, deckList); + Assert.assertFalse(validator.getInvalid().toString(), validationSuccessful); + validator.getInvalid().clear(); + + deckList.clear(); deckList.add(new CardNameAmount("Cloudpost", 4)); + deckList.add(new CardNameAmount("Mountain", 56)); + validationSuccessful = testDeckValid(validator, deckList); + Assert.assertFalse(validator.getInvalid().toString(), validationSuccessful); + validator.getInvalid().clear(); + + deckList.clear(); deckList.add(new CardNameAmount("Dark Depths", 4)); + deckList.add(new CardNameAmount("Mountain", 56)); + validationSuccessful = testDeckValid(validator, deckList); + Assert.assertFalse(validator.getInvalid().toString(), validationSuccessful); + validator.getInvalid().clear(); + + deckList.clear(); deckList.add(new CardNameAmount("Deathrite Shaman", 4)); + deckList.add(new CardNameAmount("Mountain", 56)); + validationSuccessful = testDeckValid(validator, deckList); + Assert.assertFalse(validator.getInvalid().toString(), validationSuccessful); + validator.getInvalid().clear(); + + deckList.clear(); deckList.add(new CardNameAmount("Dig Through Time", 4)); + deckList.add(new CardNameAmount("Mountain", 56)); + validationSuccessful = testDeckValid(validator, deckList); + Assert.assertFalse(validator.getInvalid().toString(), validationSuccessful); + validator.getInvalid().clear(); + + deckList.clear(); deckList.add(new CardNameAmount("Dread Return", 4)); + deckList.add(new CardNameAmount("Mountain", 56)); + validationSuccessful = testDeckValid(validator, deckList); + Assert.assertFalse(validator.getInvalid().toString(), validationSuccessful); + validator.getInvalid().clear(); + + deckList.clear(); deckList.add(new CardNameAmount("Glimpse of Nature", 4)); + deckList.add(new CardNameAmount("Mountain", 56)); + validationSuccessful = testDeckValid(validator, deckList); + Assert.assertFalse(validator.getInvalid().toString(), validationSuccessful); + validator.getInvalid().clear(); + + deckList.clear(); deckList.add(new CardNameAmount("Great Furnace", 4)); + deckList.add(new CardNameAmount("Mountain", 56)); + validationSuccessful = testDeckValid(validator, deckList); + Assert.assertFalse(validator.getInvalid().toString(), validationSuccessful); + validator.getInvalid().clear(); + + deckList.clear(); deckList.add(new CardNameAmount("Green Sun's Zenith", 4)); + deckList.add(new CardNameAmount("Mountain", 56)); + validationSuccessful = testDeckValid(validator, deckList); + Assert.assertFalse(validator.getInvalid().toString(), validationSuccessful); + validator.getInvalid().clear(); + + deckList.clear(); deckList.add(new CardNameAmount("Hypergenesis", 4)); + deckList.add(new CardNameAmount("Mountain", 56)); + validationSuccessful = testDeckValid(validator, deckList); + Assert.assertFalse(validator.getInvalid().toString(), validationSuccessful); + validator.getInvalid().clear(); + + deckList.clear(); deckList.add(new CardNameAmount("Jace, the Mind Sculptor", 4)); + deckList.add(new CardNameAmount("Mountain", 56)); + validationSuccessful = testDeckValid(validator, deckList); + Assert.assertTrue(validator.getInvalid().toString(), validationSuccessful); + validator.getInvalid().clear(); + + deckList.clear(); deckList.add(new CardNameAmount("Mental Misstep", 4)); - Assert.assertFalse("banned cards are not allowed", testDeckValid(new Modern(), deckList)); + deckList.add(new CardNameAmount("Mountain", 56)); + validationSuccessful = testDeckValid(validator, deckList); + Assert.assertFalse(validator.getInvalid().toString(), validationSuccessful); + validator.getInvalid().clear(); } private boolean testDeckValid(DeckValidator validator, List cards) { + return testDeckValid(validator, cards, null); + } + + private boolean testDeckValid(DeckValidator validator, List cards, List cardsSideboard) { Deck deckToTest = new Deck(); - for (CardNameAmount cardNameAmount : cards) { - CardInfo cardinfo; - if (cardNameAmount.getName().isEmpty()) { - cardinfo = CardRepository.instance.findCard(cardNameAmount.getSetCode(), cardNameAmount.getCardNumber()); - } else { - cardinfo = CardRepository.instance.findCard(cardNameAmount.getName()); + if (cards != null) { + for (CardNameAmount cardNameAmount : cards) { + CardInfo cardinfo; + if (cardNameAmount.getName().isEmpty()) { + cardinfo = CardRepository.instance.findCard(cardNameAmount.getSetCode(), cardNameAmount.getCardNumber()); + } else { + cardinfo = CardRepository.instance.findCard(cardNameAmount.getName()); + } + for (int i = 0; i < cardNameAmount.getNumber(); i++) { + deckToTest.getCards().add(cardinfo.getCard()); + } } - for (int i = 0; i < cardNameAmount.getNumber(); i++) { - deckToTest.getCards().add(cardinfo.getCard()); + } + if (cardsSideboard != null) { + for (CardNameAmount cardNameAmount : cardsSideboard) { + CardInfo cardinfo; + if (cardNameAmount.getName().isEmpty()) { + cardinfo = CardRepository.instance.findCard(cardNameAmount.getSetCode(), cardNameAmount.getCardNumber()); + } else { + cardinfo = CardRepository.instance.findCard(cardNameAmount.getName()); + } + for (int i = 0; i < cardNameAmount.getNumber(); i++) { + deckToTest.getSideboard().add(cardinfo.getCard()); + } } } return validator.validate(deckToTest);