aboutsummaryrefslogtreecommitdiffstats
path: root/test/eu/equalparts
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2015-07-13 03:31:02 +0200
committerEduardo Pedroni <ep625@york.ac.uk>2015-07-13 03:31:02 +0200
commit19183986d37c5ca1a31a5b308bace92b87430ffe (patch)
treefc2bf0fc6bed0fa836a8c1401f16d967b639b491 /test/eu/equalparts
parente319b8b0790d442d836958df41302af91d750313 (diff)
Added some statistics functionality, TDD
Diffstat (limited to 'test/eu/equalparts')
-rw-r--r--test/eu/equalparts/test/cardbase/CardbaseSortTest.java2
-rw-r--r--test/eu/equalparts/test/decks/DeckTest.java13
-rw-r--r--test/eu/equalparts/test/decks/StatisticsTest.java146
3 files changed, 152 insertions, 9 deletions
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