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') 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 From f19b688112598273ab5e1147c185c4ab2a3fe749 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 8 May 2016 20:26:28 +0200 Subject: Refactor deserialization --- test/ch/epfl/xblast/GameStateDeserializerTest.java | 26 --------------------- .../xblast/client/GameStateDeserializerTest.java | 27 ++++++++++++++++++++++ test/ch/epfl/xblast/server/BlockTest.java | 2 +- 3 files changed, 28 insertions(+), 27 deletions(-) delete mode 100644 test/ch/epfl/xblast/GameStateDeserializerTest.java create mode 100644 test/ch/epfl/xblast/client/GameStateDeserializerTest.java (limited to 'test/ch') diff --git a/test/ch/epfl/xblast/GameStateDeserializerTest.java b/test/ch/epfl/xblast/GameStateDeserializerTest.java deleted file mode 100644 index 4f4fac1..0000000 --- a/test/ch/epfl/xblast/GameStateDeserializerTest.java +++ /dev/null @@ -1,26 +0,0 @@ -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/client/GameStateDeserializerTest.java b/test/ch/epfl/xblast/client/GameStateDeserializerTest.java new file mode 100644 index 0000000..e74728e --- /dev/null +++ b/test/ch/epfl/xblast/client/GameStateDeserializerTest.java @@ -0,0 +1,27 @@ +package ch.epfl.xblast.client; + +import ch.epfl.xblast.GameStateSerializerTest; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.fail; + +/** + * @author Timothée FLOURE (257420) + * @author Pacien TRAN-GIRARD (261948) + */ +public class GameStateDeserializerTest { + + private static final List SERIALIZED_INITIAL_GAME_STATE = GameStateSerializerTest.getInitialValues(); + + @Test + public void deserializationTerminates() { + try { + GameStateDeserializer.deserialize(SERIALIZED_INITIAL_GAME_STATE); + } catch (Exception e) { + fail(e.getMessage()); + } + } + +} diff --git a/test/ch/epfl/xblast/server/BlockTest.java b/test/ch/epfl/xblast/server/BlockTest.java index 31fd08a..9938299 100644 --- a/test/ch/epfl/xblast/server/BlockTest.java +++ b/test/ch/epfl/xblast/server/BlockTest.java @@ -7,7 +7,7 @@ import static org.junit.Assert.assertTrue; /** * @author Timothée FLOURE (257420) - * @author pacien TRAN-GIRARD (261948) + * @author Pacien TRAN-GIRARD (261948) */ public class BlockTest { -- cgit v1.2.3