From 4c7d7b9d422b043503a70c23e48bd39883c8ee20 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Sun, 8 May 2016 14:11:48 +0200 Subject: Basic test for GameStateDeserializer --- test/ch/epfl/xblast/GameStateDeserializerTest.java | 26 ++++++++++++++++++++++ test/ch/epfl/xblast/GameStateSerializerTest.java | 26 +++++++++++++++------- 2 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 test/ch/epfl/xblast/GameStateDeserializerTest.java (limited to 'test/ch/epfl') 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 @@ +package ch.epfl.xblast; + +import ch.epfl.xblast.client.*; +import ch.epfl.xblast.server.*; +import ch.epfl.xblast.server.Level; +import org.junit.Assert; +import org.junit.Test; + +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author Timothée FLOURE (257420) + */ +public class GameStateDeserializerTest { + /** + * Check if we can deserialize the initial GameState... + */ + @Test + public void InitialGameStateDeserializationTest() { + GameStateDeserializer.deserialize(GameStateSerializerTest.getInitialValues()); + } +} 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; */ public class GameStateSerializerTest { - @Test - public void IntialGameStateSerializationTest() { + + /** + * Build a list a bytes corresponding to the serialized data of the initial GameState. + * + * @return the serialized gametstate + */ + public static List getInitialValues() { List sourceValues = Arrays.asList( // Serialized Board 121, -50, 2, 1, -2, 0, 3, 1, 3, 1, -2, 0, 1, 1, 3, 1, 3, @@ -37,11 +42,16 @@ public class GameStateSerializerTest { // Ticks 60); - // Build a List of Bytes from the Expected Values - List expectedValues = sourceValues.stream().map(i -> (byte) i.intValue()).collect(Collectors.toList()); + // Build a List of Bytes from the sources values + return sourceValues.stream().map(i -> (byte) i.intValue()).collect(Collectors.toList()); + } + + @Test + public void IntialGameStateSerializationTest() { + List expectedValues = getInitialValues(); - // Get the actual values - List actualValues = GameStateSerializer.serialize( + // Get the current values + List currentValues = GameStateSerializer.serialize( Level.DEFAULT_LEVEL.painter(), Level.DEFAULT_LEVEL.initialState() ); @@ -49,13 +59,13 @@ public class GameStateSerializerTest { // Check the first element (number of elements) Assert.assertEquals( Byte.toUnsignedInt(expectedValues.get(0)), - Byte.toUnsignedInt(actualValues.get(0)) + Byte.toUnsignedInt(currentValues.get(0)) ); // Check the rest of the data chunk Assert.assertEquals( expectedValues.subList(1,expectedValues.size()), - actualValues.subList(1,expectedValues.size()) + currentValues.subList(1,expectedValues.size()) ); } } -- cgit v1.2.3