From 168494da4601fbdce7578f40c4ec9b1ae127fc5f Mon Sep 17 00:00:00 2001 From: jbion Date: Thu, 22 Dec 2016 01:53:02 +0100 Subject: Move Decks to the cards package --- .../org/luxons/sevenwonders/game/DecksTest.java | 102 --------------------- .../luxons/sevenwonders/game/cards/DecksTest.java | 100 ++++++++++++++++++++ 2 files changed, 100 insertions(+), 102 deletions(-) delete mode 100644 src/test/java/org/luxons/sevenwonders/game/DecksTest.java create mode 100644 src/test/java/org/luxons/sevenwonders/game/cards/DecksTest.java (limited to 'src/test/java/org') diff --git a/src/test/java/org/luxons/sevenwonders/game/DecksTest.java b/src/test/java/org/luxons/sevenwonders/game/DecksTest.java deleted file mode 100644 index a00e9c76..00000000 --- a/src/test/java/org/luxons/sevenwonders/game/DecksTest.java +++ /dev/null @@ -1,102 +0,0 @@ -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> 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 createSampleCards(int fromIndex, int nbCards) { - List 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> hands = decks.deal(1, 10); - for (List hand : hands.values()) { - assertTrue(hand.isEmpty()); - } - } - - @Test - public void deal_evenDistribution() { - int nbCardsPerAge = 12; - int nbPlayers = 4; - Decks decks = createDecks(3, nbCardsPerAge); - Map> hands = decks.deal(1, nbPlayers); - for (List 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/DecksTest.java b/src/test/java/org/luxons/sevenwonders/game/cards/DecksTest.java new file mode 100644 index 00000000..b7fad970 --- /dev/null +++ b/src/test/java/org/luxons/sevenwonders/game/cards/DecksTest.java @@ -0,0 +1,100 @@ +package org.luxons.sevenwonders.game.cards; + +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.cards.Decks.CardNotFoundException; + +import static org.junit.Assert.*; + +public class DecksTest { + + private static Decks createDecks(int nbAges, int nbCardsPerAge) { + Map> 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 createSampleCards(int fromIndex, int nbCards) { + List 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> hands = decks.deal(1, 10); + for (List hand : hands.values()) { + assertTrue(hand.isEmpty()); + } + } + + @Test + public void deal_evenDistribution() { + int nbCardsPerAge = 12; + int nbPlayers = 4; + Decks decks = createDecks(3, nbCardsPerAge); + Map> hands = decks.deal(1, nbPlayers); + for (List hand : hands.values()) { + assertEquals(nbCardsPerAge / nbPlayers, hand.size()); + } + } +} \ No newline at end of file -- cgit