diff options
author | Timothée Floure | 2016-04-30 17:33:41 +0200 |
---|---|---|
committer | Timothée Floure | 2016-04-30 17:33:41 +0200 |
commit | d60cd3c353b4132e3d37122a274ecc3cbe43b78e (patch) | |
tree | 8e3c468e29b00e1468231453f012e76bd524f656 /test/ch | |
parent | 8b92f6267c09c2e8936a853f28ddb6155e3d4ddc (diff) | |
download | xblast-d60cd3c353b4132e3d37122a274ecc3cbe43b78e.tar.gz |
Fix the GameStateSerializer (comply with the subject)
Diffstat (limited to 'test/ch')
-rw-r--r-- | test/ch/epfl/xblast/GameStateSerializerTest.java | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/test/ch/epfl/xblast/GameStateSerializerTest.java b/test/ch/epfl/xblast/GameStateSerializerTest.java index a701d2b..881b1ec 100644 --- a/test/ch/epfl/xblast/GameStateSerializerTest.java +++ b/test/ch/epfl/xblast/GameStateSerializerTest.java | |||
@@ -5,9 +5,11 @@ import ch.epfl.xblast.server.Level; | |||
5 | import org.junit.Assert; | 5 | import org.junit.Assert; |
6 | import org.junit.Test; | 6 | import org.junit.Test; |
7 | 7 | ||
8 | import java.lang.reflect.Array; | ||
8 | import java.util.ArrayList; | 9 | import java.util.ArrayList; |
9 | import java.util.Arrays; | 10 | import java.util.Arrays; |
10 | import java.util.List; | 11 | import java.util.List; |
12 | import java.util.stream.Collectors; | ||
11 | 13 | ||
12 | /** | 14 | /** |
13 | * @author Timothée FLOURE (257420) | 15 | * @author Timothée FLOURE (257420) |
@@ -15,25 +17,45 @@ import java.util.List; | |||
15 | public class GameStateSerializerTest { | 17 | public class GameStateSerializerTest { |
16 | 18 | ||
17 | @Test | 19 | @Test |
18 | public void GameStateSerializerTest() { | 20 | public void IntialGameStateSerializationTest() { |
19 | List<Integer> integerExpectedValues = Arrays.asList(121, -50, 2, 1, -2, 0, 3, 1, 3, 1, -2, 0, 1, 1, 3, 1, 3, | 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, | ||
20 | 1, 3, 1, 1, -2, 0, 1, 3, 1, 3, -2, 0, -1, 1, 3, 1, 3, 1, | 24 | 1, 3, 1, 1, -2, 0, 1, 3, 1, 3, -2, 0, -1, 1, 3, 1, 3, 1, |
21 | 3, 1, 1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, | 25 | 3, 1, 1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, |
22 | 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, | 26 | 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, |
23 | 3, 1, 0, 0, 3, 1, 3, 1, 0, 0, 1, 1, 3, 1, 1, 0, 0, 1, 3, | 27 | 3, 1, 0, 0, 3, 1, 3, 1, 0, 0, 1, 1, 3, 1, 1, 0, 0, 1, 3, |
24 | 1, 3, 0, 0, -1, 1, 3, 1, 1, -5, 2, 3, 2, 3, -5, 2, 3, 2, | 28 | 1, 3, 0, 0, -1, 1, 3, 1, 1, -5, 2, 3, 2, 3, -5, 2, 3, 2, |
25 | 3, 1, -2, 0, 3, -2, 0, 1, 3, 2, 1, 2, 4, -128, 16, -63, | 29 | 3, 1, -2, 0, 3, -2, 0, 1, 3, 2, 1, 2, |
26 | 16, 3, 24, 24, 6, 3, -40, 24, 26, 3, -40, -72, 46, 3, 24, | 30 | // Explosions (blasts & bombs) |
27 | -72, 66, 60); | 31 | 4, -128, 16, -63, 16, |
28 | List<Byte> expectedValues = new ArrayList<>(); | 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); | ||
29 | 39 | ||
30 | for (Integer i : integerExpectedValues) { | 40 | // Build a List of Bytes from the Expected Values |
31 | expectedValues.add((byte) i.intValue()); | 41 | List<Byte> expectedValues = sourceValues.stream().map(i -> (byte) i.intValue()).collect(Collectors.toList()); |
32 | } | ||
33 | 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 | ||
34 | Assert.assertEquals( | 56 | Assert.assertEquals( |
35 | expectedValues, | 57 | expectedValues.subList(1,expectedValues.size()), |
36 | GameStateSerializer.serialize(Level.DEFAULT_LEVEL.painter(), Level.DEFAULT_LEVEL.initialState()) | 58 | actualValues.subList(1,expectedValues.size()) |
37 | ); | 59 | ); |
38 | } | 60 | } |
39 | } | 61 | } |