aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/ch/epfl/xblast/GameStateSerializerTest.java71
-rw-r--r--test/ch/epfl/xblast/client/GameStateDeserializerTest.java28
2 files changed, 24 insertions, 75 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 }