aboutsummaryrefslogtreecommitdiff
path: root/test/ch/epfl
diff options
context:
space:
mode:
authorTimothée Floure2016-05-09 08:55:30 +0200
committerTimothée Floure2016-05-09 08:55:30 +0200
commit55eff1840389058bfc8ce9e5a68356cf801a6a99 (patch)
tree8d06eb2d74f977a1e4422045ecdfd4cab30f8560 /test/ch/epfl
parent7ad963df88e1ad3f537f84db9d8bce6c7f46a6fa (diff)
parentf19b688112598273ab5e1147c185c4ab2a3fe749 (diff)
downloadxblast-55eff1840389058bfc8ce9e5a68356cf801a6a99.tar.gz
Merge branch '09_deserialization'
Diffstat (limited to 'test/ch/epfl')
-rw-r--r--test/ch/epfl/xblast/GameStateSerializerTest.java71
-rw-r--r--test/ch/epfl/xblast/client/GameStateDeserializerTest.java27
-rw-r--r--test/ch/epfl/xblast/server/BlockTest.java2
3 files changed, 99 insertions, 1 deletions
diff --git a/test/ch/epfl/xblast/GameStateSerializerTest.java b/test/ch/epfl/xblast/GameStateSerializerTest.java
new file mode 100644
index 0000000..c0547bb
--- /dev/null
+++ b/test/ch/epfl/xblast/GameStateSerializerTest.java
@@ -0,0 +1,71 @@
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
new file mode 100644
index 0000000..e74728e
--- /dev/null
+++ b/test/ch/epfl/xblast/client/GameStateDeserializerTest.java
@@ -0,0 +1,27 @@
1package ch.epfl.xblast.client;
2
3import ch.epfl.xblast.GameStateSerializerTest;
4import org.junit.Test;
5
6import java.util.List;
7
8import static org.junit.Assert.fail;
9
10/**
11 * @author Timothée FLOURE (257420)
12 * @author Pacien TRAN-GIRARD (261948)
13 */
14public class GameStateDeserializerTest {
15
16 private static final List<Byte> SERIALIZED_INITIAL_GAME_STATE = GameStateSerializerTest.getInitialValues();
17
18 @Test
19 public void deserializationTerminates() {
20 try {
21 GameStateDeserializer.deserialize(SERIALIZED_INITIAL_GAME_STATE);
22 } catch (Exception e) {
23 fail(e.getMessage());
24 }
25 }
26
27}
diff --git a/test/ch/epfl/xblast/server/BlockTest.java b/test/ch/epfl/xblast/server/BlockTest.java
index 31fd08a..9938299 100644
--- a/test/ch/epfl/xblast/server/BlockTest.java
+++ b/test/ch/epfl/xblast/server/BlockTest.java
@@ -7,7 +7,7 @@ import static org.junit.Assert.assertTrue;
7 7
8/** 8/**
9 * @author Timothée FLOURE (257420) 9 * @author Timothée FLOURE (257420)
10 * @author pacien TRAN-GIRARD (261948) 10 * @author Pacien TRAN-GIRARD (261948)
11 */ 11 */
12public class BlockTest { 12public class BlockTest {
13 13