diff options
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java | 39 | ||||
-rw-r--r-- | src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java | 25 |
2 files changed, 60 insertions, 4 deletions
diff --git a/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java b/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java index 0ac96203..952561ac 100644 --- a/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java +++ b/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java @@ -1,10 +1,15 @@ package org.luxons.sevenwonders.game.boards; +import java.util.Arrays; +import java.util.Collections; + import org.junit.experimental.theories.DataPoints; +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.Settings; +import org.luxons.sevenwonders.game.cards.Color; import org.luxons.sevenwonders.game.resources.ResourceType; import org.luxons.sevenwonders.game.resources.Resources; import org.luxons.sevenwonders.game.test.TestUtils; @@ -15,9 +20,14 @@ import static org.junit.Assert.assertTrue; @RunWith(Theories.class) public class BoardTest { - @DataPoints + @DataPoints("gold") public static int[] goldAmounts() { - return new int[]{-5, -1, 0, 1, 2, 3, 5, 10}; + return new int[]{-3, -1, 0, 1, 2, 3}; + } + + @DataPoints("nbCards") + public static int[] nbCards() { + return new int[] {0, 1, 2}; } @DataPoints @@ -25,8 +35,13 @@ public class BoardTest { return ResourceType.values(); } + @DataPoints + public static Color[] colors() { + return Color.values(); + } + @Theory - public void initialGold_respectsSettings(int goldAmountInSettings) { + public void initialGold_respectsSettings(@FromDataPoints("gold") int goldAmountInSettings) { Settings settings = new Settings(); settings.setInitialGold(goldAmountInSettings); Board board = new Board(TestUtils.createWonder(), null, settings); @@ -40,4 +55,22 @@ public class BoardTest { assertTrue(board.getProduction().contains(resources)); } + @Theory + public void getNbCardsOfColor_properCount_singleColor(ResourceType type, @FromDataPoints("nbCards") int nbCards, + @FromDataPoints("nbCards") int nbOtherCards, Color color) { + Board board = new Board(TestUtils.createWonder(type), null, new Settings()); + TestUtils.addCards(board, nbCards, nbOtherCards, color); + assertEquals(nbCards, board.getNbCardsOfColor(Collections.singletonList(color))); + } + + @Theory + public void getNbCardsOfColor_properCount_multiColors(ResourceType type, @FromDataPoints("nbCards") int nbCards1, + @FromDataPoints("nbCards") int nbCards2, @FromDataPoints("nbCards") int nbOtherCards, Color color1, + Color color2) { + Board board = new Board(TestUtils.createWonder(type), null, new Settings()); + TestUtils.addCards(board, nbCards1, color1); + TestUtils.addCards(board, nbCards2, color2); + TestUtils.addCards(board, nbOtherCards, TestUtils.getDifferentColorFrom(color1, color2)); + assertEquals(nbCards1 + nbCards2, board.getNbCardsOfColor(Arrays.asList(color1, color2))); + } }
\ 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 9f4e712a..2f4fd13a 100644 --- a/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java +++ b/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java @@ -1,6 +1,7 @@ package org.luxons.sevenwonders.game.test; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.luxons.sevenwonders.game.Player; @@ -113,10 +114,32 @@ public class TestUtils { return sampleCards; } - public static Card createCard(int num, Color color) { + private static Card createCard(int num, Color color) { return new Card("Test Card " + num, color, new Requirements(), null, null, null, null); } + public static void addCards(Board board, int nbCardsOfColor, int nbOtherCards, Color color) { + addCards(board, nbCardsOfColor, color); + Color otherColor = getDifferentColorFrom(color); + addCards(board, nbOtherCards, otherColor); + } + + public static void addCards(Board board, int nbCards, Color color) { + for (int i = 0; i < nbCards; i++) { + board.addCard(createCard(i, color)); + } + } + + public static Color getDifferentColorFrom(Color... colors) { + List<Color> forbiddenColors = Arrays.asList(colors); + for (Color color : Color.values()) { + if (!forbiddenColors.contains(color)) { + return color; + } + } + throw new IllegalArgumentException("All colors are forbidden!"); + } + public static ScienceProgress createScienceProgress(int compasses, int wheels, int tablets, int jokers) { ScienceProgress progress = new ScienceProgress(); progress.setScience(TestUtils.createScience(compasses, wheels, tablets, jokers)); |