summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2016-12-21 12:36:30 +0100
committerjbion <joffrey.bion@amadeus.com>2016-12-21 12:36:30 +0100
commit6ea510e94ee51b221bac4ffe494c0307fc6e1064 (patch)
treea957b49b9514f1c252699f6a929cc85417377fe0 /src/test
parentAdd test for NumericEffectSerializer (diff)
downloadseven-wonders-6ea510e94ee51b221bac4ffe494c0307fc6e1064.tar.gz
seven-wonders-6ea510e94ee51b221bac4ffe494c0307fc6e1064.tar.bz2
seven-wonders-6ea510e94ee51b221bac4ffe494c0307fc6e1064.zip
Add test for Decks
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/DecksTest.java102
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java2
2 files changed, 103 insertions, 1 deletions
diff --git a/src/test/java/org/luxons/sevenwonders/game/DecksTest.java b/src/test/java/org/luxons/sevenwonders/game/DecksTest.java
new file mode 100644
index 00000000..a00e9c76
--- /dev/null
+++ b/src/test/java/org/luxons/sevenwonders/game/DecksTest.java
@@ -0,0 +1,102 @@
+package org.luxons.sevenwonders.game;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.luxons.sevenwonders.game.Decks.CardNotFoundException;
+import org.luxons.sevenwonders.game.cards.Card;
+import org.luxons.sevenwonders.game.cards.Color;
+
+import static org.junit.Assert.*;
+
+public class DecksTest {
+
+ private static Decks createDecks(int nbAges, int nbCardsPerAge) {
+ Map<Integer, List<Card>> cardsPerAge = new HashMap<>();
+ for (int age = 1; age <= nbAges; age++) {
+ int firstCardNumber = (age - 1) * nbCardsPerAge;
+ cardsPerAge.put(age, createSampleCards(firstCardNumber, nbCardsPerAge));
+ }
+ return new Decks(cardsPerAge);
+ }
+
+ private static List<Card> createSampleCards(int fromIndex, int nbCards) {
+ List<Card> sampleCards = new ArrayList<>();
+ for (int i = fromIndex; i < fromIndex + nbCards; i++) {
+ sampleCards.add(new Card("Test Card " + i, Color.BLUE, null, null, null, null, null));
+ }
+ return sampleCards;
+ }
+
+ @Test(expected = CardNotFoundException.class)
+ public void getCard_failsOnNullNameWhenDeckIsEmpty() {
+ Decks decks = createDecks(0, 0);
+ decks.getCard(null);
+ }
+
+ @Test(expected = CardNotFoundException.class)
+ public void getCard_failsOnEmptyNameWhenDeckIsEmpty() {
+ Decks decks = createDecks(0, 0);
+ decks.getCard("");
+ }
+
+ @Test(expected = CardNotFoundException.class)
+ public void getCard_failsWhenDeckIsEmpty() {
+ Decks decks = createDecks(0, 0);
+ decks.getCard("Any name");
+ }
+
+ @Test(expected = CardNotFoundException.class)
+ public void getCard_failsWhenCardIsNotFound() {
+ Decks decks = createDecks(3, 20);
+ decks.getCard("Unknown name");
+ }
+
+ @Test
+ public void getCard_succeedsWhenCardIsFound() {
+ Decks decks = createDecks(3, 20);
+ Card card = decks.getCard("Test Card 3");
+ assertEquals("Test Card 3", card.getName());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void deal_failsOnZeroPlayers() {
+ Decks decks = createDecks(3, 20);
+ decks.deal(1, 0);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void deal_failsOnMissingAge() {
+ Decks decks = createDecks(2, 0);
+ decks.deal(4, 10);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void deal_failsWhenTooFewPlayers() {
+ Decks decks = createDecks(3, 28);
+ decks.deal(1, 3);
+ }
+
+ @Test
+ public void deal_succeedsOnZeroCards() {
+ Decks decks = createDecks(3, 0);
+ Map<Integer, List<Card>> hands = decks.deal(1, 10);
+ for (List<Card> hand : hands.values()) {
+ assertTrue(hand.isEmpty());
+ }
+ }
+
+ @Test
+ public void deal_evenDistribution() {
+ int nbCardsPerAge = 12;
+ int nbPlayers = 4;
+ Decks decks = createDecks(3, nbCardsPerAge);
+ Map<Integer, List<Card>> hands = decks.deal(1, nbPlayers);
+ for (List<Card> hand : hands.values()) {
+ assertEquals(nbCardsPerAge / nbPlayers, hand.size());
+ }
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java b/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java
index 62bf376d..cbd2fd71 100644
--- a/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java
+++ b/src/test/java/org/luxons/sevenwonders/game/cards/CardTest.java
@@ -39,7 +39,7 @@ public class CardTest {
List<Effect> effects = Collections.singletonList(treeFarmEffect);
- treeFarmCard = new Card("Tree Farm", Color.BROWN, treeFarmRequirements, "", effects, null);
+ treeFarmCard = new Card("Tree Farm", Color.BROWN, treeFarmRequirements, effects, "", null, null);
}
@Test
bgstack15