From d29a6a41aace1eaf6e2f9932e748dbcae007471d Mon Sep 17 00:00:00 2001 From: jbion Date: Thu, 22 Dec 2016 18:45:15 +0100 Subject: Add Hands.createHand() test --- .../org/luxons/sevenwonders/game/cards/HandsTest.java | 19 +++++++++++++++++++ .../org/luxons/sevenwonders/game/test/TestUtils.java | 16 +++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) (limited to 'src/test/java') diff --git a/src/test/java/org/luxons/sevenwonders/game/cards/HandsTest.java b/src/test/java/org/luxons/sevenwonders/game/cards/HandsTest.java index 86763450..4475fd3b 100644 --- a/src/test/java/org/luxons/sevenwonders/game/cards/HandsTest.java +++ b/src/test/java/org/luxons/sevenwonders/game/cards/HandsTest.java @@ -10,6 +10,8 @@ import org.junit.experimental.theories.FromDataPoints; import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; import org.junit.runner.RunWith; +import org.luxons.sevenwonders.game.api.HandCard; +import org.luxons.sevenwonders.game.api.Table; import org.luxons.sevenwonders.game.cards.Hands.PlayerIndexOutOfBoundsException; import org.luxons.sevenwonders.game.test.TestUtils; @@ -137,4 +139,21 @@ public class HandsTest { assertEquals(rotated.get(2), hands.get(1)); assertEquals(rotated.get(0), hands.get(2)); } + + @Test + public void createHand_containsAllCards() { + List hand0 = TestUtils.createSampleCards(0, 5); + List hand1 = TestUtils.createSampleCards(5, 10); + Map> handsMap = new HashMap<>(); + handsMap.put(0, hand0); + handsMap.put(1, hand1); + Hands hands = new Hands(handsMap, 2); + + Table table = TestUtils.createTable(2); + List hand = hands.createHand(table, 0); + + for (HandCard handCard : hand) { + assertTrue(hand0.contains(handCard.getCard())); + } + } } \ No newline at end of file diff --git a/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java b/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java index 2a3bc379..968e4821 100644 --- a/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java +++ b/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java @@ -4,9 +4,11 @@ import java.util.ArrayList; import java.util.List; import org.luxons.sevenwonders.game.Settings; +import org.luxons.sevenwonders.game.api.Table; import org.luxons.sevenwonders.game.boards.Board; import org.luxons.sevenwonders.game.cards.Card; import org.luxons.sevenwonders.game.cards.Color; +import org.luxons.sevenwonders.game.cards.Requirements; import org.luxons.sevenwonders.game.resources.Production; import org.luxons.sevenwonders.game.resources.ResourceType; import org.luxons.sevenwonders.game.resources.Resources; @@ -14,6 +16,18 @@ import org.luxons.sevenwonders.game.wonders.Wonder; public class TestUtils { + public static Table createTable(int nbPlayers) { + return new Table(createBoards(nbPlayers)); + } + + public static List createBoards(int count) { + List boards = new ArrayList<>(count); + for (int i = 0; i < count; i++) { + boards.add(createBoard(ResourceType.WOOD)); + } + return boards; + } + public static Board createBoard(ResourceType initialResource) { Settings settings = new Settings(); Wonder wonder = new Wonder("Test Wonder " + initialResource.getSymbol(), initialResource); @@ -58,7 +72,7 @@ public class TestUtils { public 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)); + sampleCards.add(new Card("Test Card " + i, Color.BLUE, new Requirements(), null, null, null, null)); } return sampleCards; } -- cgit