From 4b5ceec97b1d01616c025c6ddbcece4455225543 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 9 May 2016 11:29:32 +0200 Subject: Move deserialization test --- test/ch/epfl/xblast/GameStateSerializerTest.java | 71 ---------------------- .../xblast/client/GameStateDeserializerTest.java | 28 +++++++-- 2 files changed, 24 insertions(+), 75 deletions(-) delete mode 100644 test/ch/epfl/xblast/GameStateSerializerTest.java (limited to 'test') diff --git a/test/ch/epfl/xblast/GameStateSerializerTest.java b/test/ch/epfl/xblast/GameStateSerializerTest.java deleted file mode 100644 index c0547bb..0000000 --- a/test/ch/epfl/xblast/GameStateSerializerTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package ch.epfl.xblast; - -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 GameStateSerializerTest { - - - /** - * 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, - 1, 3, 1, 1, -2, 0, 1, 3, 1, 3, -2, 0, -1, 1, 3, 1, 3, 1, - 3, 1, 1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, - 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, - 3, 1, 0, 0, 3, 1, 3, 1, 0, 0, 1, 1, 3, 1, 1, 0, 0, 1, 3, - 1, 3, 0, 0, -1, 1, 3, 1, 1, -5, 2, 3, 2, 3, -5, 2, 3, 2, - 3, 1, -2, 0, 3, -2, 0, 1, 3, 2, 1, 2, - // Explosions (blasts & bombs) - 4, -128, 16, -63, 16, - // Players - 3, 24, 24, 6, - 3, -40, 24, 26, - 3, -40, -72, 46, - 3, 24, -72, 66, - // Ticks - 60); - - // 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 current values - List currentValues = GameStateSerializer.serialize( - Level.DEFAULT_LEVEL.painter(), - Level.DEFAULT_LEVEL.initialState() - ); - - // Check the first element (number of elements) - Assert.assertEquals( - Byte.toUnsignedInt(expectedValues.get(0)), - Byte.toUnsignedInt(currentValues.get(0)) - ); - - // Check the rest of the data chunk - Assert.assertEquals( - expectedValues.subList(1,expectedValues.size()), - currentValues.subList(1,expectedValues.size()) - ); - } -} diff --git a/test/ch/epfl/xblast/client/GameStateDeserializerTest.java b/test/ch/epfl/xblast/client/GameStateDeserializerTest.java index e74728e..418d283 100644 --- a/test/ch/epfl/xblast/client/GameStateDeserializerTest.java +++ b/test/ch/epfl/xblast/client/GameStateDeserializerTest.java @@ -1,9 +1,8 @@ package ch.epfl.xblast.client; -import ch.epfl.xblast.GameStateSerializerTest; import org.junit.Test; -import java.util.List; +import java.util.Arrays; import static org.junit.Assert.fail; @@ -13,12 +12,33 @@ import static org.junit.Assert.fail; */ public class GameStateDeserializerTest { - private static final List SERIALIZED_INITIAL_GAME_STATE = GameStateSerializerTest.getInitialValues(); + private static final Byte[] SERIALIZED_GAME_STATE = { + // Serialized Board + 121, -50, 2, 1, -2, 0, 3, 1, 3, 1, -2, 0, 1, 1, 3, 1, 3, + 1, 3, 1, 1, -2, 0, 1, 3, 1, 3, -2, 0, -1, 1, 3, 1, 3, 1, + 3, 1, 1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, + 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, + 3, 1, 0, 0, 3, 1, 3, 1, 0, 0, 1, 1, 3, 1, 1, 0, 0, 1, 3, + 1, 3, 0, 0, -1, 1, 3, 1, 1, -5, 2, 3, 2, 3, -5, 2, 3, 2, + 3, 1, -2, 0, 3, -2, 0, 1, 3, 2, 1, 2, + + // Explosions (blasts & bombs) + 4, -128, 16, -63, 16, + + // Players + 3, 24, 24, 6, + 3, -40, 24, 26, + 3, -40, -72, 46, + 3, 24, -72, 66, + + // Ticks + 60 + }; @Test public void deserializationTerminates() { try { - GameStateDeserializer.deserialize(SERIALIZED_INITIAL_GAME_STATE); + GameStateDeserializer.deserialize(Arrays.asList(SERIALIZED_GAME_STATE)); } catch (Exception e) { fail(e.getMessage()); } -- cgit v1.2.3