aboutsummaryrefslogtreecommitdiff
path: root/test/ch/epfl
diff options
context:
space:
mode:
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