aboutsummaryrefslogtreecommitdiff
path: root/test/ch
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2016-05-06 19:43:41 +0200
committerPacien TRAN-GIRARD2016-05-06 19:43:41 +0200
commitf11a40948bc99d6ed59e927a62e0ff321b266584 (patch)
treea560223f2d5bb59db78af0a9696db1420a8f6591 /test/ch
parent31b29f7418540f956257894560a09f6ccd6ee091 (diff)
downloadxblast-f11a40948bc99d6ed59e927a62e0ff321b266584.tar.gz
Refactor game state serialization test
Diffstat (limited to 'test/ch')
-rw-r--r--test/ch/epfl/xblast/GameStateSerializerTest.java61
-rw-r--r--test/ch/epfl/xblast/server/GameStateSerializerTest.java49
2 files changed, 49 insertions, 61 deletions
diff --git a/test/ch/epfl/xblast/GameStateSerializerTest.java b/test/ch/epfl/xblast/GameStateSerializerTest.java
deleted file mode 100644
index 881b1ec..0000000
--- a/test/ch/epfl/xblast/GameStateSerializerTest.java
+++ /dev/null
@@ -1,61 +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 @Test
20 public void IntialGameStateSerializationTest() {
21 List<Integer> sourceValues = Arrays.asList(
22 // Serialized Board
23 121, -50, 2, 1, -2, 0, 3, 1, 3, 1, -2, 0, 1, 1, 3, 1, 3,
24 1, 3, 1, 1, -2, 0, 1, 3, 1, 3, -2, 0, -1, 1, 3, 1, 3, 1,
25 3, 1, 1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3,
26 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2,
27 3, 1, 0, 0, 3, 1, 3, 1, 0, 0, 1, 1, 3, 1, 1, 0, 0, 1, 3,
28 1, 3, 0, 0, -1, 1, 3, 1, 1, -5, 2, 3, 2, 3, -5, 2, 3, 2,
29 3, 1, -2, 0, 3, -2, 0, 1, 3, 2, 1, 2,
30 // Explosions (blasts & bombs)
31 4, -128, 16, -63, 16,
32 // Players
33 3, 24, 24, 6,
34 3, -40, 24, 26,
35 3, -40, -72, 46,
36 3, 24, -72, 66,
37 // Ticks
38 60);
39
40 // Build a List of Bytes from the Expected Values
41 List<Byte> expectedValues = sourceValues.stream().map(i -> (byte) i.intValue()).collect(Collectors.toList());
42
43 // Get the actual values
44 List<Byte> actualValues = GameStateSerializer.serialize(
45 Level.DEFAULT_LEVEL.painter(),
46 Level.DEFAULT_LEVEL.initialState()
47 );
48
49 // Check the first element (number of elements)
50 Assert.assertEquals(
51 Byte.toUnsignedInt(expectedValues.get(0)),
52 Byte.toUnsignedInt(actualValues.get(0))
53 );
54
55 // Check the rest of the data chunk
56 Assert.assertEquals(
57 expectedValues.subList(1,expectedValues.size()),
58 actualValues.subList(1,expectedValues.size())
59 );
60 }
61}
diff --git a/test/ch/epfl/xblast/server/GameStateSerializerTest.java b/test/ch/epfl/xblast/server/GameStateSerializerTest.java
new file mode 100644
index 0000000..ff8c75a
--- /dev/null
+++ b/test/ch/epfl/xblast/server/GameStateSerializerTest.java
@@ -0,0 +1,49 @@
1package ch.epfl.xblast.server;
2
3import ch.epfl.xblast.server.painter.BoardPainter;
4import org.junit.Test;
5
6import java.util.Arrays;
7import java.util.List;
8
9import static org.junit.Assert.assertEquals;
10
11/**
12 * @author Pacien TRAN-GIRARD (261948)
13 * @author Timothée Floure (257420)
14 */
15public class GameStateSerializerTest {
16
17 private static final BoardPainter BOARD_PAINTER = BoardPainter.DEFAULT_BOARD_PAINTER;
18
19 private static final GameState SAMPLE_GAME_STATE = GameState.DEFAULT_GAME_STATE;
20 private static final Byte[] SERIALIZED_GAME_STATE = {
21 // Serialized Board
22 121, -50, 2, 1, -2, 0, 3, 1, 3, 1, -2, 0, 1, 1, 3, 1, 3,
23 1, 3, 1, 1, -2, 0, 1, 3, 1, 3, -2, 0, -1, 1, 3, 1, 3, 1,
24 3, 1, 1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3,
25 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2,
26 3, 1, 0, 0, 3, 1, 3, 1, 0, 0, 1, 1, 3, 1, 1, 0, 0, 1, 3,
27 1, 3, 0, 0, -1, 1, 3, 1, 1, -5, 2, 3, 2, 3, -5, 2, 3, 2,
28 3, 1, -2, 0, 3, -2, 0, 1, 3, 2, 1, 2,
29
30 // Explosions (blasts & bombs)
31 4, -128, 16, -63, 16,
32
33 // Players
34 3, 24, 24, 6,
35 3, -40, 24, 26,
36 3, -40, -72, 46,
37 3, 24, -72, 66,
38
39 // Ticks
40 60
41 };
42
43 @Test
44 public void isInitialGameStateSerialized() {
45 List<Byte> serialized = GameStateSerializer.serialize(BOARD_PAINTER, SAMPLE_GAME_STATE);
46 assertEquals(Arrays.asList(SERIALIZED_GAME_STATE), serialized);
47 }
48
49}