aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ch/epfl/xblast/server/Block.java14
-rw-r--r--test/ch/epfl/xblast/etape6/RandomTestGame.java11
2 files changed, 23 insertions, 2 deletions
diff --git a/src/ch/epfl/xblast/server/Block.java b/src/ch/epfl/xblast/server/Block.java
index 4f3d033..5cb662c 100644
--- a/src/ch/epfl/xblast/server/Block.java
+++ b/src/ch/epfl/xblast/server/Block.java
@@ -55,7 +55,19 @@ public enum Block {
55 /** 55 /**
56 * Pseudo-random source for randomized behaviours. 56 * Pseudo-random source for randomized behaviours.
57 */ 57 */
58 private static final Random RANDOM_SOURCE = new Random(RANDOM_SEED); 58 private static Random RANDOM_SOURCE;
59
60 /**
61 * Resets the random source used for bonus block spawning.
62 * Useful for deterministic tests.
63 */
64 public static void resetRandomGenerator() {
65 RANDOM_SOURCE = new Random(RANDOM_SEED);
66 }
67
68 static {
69 resetRandomGenerator();
70 }
59 71
60 /** 72 /**
61 * Corresponding bonus, or null. 73 * Corresponding bonus, or null.
diff --git a/test/ch/epfl/xblast/etape6/RandomTestGame.java b/test/ch/epfl/xblast/etape6/RandomTestGame.java
index 8192956..90435c8 100644
--- a/test/ch/epfl/xblast/etape6/RandomTestGame.java
+++ b/test/ch/epfl/xblast/etape6/RandomTestGame.java
@@ -9,6 +9,7 @@ import ch.epfl.xblast.server.GameState;
9import ch.epfl.xblast.server.Player; 9import ch.epfl.xblast.server.Player;
10import ch.epfl.xblast.server.Player.DirectedPosition; 10import ch.epfl.xblast.server.Player.DirectedPosition;
11import ch.epfl.xblast.server.debug.RandomEventGenerator; 11import ch.epfl.xblast.server.debug.RandomEventGenerator;
12import org.junit.Before;
12import org.junit.Test; 13import org.junit.Test;
13 14
14import java.io.IOException; 15import java.io.IOException;
@@ -26,6 +27,7 @@ import static org.junit.Assert.assertTrue;
26 * Checks that the player move as in the example for the random game provided as example 27 * Checks that the player move as in the example for the random game provided as example
27 * 28 *
28 * @author EPFL 29 * @author EPFL
30 * @author Pacien TRAN-GIRARD (261948)
29 */ 31 */
30public class RandomTestGame { 32public class RandomTestGame {
31 33
@@ -56,7 +58,6 @@ public class RandomTestGame {
56 new Player(PlayerID.PLAYER_4, lives, p4, maxBombs, bombRange)); 58 new Player(PlayerID.PLAYER_4, lives, p4, maxBombs, bombRange));
57 } 59 }
58 60
59
60 @Test 61 @Test
61 public void testPositionsRandomGame() throws InterruptedException, IOException, URISyntaxException { 62 public void testPositionsRandomGame() throws InterruptedException, IOException, URISyntaxException {
62 String fileName = getClass().getResource("/stage6files/randomgame_positions.txt").toURI().getPath(); 63 String fileName = getClass().getResource("/stage6files/randomgame_positions.txt").toURI().getPath();
@@ -83,4 +84,12 @@ public class RandomTestGame {
83 player_positions.close(); 84 player_positions.close();
84 } 85 }
85 86
87 /**
88 * Resets the random bonus generator.
89 */
90 @Before
91 public void resetRandomSource() {
92 Block.resetRandomGenerator();
93 }
94
86} 95}