summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2017-01-31 00:40:17 +0100
committerJoffrey BION <joffrey.bion@gmail.com>2017-01-31 01:44:35 +0100
commit09391e9bbce343c71595a66c33f2d33d4148c79e (patch)
tree2cadb94d3c6996c04ed39f41852f40b2d618636e /backend
parentAdd public/private production concept (diff)
downloadseven-wonders-09391e9bbce343c71595a66c33f2d33d4148c79e.tar.gz
seven-wonders-09391e9bbce343c71595a66c33f2d33d4148c79e.tar.bz2
seven-wonders-09391e9bbce343c71595a66c33f2d33d4148c79e.zip
Use specific seed for randomness in tests for determinism
Diffstat (limited to 'backend')
-rw-r--r--backend/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java2
-rw-r--r--backend/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java28
2 files changed, 23 insertions, 7 deletions
diff --git a/backend/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java b/backend/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java
index 5756b36a..858a6e2c 100644
--- a/backend/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java
+++ b/backend/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java
@@ -50,7 +50,7 @@ public class BoardTest {
@Theory
public void initialGold_respectsSettings(@FromDataPoints("gold") int goldAmountInSettings) {
- CustomizableSettings customSettings = new CustomizableSettings();
+ CustomizableSettings customSettings = TestUtils.createCustomizableSettings();
customSettings.setInitialGold(goldAmountInSettings);
Settings settings = new Settings(5, customSettings);
Board board = new Board(TestUtils.createWonder(), null, settings);
diff --git a/backend/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java b/backend/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java
index c4fa7059..b8112779 100644
--- a/backend/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java
+++ b/backend/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java
@@ -31,8 +31,20 @@ import org.luxons.sevenwonders.game.wonders.WonderStage;
public class TestUtils {
+ private static final long SEED = 42;
+
+ public static CustomizableSettings createCustomizableSettings() {
+ CustomizableSettings customizableSettings = new CustomizableSettings();
+ customizableSettings.setRandomSeedForTests(SEED);
+ return customizableSettings;
+ }
+
+ private static Settings createSettings(int nbPlayers) {
+ return new Settings(nbPlayers, createCustomizableSettings());
+ }
+
public static Game createGame(int id, int nbPlayers) {
- Settings settings = new Settings(nbPlayers, new CustomizableSettings());
+ Settings settings = createSettings(nbPlayers);
List<Player> players = TestUtils.createPlayers(nbPlayers);
List<Board> boards = TestUtils.createBoards(nbPlayers);
List<Card> cards = TestUtils.createSampleCards(0, nbPlayers * 7);
@@ -45,10 +57,11 @@ public class TestUtils {
return new Table(createBoards(nbPlayers));
}
- public static List<Board> createBoards(int count) {
+ private static List<Board> createBoards(int count) {
+ Settings settings = createSettings(count);
List<Board> boards = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
- boards.add(createBoard(ResourceType.WOOD));
+ boards.add(createBoard(settings, ResourceType.WOOD));
}
return boards;
}
@@ -65,8 +78,7 @@ public class TestUtils {
return players;
}
- public static Board createBoard(ResourceType initialResource) {
- Settings settings = new Settings(5);
+ private static Board createBoard(Settings settings, ResourceType initialResource) {
Wonder wonder = createWonder(initialResource);
String username = "testUser" + initialResource.getSymbol();
@@ -76,7 +88,11 @@ public class TestUtils {
return new Board(wonder, player, settings);
}
- public static Board createBoard(ResourceType initialResource, ResourceType... production) {
+ public static Board createBoard(ResourceType initialResource) {
+ return createBoard(createSettings(5), initialResource);
+ }
+
+ private static Board createBoard(ResourceType initialResource, ResourceType... production) {
Board board = createBoard(initialResource);
board.getProduction().addAll(createFixedProduction(production));
return board;
bgstack15