diff options
author | Eduardo Pedroni <e.pedroni91@gmail.com> | 2016-08-07 22:18:55 +0200 |
---|---|---|
committer | Eduardo Pedroni <e.pedroni91@gmail.com> | 2016-08-07 22:18:55 +0200 |
commit | f7fe057b745d3f0e19b5dd6bd1819b11fc89c551 (patch) | |
tree | 1d19673aa4170f91248682a21db9fbc7c3945f4e /test | |
parent | 64c8e926d167a17865a6c3d86e48b383d413b569 (diff) |
Added filtering, still not working fully
Diffstat (limited to 'test')
-rw-r--r-- | test/eu/equalparts/cardbase/containers/ReferenceCardContainerTest.java (renamed from test/eu/equalparts/cardbase/cardstorage/ReferenceCardContainerTest.java) | 5 | ||||
-rw-r--r-- | test/eu/equalparts/cardbase/containers/StandaloneCardContainerTest.java (renamed from test/eu/equalparts/cardbase/cardstorage/StandaloneCardContainerTest.java) | 5 | ||||
-rw-r--r-- | test/eu/equalparts/cardbase/decks/ReferenceDeckTest.java | 2 | ||||
-rw-r--r-- | test/eu/equalparts/cardbase/filtering/CardFilteringTest.java | 252 | ||||
-rw-r--r-- | test/eu/equalparts/cardbase/sorting/CardSortingTest.java | 88 |
5 files changed, 308 insertions, 44 deletions
diff --git a/test/eu/equalparts/cardbase/cardstorage/ReferenceCardContainerTest.java b/test/eu/equalparts/cardbase/containers/ReferenceCardContainerTest.java index bf49e2f..849d84c 100644 --- a/test/eu/equalparts/cardbase/cardstorage/ReferenceCardContainerTest.java +++ b/test/eu/equalparts/cardbase/containers/ReferenceCardContainerTest.java @@ -1,4 +1,4 @@ -package eu.equalparts.cardbase.cardstorage; +package eu.equalparts.cardbase.containers; import static org.junit.Assert.assertEquals; @@ -11,7 +11,6 @@ import org.junit.rules.TemporaryFolder; import com.fasterxml.jackson.databind.ObjectMapper; -import eu.equalparts.cardbase.CardbaseTest; import eu.equalparts.cardbase.cards.Card; public class ReferenceCardContainerTest { @@ -28,7 +27,7 @@ public class ReferenceCardContainerTest { @BeforeClass public static void setUpBeforeClass() throws Exception { ObjectMapper mapper = new ObjectMapper(); - testCard = mapper.readValue(CardbaseTest.class.getResourceAsStream("/shivandragon.json"), Card.class); + testCard = mapper.readValue(ReferenceCardContainerTest.class.getResourceAsStream("/shivandragon.json"), Card.class); } @Before diff --git a/test/eu/equalparts/cardbase/cardstorage/StandaloneCardContainerTest.java b/test/eu/equalparts/cardbase/containers/StandaloneCardContainerTest.java index 6071e09..6e9b31a 100644 --- a/test/eu/equalparts/cardbase/cardstorage/StandaloneCardContainerTest.java +++ b/test/eu/equalparts/cardbase/containers/StandaloneCardContainerTest.java @@ -1,4 +1,4 @@ -package eu.equalparts.cardbase.cardstorage; +package eu.equalparts.cardbase.containers; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -16,7 +16,6 @@ import org.junit.rules.TemporaryFolder; import com.fasterxml.jackson.databind.ObjectMapper; -import eu.equalparts.cardbase.CardbaseTest; import eu.equalparts.cardbase.cards.Card; public class StandaloneCardContainerTest { @@ -32,7 +31,7 @@ public class StandaloneCardContainerTest { @BeforeClass public static void setUpBeforeClass() throws Exception { ObjectMapper mapper = new ObjectMapper(); - testCard = mapper.readValue(CardbaseTest.class.getResourceAsStream("/shivandragon.json"), Card.class); + testCard = mapper.readValue(StandaloneCardContainerTest.class.getResourceAsStream("/shivandragon.json"), Card.class); } @Before diff --git a/test/eu/equalparts/cardbase/decks/ReferenceDeckTest.java b/test/eu/equalparts/cardbase/decks/ReferenceDeckTest.java index 928c167..2a6f482 100644 --- a/test/eu/equalparts/cardbase/decks/ReferenceDeckTest.java +++ b/test/eu/equalparts/cardbase/decks/ReferenceDeckTest.java @@ -6,7 +6,7 @@ import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; -import eu.equalparts.cardbase.cardstorage.ReferenceCardContainer; +import eu.equalparts.cardbase.containers.ReferenceCardContainer; public class ReferenceDeckTest { private ReferenceDeck uut; diff --git a/test/eu/equalparts/cardbase/filtering/CardFilteringTest.java b/test/eu/equalparts/cardbase/filtering/CardFilteringTest.java new file mode 100644 index 0000000..4f5579d --- /dev/null +++ b/test/eu/equalparts/cardbase/filtering/CardFilteringTest.java @@ -0,0 +1,252 @@ +package eu.equalparts.cardbase.filtering; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.LinkedList; +import java.util.List; + +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +import eu.equalparts.cardbase.cards.Card; +import eu.equalparts.cardbase.filtering.CardFiltering.FilterType; + +public class CardFilteringTest { + private static List<Card> allTestCards, testCards; + + @Rule + public final ExpectedException exception = ExpectedException.none(); + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + ObjectMapper mapper = new ObjectMapper(); + allTestCards = mapper.readValue(CardFilteringTest.class.getResourceAsStream("/testcards.json"), new TypeReference<List<Card>>() {}); + } + + @Before + public void setUp() { + testCards = new LinkedList<>(allTestCards); + } + + @Test + public void filterByNameEquals() throws Exception { + CardFiltering.filterByField(testCards, "name", FilterType.EQUALS, "Callow jushi"); + + assertEquals("Wrong list size.", 1, testCards.size()); + assertEquals("Callow Jushi", testCards.get(0).name); + } + + @Test + public void filterByNameContains() throws Exception { + CardFiltering.filterByField(testCards, "name", FilterType.CONTAINS, "sh"); + + assertEquals("Wrong list size.", 3, testCards.size()); + int i = 0; + String[] names = { + "Callow Jushi", + "Shivan Dragon", + "Disrupting Shoal", + }; + for (Card card : testCards) { + assertTrue(card.name + " should have been " + names[i] + ", i = " + i, card.name.equals(names[i])); + i++; + } + } + + @Test + public void filterByNameRegex() throws Exception { + CardFiltering.filterByField(testCards, "name", FilterType.REGEX, ".+?n"); + + assertEquals("Wrong list size.", 2, testCards.size()); + int i = 0; + String[] names = { + "Coerced Confession", + "Shivan Dragon", + }; + for (Card card : testCards) { + assertTrue(card.name + " should have been " + names[i] + ", i = " + i, card.name.equals(names[i])); + i++; + } + } + + @Test + public void filterByLayoutEquals() throws Exception { + CardFiltering.filterByField(testCards, "layout", FilterType.EQUALS, "flip"); + + assertEquals("Wrong list size.", 1, testCards.size()); + assertEquals("Callow Jushi", testCards.get(0).name); + } + + @Test + public void filterByLayoutContains() throws Exception { + CardFiltering.filterByField(testCards, "layout", FilterType.CONTAINS, "l"); + + assertEquals("Wrong list size.", 8, testCards.size()); + int i = 0; + String[] names = { + "Callow Jushi", + "Coerced Confession", + "Khalni Hydra", + "Nightmare", + "Shivan Dragon", + "Disrupting Shoal", + "Sorin Markov", + "Ugin's Construct", + }; + for (Card card : testCards) { + assertTrue(card.name + " should have been " + names[i] + ", i = " + i, card.name.equals(names[i])); + i++; + } + } + + @Test + public void filterByLayoutRegex() throws Exception { + CardFiltering.filterByField(testCards, "layout", FilterType.REGEX, "fl[a-z]p"); + + assertEquals("Wrong list size.", 1, testCards.size()); + assertEquals("Callow Jushi", testCards.get(0).name); + } + + @Test + public void filterByManaCostEquals() throws Exception { + CardFiltering.filterByField(testCards, "manaCost", FilterType.EQUALS, "{X}{U}{U}"); + + assertEquals("Wrong list size.", 1, testCards.size()); + assertEquals("Disrupting Shoal", testCards.get(0).name); + } + + @Test + public void filterByManaCostContains() throws Exception { + CardFiltering.filterByField(testCards, "manaCost", FilterType.CONTAINS, "B"); + + assertEquals("Wrong list size.", 3, testCards.size()); + int i = 0; + String[] names = { + "Coerced Confession", + "Nightmare", + "Sorin Markov", + }; + for (Card card : testCards) { + assertTrue(card.name + " should have been " + names[i] + ", i = " + i, card.name.equals(names[i])); + i++; + } + } + + @Test + public void filterByManaCostRegex() throws Exception { + CardFiltering.filterByField(testCards, "manaCost", FilterType.REGEX, "(\\{G\\}){8}"); + + assertEquals("Wrong list size.", 1, testCards.size()); + assertEquals("Khalni Hydra", testCards.get(0).name); + } + + @Test + public void filterByCMCEquals() throws Exception { + CardFiltering.filterByField(testCards, "cmc", FilterType.EQUALS, "5"); + + assertEquals("Wrong list size.", 1, testCards.size()); + assertEquals("Coerced Confession", testCards.get(0).name); + } + + @Test + public void filterByCMCContains() throws Exception { + CardFiltering.filterByField(testCards, "cmc", FilterType.CONTAINS, "B"); + + assertEquals("Wrong list size.", 3, testCards.size()); + int i = 0; + String[] names = { + "Coerced Confession", + "Nightmare", + "Sorin Markov", + }; + for (Card card : testCards) { + assertTrue(card.name + " should have been " + names[i] + ", i = " + i, card.name.equals(names[i])); + i++; + } + } + + @Test + public void filterByCMCRegex() throws Exception { + CardFiltering.filterByField(testCards, "cmc", FilterType.REGEX, "(\\{G\\}){8}"); + + assertEquals("Wrong list size.", 1, testCards.size()); + assertEquals("Khalni Hydra", testCards.get(0).name); + } + + @Test + public void filterByType() throws Exception { + + } + + @Test + public void filterByRarity() throws Exception { + + } + + @Test + public void filterByText() throws Exception { + + } + + @Test + public void filterByFlavor() throws Exception { + + } + + @Test + public void filterByArtist() throws Exception { + + } + + @Test + public void filterByNumber() throws Exception { + + } + + @Test + public void filterByPower() throws Exception { + + } + + @Test + public void filterByToughness() throws Exception { + + } + + @Test + public void filterByLoyalty() throws Exception { + + } + + @Test + public void filterByMultiverseID() throws Exception { + + } + + @Test + public void filterByImageName() throws Exception { + + } + + @Test + public void filterByWatermark() throws Exception { + + } + + @Test + public void filterBySetCode() throws Exception { + + } + + @Test + public void filterByImageCode() throws Exception { + + } +} diff --git a/test/eu/equalparts/cardbase/sorting/CardSortingTest.java b/test/eu/equalparts/cardbase/sorting/CardSortingTest.java index 64a33b5..4ec0f5e 100644 --- a/test/eu/equalparts/cardbase/sorting/CardSortingTest.java +++ b/test/eu/equalparts/cardbase/sorting/CardSortingTest.java @@ -2,11 +2,12 @@ package eu.equalparts.cardbase.sorting; import static org.junit.Assert.assertTrue; -import java.util.Collection; import java.util.List; import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; @@ -21,6 +22,9 @@ import eu.equalparts.cardbase.cards.Card; */ public class CardSortingTest { private static List<Card> testCards; + + @Rule + public final ExpectedException exception = ExpectedException.none(); @BeforeClass public static void setUpBeforeClass() throws Exception { @@ -30,7 +34,7 @@ public class CardSortingTest { @Test public void sortByName() throws Exception { - Collection<Card> sortedCards = CardSorting.sortByField(testCards, "name"); + CardSorting.sortByField(testCards, "name"); int i = 0; String[] names = { "Callow Jushi", @@ -42,7 +46,7 @@ public class CardSortingTest { "Sorin Markov", "Ugin's Construct", }; - for (Card card : sortedCards) { + for (Card card : testCards) { assertTrue(card.name + " should have been " + names[i] + ", i = " + i, card.name.equals(names[i])); i++; } @@ -50,7 +54,7 @@ public class CardSortingTest { @Test public void sortByLayout() throws Exception { - Collection<Card> sortedCards = CardSorting.sortByField(testCards, "layout"); + CardSorting.sortByField(testCards, "layout"); int i = 0; String[] layouts = { "flip", @@ -62,7 +66,7 @@ public class CardSortingTest { "normal", "normal", }; - for (Card card : sortedCards) { + for (Card card : testCards) { assertTrue(card.layout + " should have been " + layouts[i] + ", i = " + i, card.layout.equals(layouts[i])); i++; } @@ -70,7 +74,7 @@ public class CardSortingTest { @Test public void sortByManaCost() throws Exception { - Collection<Card> sortedCards = CardSorting.sortByField(testCards, "manaCost"); + CardSorting.sortByField(testCards, "manaCost"); int i = 0; String[] costs = { "{1}{U}{U}", @@ -82,7 +86,7 @@ public class CardSortingTest { "{G}{G}{G}{G}{G}{G}{G}{G}", "{X}{U}{U}", }; - for (Card card : sortedCards) { + for (Card card : testCards) { assertTrue(card.manaCost + " should have been " + costs[i] + ", i = " + i, card.manaCost.equals(costs[i])); i++; } @@ -90,10 +94,10 @@ public class CardSortingTest { @Test public void sortByCMC() throws Exception { - Collection<Card> sortedCards = CardSorting.sortByField(testCards, "cmc"); + CardSorting.sortByField(testCards, "cmc"); int i = 0; Integer[] cmcs = {2, 3, 4, 5, 6, 6, 6, 8}; - for (Card card : sortedCards) { + for (Card card : testCards) { assertTrue(card.cmc + " should have been " + cmcs[i] + ", i = " + i, card.cmc.equals(cmcs[i])); i++; } @@ -101,7 +105,7 @@ public class CardSortingTest { @Test public void sortByType() throws Exception { - Collection<Card> sortedCards = CardSorting.sortByField(testCards, "type"); + CardSorting.sortByField(testCards, "type"); int i = 0; String[] types = { "Artifact Creature ā Construct", @@ -113,7 +117,7 @@ public class CardSortingTest { "Planeswalker ā Sorin", "Sorcery", }; - for (Card card : sortedCards) { + for (Card card : testCards) { assertTrue(card.type + " should have been " + types[i] + ", i = " + i, card.type.equals(types[i])); i++; } @@ -121,7 +125,7 @@ public class CardSortingTest { @Test public void sortByRarity() throws Exception { - Collection<Card> sortedCards = CardSorting.sortByField(testCards, "rarity"); + CardSorting.sortByField(testCards, "rarity"); int i = 0; String[] rarities = { "Uncommon", @@ -133,7 +137,7 @@ public class CardSortingTest { "Mythic Rare", "Mythic Rare", }; - for (Card card : sortedCards) { + for (Card card : testCards) { assertTrue(card.rarity + " should have been " + rarities[i] + ", i = " + i, card.rarity.equals(rarities[i])); i++; } @@ -141,7 +145,7 @@ public class CardSortingTest { @Test public void sortByText() throws Exception { - Collection<Card> sortedCards = CardSorting.sortByField(testCards, "text"); + CardSorting.sortByField(testCards, "text"); int i = 0; String[] texts = { "+2: Sorin Markov deals 2 damage to target creature or player and you gain 2 life.\nā3: Target opponent's life total becomes 10.\nā7: You control target player during that player's next turn.", @@ -153,7 +157,7 @@ public class CardSortingTest { "Whenever you cast a Spirit or Arcane spell, you may put a ki counter on Callow Jushi.\nAt the beginning of the end step, if there are two or more ki counters on Callow Jushi, you may flip it.", "You may exile a blue card with converted mana cost X from your hand rather than pay Disrupting Shoal's mana cost.\nCounter target spell if its converted mana cost is X.", }; - for (Card card : sortedCards) { + for (Card card : testCards) { assertTrue(card.text + " should have been " + texts[i] + ", i = " + i, card.text.equals(texts[i])); i++; } @@ -161,7 +165,7 @@ public class CardSortingTest { @Test public void sortByFlavor() throws Exception { - Collection<Card> sortedCards = CardSorting.sortByField(testCards, "flavor"); + CardSorting.sortByField(testCards, "flavor"); int i = 0; String[] flavors = { "", @@ -173,7 +177,7 @@ public class CardSortingTest { "The undisputed master of the mountains of Shiv.", "While trapping the Eldrazi on Zendikar, Ugin learned little from Sorin, but he gleaned the rudiments of lithomancy from Nahiri.", }; - for (Card card : sortedCards) { + for (Card card : testCards) { String flavor = card.flavor != null ? card.flavor : ""; assertTrue(flavor + " should have been " + flavors[i] + ", i = " + i, flavor.equals(flavors[i])); i++; @@ -182,7 +186,7 @@ public class CardSortingTest { @Test public void sortByArtist() throws Exception { - Collection<Card> sortedCards = CardSorting.sortByField(testCards, "artist"); + CardSorting.sortByField(testCards, "artist"); int i = 0; String[] artists = { "Donato Giancola", @@ -194,7 +198,7 @@ public class CardSortingTest { "Tsutomu Kawade", "Vance Kovacs", }; - for (Card card : sortedCards) { + for (Card card : testCards) { assertTrue(card.artist + " should have been " + artists[i] + ", i = " + i, card.artist.equals(artists[i])); i++; } @@ -202,7 +206,7 @@ public class CardSortingTest { @Test public void sortByNumber() throws Exception { - Collection<Card> sortedCards = CardSorting.sortByField(testCards, "number"); + CardSorting.sortByField(testCards, "number"); int i = 0; String[] numbers = { "31a", @@ -214,7 +218,7 @@ public class CardSortingTest { "276", "281", }; - for (Card card : sortedCards) { + for (Card card : testCards) { assertTrue(card.number + " should have been " + numbers[i] + ", i = " + i, card.number.equals(numbers[i])); i++; } @@ -222,7 +226,7 @@ public class CardSortingTest { @Test public void sortByPower() throws Exception { - Collection<Card> sortedCards = CardSorting.sortByField(testCards, "power"); + CardSorting.sortByField(testCards, "power"); int i = 0; String[] powers = { "", @@ -234,7 +238,7 @@ public class CardSortingTest { "5", "8", }; - for (Card card : sortedCards) { + for (Card card : testCards) { String power = card.power != null ? card.power : ""; assertTrue(power + " should have been " + powers[i] + ", i = " + i, power.equals(powers[i])); i++; @@ -243,7 +247,7 @@ public class CardSortingTest { @Test public void sortByToughness() throws Exception { - Collection<Card> sortedCards = CardSorting.sortByField(testCards, "power"); + CardSorting.sortByField(testCards, "power"); int i = 0; String[] toughnesses = { "", @@ -255,7 +259,7 @@ public class CardSortingTest { "5", "8", }; - for (Card card : sortedCards) { + for (Card card : testCards) { String toughness = card.toughness != null ? card.toughness : ""; assertTrue(toughness + " should have been " + toughnesses[i] + ", i = " + i, toughness.equals(toughnesses[i])); i++; @@ -264,10 +268,10 @@ public class CardSortingTest { @Test public void sortByLoyalty() throws Exception { - Collection<Card> sortedCards = CardSorting.sortByField(testCards, "loyalty"); + CardSorting.sortByField(testCards, "loyalty"); int i = 0; Integer[] loyalties = {0, 0, 0, 0, 0, 0, 0, 4}; - for (Card card : sortedCards) { + for (Card card : testCards) { Integer loyalty = card.loyalty != null ? card.loyalty : 0; assertTrue(loyalty + " should have been " + loyalties[i] + ", i = " + i, loyalty.equals(loyalties[i])); i++; @@ -276,10 +280,10 @@ public class CardSortingTest { @Test public void sortByMultiverseID() throws Exception { - Collection<Card> sortedCards = CardSorting.sortByField(testCards, "multiverseid"); + CardSorting.sortByField(testCards, "multiverseid"); int i = 0; Integer[] ids = {74128, 74489, 193551, 238330, 366408, 383168, 383172, 391949 }; - for (Card card : sortedCards) { + for (Card card : testCards) { Integer id = card.multiverseid != null ? card.multiverseid : 0; assertTrue(id + " should have been " + ids[i] + ", i = " + i, id.equals(ids[i])); i++; @@ -288,7 +292,7 @@ public class CardSortingTest { @Test public void sortByImageName() throws Exception { - Collection<Card> sortedCards = CardSorting.sortByField(testCards, "imageName"); + CardSorting.sortByField(testCards, "imageName"); int i = 0; String[] names = { "callow jushi", @@ -300,7 +304,7 @@ public class CardSortingTest { "sorin markov", "ugin's construct", }; - for (Card card : sortedCards) { + for (Card card : testCards) { assertTrue(card.imageName + " should have been " + names[i] + ", i = " + i, card.imageName.equals(names[i])); i++; } @@ -308,7 +312,7 @@ public class CardSortingTest { @Test public void sortByWatermark() throws Exception { - Collection<Card> sortedCards = CardSorting.sortByField(testCards, "watermark"); + CardSorting.sortByField(testCards, "watermark"); int i = 0; String[] watermarks = { "", @@ -320,7 +324,7 @@ public class CardSortingTest { "", "Dimir", }; - for (Card card : sortedCards) { + for (Card card : testCards) { String watermark = card.watermark != null ? card.watermark : ""; assertTrue(watermark + " should have been " + watermarks[i] + ", i = " + i, watermark.equals(watermarks[i])); i++; @@ -329,7 +333,7 @@ public class CardSortingTest { @Test public void sortBySetCode() throws Exception { - Collection<Card> sortedCards = CardSorting.sortByField(testCards, "setCode"); + CardSorting.sortByField(testCards, "setCode"); int i = 0; String[] sets = { "BOK", @@ -341,14 +345,15 @@ public class CardSortingTest { "M15", "ROE", }; - for (Card card : sortedCards) { + for (Card card : testCards) { assertTrue(card.setCode + " should have been " + sets[i] + ", i = " + i, card.setCode.equals(sets[i])); i++; } } + @Test public void sortByImageCode() throws Exception { - Collection<Card> sortedCards = CardSorting.sortByField(testCards, "imageCode"); + CardSorting.sortByField(testCards, "imageCode"); int i = 0; String[] codes = { "bok", @@ -360,9 +365,18 @@ public class CardSortingTest { "m15", "roe", }; - for (Card card : sortedCards) { + for (Card card : testCards) { assertTrue(card.imageCode + " should have been " + codes[i] + ", i = " + i, card.imageCode.equals(codes[i])); i++; } } + + /* + * Edge cases + */ + @Test + public void sortFieldDoesNotExist() throws Exception { + exception.expect(NoSuchFieldException.class); + CardSorting.sortByField(testCards, "not a field name"); + } } |