From f11a40948bc99d6ed59e927a62e0ff321b266584 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Fri, 6 May 2016 19:43:41 +0200 Subject: Refactor game state serialization test --- test/ch/epfl/xblast/GameStateSerializerTest.java | 61 ---------------------- .../xblast/server/GameStateSerializerTest.java | 49 +++++++++++++++++ 2 files changed, 49 insertions(+), 61 deletions(-) delete mode 100644 test/ch/epfl/xblast/GameStateSerializerTest.java create mode 100644 test/ch/epfl/xblast/server/GameStateSerializerTest.java diff --git a/test/ch/epfl/xblast/GameStateSerializerTest.java b/test/ch/epfl/xblast/GameStateSerializerTest.java deleted file mode 100644 index 881b1ec..0000000 --- a/test/ch/epfl/xblast/GameStateSerializerTest.java +++ /dev/null @@ -1,61 +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 { - - @Test - public void IntialGameStateSerializationTest() { - 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 Expected Values - List expectedValues = sourceValues.stream().map(i -> (byte) i.intValue()).collect(Collectors.toList()); - - // Get the actual values - List actualValues = 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(actualValues.get(0)) - ); - - // Check the rest of the data chunk - Assert.assertEquals( - expectedValues.subList(1,expectedValues.size()), - actualValues.subList(1,expectedValues.size()) - ); - } -} diff --git a/test/ch/epfl/xblast/server/GameStateSerializerTest.java b/test/ch/epfl/xblast/server/GameStateSerializerTest.java new file mode 100644 index 0000000..ff8c75a --- /dev/null +++ b/test/ch/epfl/xblast/server/GameStateSerializerTest.java @@ -0,0 +1,49 @@ +package ch.epfl.xblast.server; + +import ch.epfl.xblast.server.painter.BoardPainter; +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +/** + * @author Pacien TRAN-GIRARD (261948) + * @author Timothée Floure (257420) + */ +public class GameStateSerializerTest { + + private static final BoardPainter BOARD_PAINTER = BoardPainter.DEFAULT_BOARD_PAINTER; + + private static final GameState SAMPLE_GAME_STATE = GameState.DEFAULT_GAME_STATE; + 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 isInitialGameStateSerialized() { + List serialized = GameStateSerializer.serialize(BOARD_PAINTER, SAMPLE_GAME_STATE); + assertEquals(Arrays.asList(SERIALIZED_GAME_STATE), serialized); + } + +} -- cgit v1.2.3