Search in sources :

Example 21 with DeckCardLists

use of mage.cards.decks.DeckCardLists in project mage by magefree.

the class DecDeckImportTest method testImport.

@Test
public void testImport() {
    StringBuilder errors = new StringBuilder();
    DecDeckImporter importer = new DecDeckImporter() {

        @Override
        public CardLookup getCardLookup() {
            return LOOKUP;
        }
    };
    DeckCardLists deck = importer.importDeck(Paths.get("src", "test", "data", "importer", "testdeck.dec").toString(), errors, false);
    TestDeckChecker.checker().addMain("Masticore", 4).addMain("Metalworker", 4).addMain("Phyrexian Colossus", 1).addMain("Crumbling Sanctuary", 1).addMain("Grim Monolith", 4).addMain("Mishra's Helix", 1).addMain("Phyrexian Processor", 4).addMain("Tangle Wire", 4).addMain("Thran Dynamo", 4).addMain("Voltaic Key", 4).addMain("Tinker", 4).addMain("Brainstorm", 4).addMain("Crystal Vein", 4).addMain("Island", 9).addMain("Rishadan Port", 4).addMain("Saprazzan Skerry", 4).addSide("Annul", 4).addSide("Chill", 4).addSide("Miscalculation", 4).addSide("Mishra's Helix", 1).addSide("Rising Waters", 2).verify(deck, 60, 15);
    assertEquals("", errors.toString());
}
Also used : DeckCardLists(mage.cards.decks.DeckCardLists) Test(org.junit.Test)

Example 22 with DeckCardLists

use of mage.cards.decks.DeckCardLists in project mage by magefree.

the class O8dDeckImportTest method testImport.

@Test
public void testImport() {
    O8dDeckImporter importer = new O8dDeckImporter() {

        @Override
        public CardLookup getCardLookup() {
            return LOOKUP;
        }
    };
    StringBuilder errors = new StringBuilder();
    DeckCardLists deck = importer.importDeck(Paths.get("src", "test", "data", "importer", "testdeck.o8d").toString(), errors, false);
    TestDeckChecker.checker().addMain("Forest", 1).addSide("Island", 2).verify(deck, 1, 2);
    assertEquals("", errors.toString());
}
Also used : DeckCardLists(mage.cards.decks.DeckCardLists) Test(org.junit.Test)

Example 23 with DeckCardLists

use of mage.cards.decks.DeckCardLists in project mage by magefree.

the class VerifyCardDataTest method test_checkSampleDecks.

@Test
public void test_checkSampleDecks() {
    Collection<String> errorsList = new ArrayList<>();
    // workaround to run verify test from IDE or from maven's project root folder
    Path rootPath = Paths.get("Mage.Client", "release", "sample-decks");
    if (!Files.exists(rootPath)) {
        rootPath = Paths.get("..", "Mage.Client", "release", "sample-decks");
    }
    if (!Files.exists(rootPath)) {
        Assert.fail("Sample decks: unknown root folder " + rootPath.toAbsolutePath());
    }
    // collect all files in all root's folders
    Collection<Path> filesList = new ArrayList<>();
    try {
        Files.walkFileTree(rootPath, new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                filesList.add(file);
                return FileVisitResult.CONTINUE;
            }
        });
    } catch (IOException e) {
        e.printStackTrace();
        errorsList.add("Error: sample deck - can't get folder content - " + e.getMessage());
    }
    Assert.assertTrue("Sample decks: can't find any deck files in " + rootPath.toAbsolutePath(), filesList.size() > 0);
    // try to open deck files
    int totalErrorFiles = 0;
    for (Path deckFile : filesList) {
        String deckName = rootPath.relativize(deckFile).toString();
        if (!deckName.endsWith(".dck") || skipListHaveName(SKIP_LIST_SAMPLE_DECKS, deckName)) {
            continue;
        }
        StringBuilder deckErrors = new StringBuilder();
        DeckCardLists deckCards = DeckImporter.importDeckFromFile(deckFile.toString(), deckErrors, AUTO_FIX_SAMPLE_DECKS);
        if (!deckErrors.toString().isEmpty()) {
            errorsList.add("Error: sample deck contains errors " + deckName);
            System.out.println("Errors in sample deck " + deckName + ":\n" + deckErrors);
            totalErrorFiles++;
            continue;
        }
        if ((deckCards.getCards().size() + deckCards.getSideboard().size()) < 10) {
            errorsList.add("Error: sample deck contains too little cards (" + deckCards.getSideboard().size() + ") " + deckName);
            totalErrorFiles++;
            continue;
        }
    }
    printMessages(errorsList);
    if (errorsList.size() > 0) {
        Assert.fail("Found sample decks: " + filesList.size() + "; with errors: " + totalErrorFiles);
    }
}
Also used : IOException(java.io.IOException) DeckCardLists(mage.cards.decks.DeckCardLists) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Test(org.junit.Test)

Aggregations

DeckCardLists (mage.cards.decks.DeckCardLists)23 Test (org.junit.Test)14 DeckCardInfo (mage.cards.decks.DeckCardInfo)5 File (java.io.File)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Deck (mage.cards.decks.Deck)3 MatchOptions (mage.game.match.MatchOptions)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 CardInfo (mage.cards.repository.CardInfo)2 Ignore (org.junit.Ignore)2 Document (org.w3c.dom.Document)2 Node (org.w3c.dom.Node)2 java.awt (java.awt)1 BufferedImage (java.awt.image.BufferedImage)1 FileReader (java.io.FileReader)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 SecureRandom (java.security.SecureRandom)1 List (java.util.List)1 Scanner (java.util.Scanner)1