summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2017-04-16 19:40:09 +0200
committerJoffrey BION <joffrey.bion@gmail.com>2017-04-16 19:40:09 +0200
commit5d03cbc905bd5522706f6e61ae88422b8fd5363a (patch)
tree8e35752b4a4ed4575e2aa4d1e479fed3b7b3a2c5
parentSimplify Requirements.isAffordedBy() signature (diff)
downloadseven-wonders-5d03cbc905bd5522706f6e61ae88422b8fd5363a.tar.gz
seven-wonders-5d03cbc905bd5522706f6e61ae88422b8fd5363a.tar.bz2
seven-wonders-5d03cbc905bd5522706f6e61ae88422b8fd5363a.zip
Add first draft of Game test
-rw-r--r--backend/src/test/java/org/luxons/sevenwonders/game/GameTest.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/backend/src/test/java/org/luxons/sevenwonders/game/GameTest.java b/backend/src/test/java/org/luxons/sevenwonders/game/GameTest.java
new file mode 100644
index 00000000..a7d10394
--- /dev/null
+++ b/backend/src/test/java/org/luxons/sevenwonders/game/GameTest.java
@@ -0,0 +1,57 @@
+package org.luxons.sevenwonders.game;
+
+import java.util.Collection;
+
+import org.junit.Test;
+import org.luxons.sevenwonders.game.api.Action;
+import org.luxons.sevenwonders.game.api.CustomizableSettings;
+import org.luxons.sevenwonders.game.api.HandCard;
+import org.luxons.sevenwonders.game.api.PlayerMove;
+import org.luxons.sevenwonders.game.api.PlayerTurnInfo;
+import org.luxons.sevenwonders.game.data.GameDefinitionLoader;
+import org.luxons.sevenwonders.game.moves.MoveType;
+import org.luxons.sevenwonders.game.test.TestUtils;
+
+import static org.junit.Assert.assertEquals;
+
+public class GameTest {
+
+ @Test
+ public void test() {
+ int nbPlayers = 5;
+ Game game = createGame(nbPlayers);
+ Collection<PlayerTurnInfo> turnInfos = game.getCurrentTurnInfo();
+
+ assertEquals(nbPlayers, turnInfos.size());
+
+ for (PlayerTurnInfo turnInfo : turnInfos) {
+ Action action = turnInfo.getAction();
+ assertEquals(Action.PLAY, action);
+ assertEquals(1, turnInfo.getCurrentAge());
+ assertEquals(7, turnInfo.getHand().size());
+ PlayerMove move = getFirstAvailableMove(turnInfo);
+ game.prepareCard(turnInfo.getPlayerIndex(), move);
+ }
+ }
+
+ private PlayerMove getFirstAvailableMove(PlayerTurnInfo turnInfo) {
+ for (HandCard handCard : turnInfo.getHand()) {
+ if (handCard.isPlayable()) {
+ return createMove(handCard, MoveType.PLAY);
+ }
+ }
+ return createMove(turnInfo.getHand().get(0), MoveType.DISCARD);
+ }
+
+ private PlayerMove createMove(HandCard handCard, MoveType play) {
+ PlayerMove move = new PlayerMove();
+ move.setCardName(handCard.getCard().getName());
+ move.setType(play);
+ return move;
+ }
+
+ private static Game createGame(int nbPlayers) {
+ CustomizableSettings settings = TestUtils.createCustomizableSettings();
+ return new GameDefinitionLoader().getGameDefinition().initGame(0, settings, nbPlayers);
+ }
+}
bgstack15