diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Testest.java | 18 | ||||
-rw-r--r-- | test/eu/equalparts/test/cardbase/CardbaseSortTest.java | 2 | ||||
-rw-r--r-- | test/eu/equalparts/test/decks/DeckTest.java | 13 | ||||
-rw-r--r-- | test/eu/equalparts/test/decks/StatisticsTest.java | 146 |
4 files changed, 159 insertions, 20 deletions
diff --git a/test/Testest.java b/test/Testest.java index 7128b75..855568d 100644 --- a/test/Testest.java +++ b/test/Testest.java @@ -7,15 +7,15 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import eu.equalparts.cardbase.Cardbase; -import eu.equalparts.cardbase.data.Card; -import eu.equalparts.cardbase.data.StandaloneDeck; +import eu.equalparts.cardbase.cards.Card; +import eu.equalparts.cardbase.decks.StandaloneDeck; import eu.equalparts.cardbase.utils.JSON; public class Testest { public static void main(String... args) throws JsonParseException, JsonMappingException, MalformedURLException, IOException { - StandaloneDeck deck = JSON.mapper.readValue(new File("control.cbd"), StandaloneDeck.class); + StandaloneDeck deck = JSON.mapper.readValue(new File("deck.cbd"), StandaloneDeck.class); System.out.println(deck.name); System.out.println("plains: " + deck.plains); @@ -24,15 +24,11 @@ public class Testest { System.out.println("mountains: " + deck.mountains); System.out.println("forests: " + deck.forests); + int count = 0; for (Card card : deck.cards) { - System.out.println(card.count + "x " + card.name); - } - - Cardbase cards = new Cardbase(new File("cards.cb")); - List<Card> missingCards = cards.getMissingCards(deck); - - for (Card card : missingCards) { - System.out.println(card.count + "x " + card.name); + if (card.type != null && card.type.contains("Instant")) + System.out.println(card.count + "x " + card.cmc + " (" + card.name + ")"); } + System.out.println("total: " + count); } } diff --git a/test/eu/equalparts/test/cardbase/CardbaseSortTest.java b/test/eu/equalparts/test/cardbase/CardbaseSortTest.java index 2e756a3..81cb6ef 100644 --- a/test/eu/equalparts/test/cardbase/CardbaseSortTest.java +++ b/test/eu/equalparts/test/cardbase/CardbaseSortTest.java @@ -13,7 +13,7 @@ import org.junit.Test; import com.fasterxml.jackson.core.type.TypeReference; import eu.equalparts.cardbase.Cardbase; -import eu.equalparts.cardbase.data.Card; +import eu.equalparts.cardbase.cards.Card; import eu.equalparts.cardbase.utils.JSON; /** diff --git a/test/eu/equalparts/test/decks/DeckTest.java b/test/eu/equalparts/test/decks/DeckTest.java index 32b1a54..c6bf0a1 100644 --- a/test/eu/equalparts/test/decks/DeckTest.java +++ b/test/eu/equalparts/test/decks/DeckTest.java @@ -7,11 +7,11 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import eu.equalparts.cardbase.Cardbase; -import eu.equalparts.cardbase.data.Card; -import eu.equalparts.cardbase.data.ReferenceDeck; -import eu.equalparts.cardbase.data.StandaloneDeck; +import eu.equalparts.cardbase.cards.Card; +import eu.equalparts.cardbase.decks.ReferenceDeck; +import eu.equalparts.cardbase.decks.StandaloneDeck; import eu.equalparts.cardbase.utils.JSON; +import eu.equalparts.cardbase.utils.UID; public class DeckTest { @@ -40,13 +40,10 @@ public class DeckTest { referenceDeck.swamps == standaloneDeck.swamps && referenceDeck.mountains == standaloneDeck.mountains && referenceDeck.forests == standaloneDeck.forests; - assertTrue("Metadata was not correctly set.", condition); assertEquals("Wrong number of cards.", referenceDeck.cardReferences.size(), standaloneDeck.cards.size()); - for (Card card : standaloneDeck.cards) { - System.out.println("Checking card: " + card.name); - Integer count = referenceDeck.cardReferences.get(Cardbase.makeHash(card)); + Integer count = referenceDeck.cardReferences.get(UID.makeHash(card)); assertNotNull("Reference missing in deck.", count); assertEquals("Card count is wrong.", card.count, count); } diff --git a/test/eu/equalparts/test/decks/StatisticsTest.java b/test/eu/equalparts/test/decks/StatisticsTest.java new file mode 100644 index 0000000..41eef0a --- /dev/null +++ b/test/eu/equalparts/test/decks/StatisticsTest.java @@ -0,0 +1,146 @@ +package eu.equalparts.test.decks; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import eu.equalparts.cardbase.decks.StandaloneDeck; +import eu.equalparts.cardbase.decks.Statistics; +import eu.equalparts.cardbase.utils.JSON; + +public class StatisticsTest { + + private static StandaloneDeck testDeck; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + testDeck = JSON.mapper.readValue(StatisticsTest.class.getResourceAsStream("deck.cbd"), StandaloneDeck.class); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @Test + public void test_totalLandCountIsComputedCorrectly() throws Exception { + int count = Statistics.count(testDeck, "Land"); + + assertEquals(23, count); + } + + @Test + public void test_basicLandCountIsComputedCorrectly() throws Exception { + int count = Statistics.count(testDeck, "Basic Land"); + + assertEquals(20, count); + } + + @Test + public void test_cardCountIsComputedCorrectly() throws Exception { + int count = Statistics.count(testDeck); + + assertEquals(60, count); + } + + @Test + public void test_landPercentageIsComputedCorrectly() throws Exception { + double percentage = Statistics.calculatePercentage(testDeck, "Land"); + + assertTrue("Land percentage should be " + (23.0 / 60.0) + ", is " + percentage, percentage == (23.0 / 60.0)); + } + + @Test + public void test_creaturePercentageIsComputedCorrectly() throws Exception { + double percentage = Statistics.calculatePercentage(testDeck, "Creature"); + + assertTrue("Creature percentage should be " + (24.0 / 60.0) + ", is " + percentage, percentage == (24.0 / 60.0)); + } + + @Test + public void test_creatureCountIsComputedCorrectly() throws Exception { + int count = Statistics.count(testDeck, "Creature"); + + assertEquals(24, count); + } + + @Test + public void test_sorceryCountIsComputedCorrectly() throws Exception { + int count = Statistics.count(testDeck, "Sorcery"); + + assertEquals(1, count); + } + + @Test + public void test_instantCountIsComputedCorrectly() throws Exception { + int count = Statistics.count(testDeck, "Instant"); + + assertEquals(6, count); + } + + @Test + public void test_planeswalkerCountIsComputedCorrectly() throws Exception { + int count = Statistics.count(testDeck, "Planeswalker"); + + assertEquals(0, count); + } + + @Test + public void test_elfCountIsComputedCorrectly() throws Exception { + int count = Statistics.count(testDeck, "Elf"); + + assertEquals(2, count); + } + + @Test + public void test_overallCostDistributionIsComputedCorrectly() throws Exception { + int[] actualCosts = Statistics.computeDistribution(testDeck); + int[] expectedCosts = {0, 8, 11, 3, 4, 7, 4}; + + assertEquals("Array lengths do not match.", expectedCosts.length, actualCosts.length); + for (int i = 0; i < expectedCosts.length; i++) { + assertEquals("CMC: " + i, expectedCosts[i], actualCosts[i]); + } + } + + @Test + public void test_creatureCostDistributionIsComputedCorrectly() throws Exception { + int[] actualCosts = Statistics.computeDistribution(testDeck, "Creature"); + int[] expectedCosts = {0, 3, 6, 2, 2, 7, 4}; + + assertEquals("Array lengths do not match.", expectedCosts.length, actualCosts.length); + for (int i = 0; i < expectedCosts.length; i++) { + assertEquals("CMC: " + i, expectedCosts[i], actualCosts[i]); + } + } + + @Test + public void test_instantCostDistributionIsComputedCorrectly() throws Exception { + int[] actualCosts = Statistics.computeDistribution(testDeck, "Instant"); + int[] expectedCosts = {0, 2, 4}; + + assertEquals("Array lengths do not match.", expectedCosts.length, actualCosts.length); + for (int i = 0; i < expectedCosts.length; i++) { + assertEquals("CMC: " + i, expectedCosts[i], actualCosts[i]); + } + } + + @Test + public void test_planeswalkerCostDistributionIsComputedCorrectly() throws Exception { + int[] actualCosts = Statistics.computeDistribution(testDeck, "Planeswalker"); + int[] expectedCosts = {}; + + assertEquals("Array lengths do not match.", expectedCosts.length, actualCosts.length); + for (int i = 0; i < expectedCosts.length; i++) { + assertEquals("CMC: " + i, expectedCosts[i], actualCosts[i]); + } + } + +}
\ No newline at end of file |