aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ch/epfl/xblast/GameStateSerializerTest.java71
-rw-r--r--test/ch/epfl/xblast/client/GameStateDeserializerTest.java28
-rw-r--r--test/ch/epfl/xblast/etape6/RandomTestGame.java11
3 files changed, 34 insertions, 76 deletions
diff --git a/test/ch/epfl/xblast/GameStateSerializerTest.java b/test/ch/epfl/xblast/GameStateSerializerTest.java
deleted file mode 100644
index c0547bb..0000000
--- a/test/ch/epfl/xblast/GameStateSerializerTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
1package ch.epfl.xblast;
2
3import ch.epfl.xblast.server.*;
4import ch.epfl.xblast.server.Level;
5import org.junit.Assert;
6import org.junit.Test;
7
8import java.lang.reflect.Array;
9import java.util.ArrayList;
10import java.util.Arrays;
11import java.util.List;
12import java.util.stream.Collectors;
13
14/**
15 * @author Timothée FLOURE (257420)
16 */
17public class GameStateSerializerTest {
18
19
20 /**
21 * Build a list a bytes corresponding to the serialized data of the initial GameState.
22 *
23 * @return the serialized gametstate
24 */
25 public static List<Byte> getInitialValues() {
26 List<Integer> sourceValues = Arrays.asList(
27 // Serialized Board
28 121, -50, 2, 1, -2, 0, 3, 1, 3, 1, -2, 0, 1, 1, 3, 1, 3,
29 1, 3, 1, 1, -2, 0, 1, 3, 1, 3, -2, 0, -1, 1, 3, 1, 3, 1,
30 3, 1, 1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3,
31 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2,
32 3, 1, 0, 0, 3, 1, 3, 1, 0, 0, 1, 1, 3, 1, 1, 0, 0, 1, 3,
33 1, 3, 0, 0, -1, 1, 3, 1, 1, -5, 2, 3, 2, 3, -5, 2, 3, 2,
34 3, 1, -2, 0, 3, -2, 0, 1, 3, 2, 1, 2,
35 // Explosions (blasts & bombs)
36 4, -128, 16, -63, 16,
37 // Players
38 3, 24, 24, 6,
39 3, -40, 24, 26,
40 3, -40, -72, 46,
41 3, 24, -72, 66,
42 // Ticks
43 60);
44
45 // Build a List of Bytes from the sources values
46 return sourceValues.stream().map(i -> (byte) i.intValue()).collect(Collectors.toList());
47 }
48
49 @Test
50 public void IntialGameStateSerializationTest() {
51 List<Byte> expectedValues = getInitialValues();
52
53 // Get the current values
54 List<Byte> currentValues = GameStateSerializer.serialize(
55 Level.DEFAULT_LEVEL.painter(),
56 Level.DEFAULT_LEVEL.initialState()
57 );
58
59 // Check the first element (number of elements)
60 Assert.assertEquals(
61 Byte.toUnsignedInt(expectedValues.get(0)),
62 Byte.toUnsignedInt(currentValues.get(0))
63 );
64
65 // Check the rest of the data chunk
66 Assert.assertEquals(
67 expectedValues.subList(1,expectedValues.size()),
68 currentValues.subList(1,expectedValues.size())
69 );
70 }
71}
diff --git a/test/ch/epfl/xblast/client/GameStateDeserializerTest.java b/test/ch/epfl/xblast/client/GameStateDeserializerTest.java
index e74728e..418d283 100644
--- a/test/ch/epfl/xblast/client/GameStateDeserializerTest.java
+++ b/test/ch/epfl/xblast/client/GameStateDeserializerTest.java
@@ -1,9 +1,8 @@
1package ch.epfl.xblast.client; 1package ch.epfl.xblast.client;
2 2
3import ch.epfl.xblast.GameStateSerializerTest;
4import org.junit.Test; 3import org.junit.Test;
5 4
6import java.util.List; 5import java.util.Arrays;
7 6
8import static org.junit.Assert.fail; 7import static org.junit.Assert.fail;
9 8
@@ -13,12 +12,33 @@ import static org.junit.Assert.fail;
13 */ 12 */
14public class GameStateDeserializerTest { 13public class GameStateDeserializerTest {
15 14
16 private static final List<Byte> SERIALIZED_INITIAL_GAME_STATE = GameStateSerializerTest.getInitialValues(); 15 private static final Byte[] SERIALIZED_GAME_STATE = {
16 // Serialized Board
17 121, -50, 2, 1, -2, 0, 3, 1, 3, 1, -2, 0, 1, 1, 3, 1, 3,
18 1, 3, 1, 1, -2, 0, 1, 3, 1, 3, -2, 0, -1, 1, 3, 1, 3, 1,
19 3, 1, 1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3,
20 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2,
21 3, 1, 0, 0, 3, 1, 3, 1, 0, 0, 1, 1, 3, 1, 1, 0, 0, 1, 3,
22 1, 3, 0, 0, -1, 1, 3, 1, 1, -5, 2, 3, 2, 3, -5, 2, 3, 2,
23 3, 1, -2, 0, 3, -2, 0, 1, 3, 2, 1, 2,
24
25 // Explosions (blasts & bombs)
26 4, -128, 16, -63, 16,
27
28 // Players
29 3, 24, 24, 6,
30 3, -40, 24, 26,
31 3, -40, -72, 46,
32 3, 24, -72, 66,
33
34 // Ticks
35 60
36 };
17 37
18 @Test 38 @Test
19 public void deserializationTerminates() { 39 public void deserializationTerminates() {
20 try { 40 try {
21 GameStateDeserializer.deserialize(SERIALIZED_INITIAL_GAME_STATE); 41 GameStateDeserializer.deserialize(Arrays.asList(SERIALIZED_GAME_STATE));
22 } catch (Exception e) { 42 } catch (Exception e) {
23 fail(e.getMessage()); 43 fail(e.getMessage());
24 } 44 }
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}