aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ch/epfl/xblast/GameStateDeserializerTest.java26
-rw-r--r--test/ch/epfl/xblast/GameStateSerializerTest.java26
2 files changed, 44 insertions, 8 deletions
diff --git a/test/ch/epfl/xblast/GameStateDeserializerTest.java b/test/ch/epfl/xblast/GameStateDeserializerTest.java
new file mode 100644
index 0000000..4f4fac1
--- /dev/null
+++ b/test/ch/epfl/xblast/GameStateDeserializerTest.java
@@ -0,0 +1,26 @@
1package ch.epfl.xblast;
2
3import ch.epfl.xblast.client.*;
4import ch.epfl.xblast.server.*;
5import ch.epfl.xblast.server.Level;
6import org.junit.Assert;
7import org.junit.Test;
8
9import java.lang.reflect.Array;
10import java.util.ArrayList;
11import java.util.Arrays;
12import java.util.List;
13import java.util.stream.Collectors;
14
15/**
16 * @author Timothée FLOURE (257420)
17 */
18public class GameStateDeserializerTest {
19 /**
20 * Check if we can deserialize the initial GameState...
21 */
22 @Test
23 public void InitialGameStateDeserializationTest() {
24 GameStateDeserializer.deserialize(GameStateSerializerTest.getInitialValues());
25 }
26}
diff --git a/test/ch/epfl/xblast/GameStateSerializerTest.java b/test/ch/epfl/xblast/GameStateSerializerTest.java
index 881b1ec..c0547bb 100644
--- a/test/ch/epfl/xblast/GameStateSerializerTest.java
+++ b/test/ch/epfl/xblast/GameStateSerializerTest.java
@@ -16,8 +16,13 @@ import java.util.stream.Collectors;
16 */ 16 */
17public class GameStateSerializerTest { 17public class GameStateSerializerTest {
18 18
19 @Test 19
20 public void IntialGameStateSerializationTest() { 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() {
21 List<Integer> sourceValues = Arrays.asList( 26 List<Integer> sourceValues = Arrays.asList(
22 // Serialized Board 27 // Serialized Board
23 121, -50, 2, 1, -2, 0, 3, 1, 3, 1, -2, 0, 1, 1, 3, 1, 3, 28 121, -50, 2, 1, -2, 0, 3, 1, 3, 1, -2, 0, 1, 1, 3, 1, 3,
@@ -37,11 +42,16 @@ public class GameStateSerializerTest {
37 // Ticks 42 // Ticks
38 60); 43 60);
39 44
40 // Build a List of Bytes from the Expected Values 45 // Build a List of Bytes from the sources values
41 List<Byte> expectedValues = sourceValues.stream().map(i -> (byte) i.intValue()).collect(Collectors.toList()); 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();
42 52
43 // Get the actual values 53 // Get the current values
44 List<Byte> actualValues = GameStateSerializer.serialize( 54 List<Byte> currentValues = GameStateSerializer.serialize(
45 Level.DEFAULT_LEVEL.painter(), 55 Level.DEFAULT_LEVEL.painter(),
46 Level.DEFAULT_LEVEL.initialState() 56 Level.DEFAULT_LEVEL.initialState()
47 ); 57 );
@@ -49,13 +59,13 @@ public class GameStateSerializerTest {
49 // Check the first element (number of elements) 59 // Check the first element (number of elements)
50 Assert.assertEquals( 60 Assert.assertEquals(
51 Byte.toUnsignedInt(expectedValues.get(0)), 61 Byte.toUnsignedInt(expectedValues.get(0)),
52 Byte.toUnsignedInt(actualValues.get(0)) 62 Byte.toUnsignedInt(currentValues.get(0))
53 ); 63 );
54 64
55 // Check the rest of the data chunk 65 // Check the rest of the data chunk
56 Assert.assertEquals( 66 Assert.assertEquals(
57 expectedValues.subList(1,expectedValues.size()), 67 expectedValues.subList(1,expectedValues.size()),
58 actualValues.subList(1,expectedValues.size()) 68 currentValues.subList(1,expectedValues.size())
59 ); 69 );
60 } 70 }
61} 71}