diff options
author | Timothée Floure | 2016-05-08 14:11:48 +0200 |
---|---|---|
committer | Timothée Floure | 2016-05-08 14:11:48 +0200 |
commit | 4c7d7b9d422b043503a70c23e48bd39883c8ee20 (patch) | |
tree | b3466b39f960d459947efbdf8a56356e6479c547 | |
parent | 4327d5bc70db49b72119773fc422d5e9b8954fc3 (diff) | |
download | xblast-4c7d7b9d422b043503a70c23e48bd39883c8ee20.tar.gz |
Basic test for GameStateDeserializer
-rw-r--r-- | test/ch/epfl/xblast/GameStateDeserializerTest.java | 26 | ||||
-rw-r--r-- | test/ch/epfl/xblast/GameStateSerializerTest.java | 26 |
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 @@ | |||
1 | package ch.epfl.xblast; | ||
2 | |||
3 | import ch.epfl.xblast.client.*; | ||
4 | import ch.epfl.xblast.server.*; | ||
5 | import ch.epfl.xblast.server.Level; | ||
6 | import org.junit.Assert; | ||
7 | import org.junit.Test; | ||
8 | |||
9 | import java.lang.reflect.Array; | ||
10 | import java.util.ArrayList; | ||
11 | import java.util.Arrays; | ||
12 | import java.util.List; | ||
13 | import java.util.stream.Collectors; | ||
14 | |||
15 | /** | ||
16 | * @author Timothée FLOURE (257420) | ||
17 | */ | ||
18 | public 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 | */ |
17 | public class GameStateSerializerTest { | 17 | public 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 | } |