summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/cards/HandsTest.java63
1 files changed, 63 insertions, 0 deletions
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 97cb4625..86763450 100644
--- a/src/test/java/org/luxons/sevenwonders/game/cards/HandsTest.java
+++ b/src/test/java/org/luxons/sevenwonders/game/cards/HandsTest.java
@@ -5,13 +5,30 @@ import java.util.List;
import java.util.Map;
import org.junit.Test;
+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.cards.Hands.PlayerIndexOutOfBoundsException;
import org.luxons.sevenwonders.game.test.TestUtils;
import static org.junit.Assert.*;
+import static org.junit.Assume.*;
+@RunWith(Theories.class)
public class HandsTest {
+ @DataPoints("nbCardsPerPlayer")
+ public static int[] nbCardsPerPlayer() {
+ return new int[] {0, 1, 2, 3, 4, 5, 6, 7};
+ }
+
+ @DataPoints("nbPlayers")
+ public static int[] nbPlayers() {
+ return new int[] {3, 4, 5, 6, 7};
+ }
+
private static Hands createHands(int nbPlayers, int nbCardsPerPlayer) {
Map<Integer, List<Card>> hands = new HashMap<>();
for (int p = 0; p < nbPlayers; p++) {
@@ -39,6 +56,52 @@ public class HandsTest {
assertEquals(hand1, hands.get(1));
}
+ @Theory
+ public void isEmpty_falseWhenAtLeast1_allSame(@FromDataPoints("nbPlayers") int nbPlayers,
+ @FromDataPoints("nbCardsPerPlayer") int nbCardsPerPlayer) {
+ assumeTrue(nbCardsPerPlayer >= 1);
+ Hands hands = createHands(nbPlayers, nbCardsPerPlayer);
+ assertFalse(hands.isEmpty());
+ }
+
+ @Theory
+ public void isEmpty_trueWhenAllEmpty(@FromDataPoints("nbPlayers") int nbPlayers) {
+ Hands hands = createHands(nbPlayers, 0);
+ assertTrue(hands.isEmpty());
+ }
+
+ @Theory
+ public void maxOneCardRemains_falseWhenAtLeast2_allSame(@FromDataPoints("nbPlayers") int nbPlayers,
+ @FromDataPoints("nbCardsPerPlayer") int nbCardsPerPlayer) {
+ assumeTrue(nbCardsPerPlayer >= 2);
+ Hands hands = createHands(nbPlayers, nbCardsPerPlayer);
+ assertFalse(hands.maxOneCardRemains());
+ }
+
+ @Theory
+ public void maxOneCardRemains_trueWhenAtMost1_allSame(@FromDataPoints("nbPlayers") int nbPlayers,
+ @FromDataPoints("nbCardsPerPlayer") int nbCardsPerPlayer) {
+ assumeTrue(nbCardsPerPlayer <= 1);
+ Hands hands = createHands(nbPlayers, nbCardsPerPlayer);
+ assertTrue(hands.maxOneCardRemains());
+ }
+
+ @Theory
+ public void maxOneCardRemains_trueWhenAtMost1_someZero(@FromDataPoints("nbPlayers") int nbPlayers) {
+ Hands hands = createHands(nbPlayers, 1);
+ hands.get(0).remove(0);
+ assertTrue(hands.maxOneCardRemains());
+ }
+
+ @Theory
+ public void gatherAndClear(@FromDataPoints("nbPlayers") int nbPlayers,
+ @FromDataPoints("nbCardsPerPlayer") int nbCardsPerPlayer) {
+ Hands hands = createHands(nbPlayers, nbCardsPerPlayer);
+ List<Card> remainingCards = hands.gatherAndClear();
+ assertEquals(nbPlayers * nbCardsPerPlayer, remainingCards.size());
+ assertTrue(hands.isEmpty());
+ }
+
@Test
public void rotate_doesNotMoveWhenOffsetIsZero() {
Hands hands = createHands(3, 7);
bgstack15