From 0134f15d18fc57affc8da7369d5d2b0deb021ce4 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 25 Apr 2016 14:41:58 +0200 Subject: New code review and refactoring --- test/ch/epfl/xblast/painter/BoardPainterTest.java | 42 ++++++++++++---------- .../epfl/xblast/painter/ExplosionPainterTest.java | 23 ++++++------ test/ch/epfl/xblast/painter/PlayerPainterTest.java | 39 ++++++++++---------- 3 files changed, 57 insertions(+), 47 deletions(-) (limited to 'test/ch/epfl') diff --git a/test/ch/epfl/xblast/painter/BoardPainterTest.java b/test/ch/epfl/xblast/painter/BoardPainterTest.java index 9ac8ad4..050e84f 100644 --- a/test/ch/epfl/xblast/painter/BoardPainterTest.java +++ b/test/ch/epfl/xblast/painter/BoardPainterTest.java @@ -1,34 +1,40 @@ package ch.epfl.xblast.painter; -import ch.epfl.xblast.*; -import ch.epfl.xblast.server.*; -import ch.epfl.xblast.server.painter.*; - -import java.util.Arrays; -import java.util.HashMap; - +import ch.epfl.xblast.Cell; +import ch.epfl.xblast.server.Block; +import ch.epfl.xblast.server.Board; +import ch.epfl.xblast.server.painter.BlockImage; +import ch.epfl.xblast.server.painter.BoardPainter; import org.junit.Assert; import org.junit.Test; +import java.util.Arrays; +import java.util.HashMap; + /** * @author Timothée Floure (257420) + * @author Pacien TRAN-GIRARD (261948) */ public class BoardPainterTest { - public static Board createBoard() { + private static Board createBoard() { Block __ = Block.FREE; Block XX = Block.INDESTRUCTIBLE_WALL; Block xx = Block.DESTRUCTIBLE_WALL; - return Board.ofQuadrantNWBlocksWalled(Arrays.asList(Arrays.asList(__, __, __, __, __, xx, __), - Arrays.asList(__, XX, xx, XX, xx, XX, xx), Arrays.asList(__, xx, __, __, __, xx, __), - Arrays.asList(xx, XX, __, XX, XX, XX, XX), Arrays.asList(__, xx, __, xx, __, __, __), - Arrays.asList(xx, XX, xx, XX, xx, XX, __))); + return Board.ofQuadrantNWBlocksWalled( + Arrays.asList( + Arrays.asList(__, __, __, __, __, xx, __), + Arrays.asList(__, XX, xx, XX, xx, XX, xx), + Arrays.asList(__, xx, __, __, __, xx, __), + Arrays.asList(xx, XX, __, XX, XX, XX, XX), + Arrays.asList(__, xx, __, xx, __, __, __), + Arrays.asList(xx, XX, xx, XX, xx, XX, __))); } @Test public void byteForCellTest() { // Create the blocks map - HashMap blocksMap = new HashMap<>(); + HashMap blocksMap = new HashMap<>(); // Fill the blocks map blocksMap.put(Block.FREE, BlockImage.IRON_FLOOR); @@ -38,20 +44,18 @@ public class BoardPainterTest { blocksMap.put(Block.BONUS_BOMB, BlockImage.BONUS_BOMB); blocksMap.put(Block.BONUS_RANGE, BlockImage.BONUS_RANGE); - // Instanciates the painter + // Instantiates the painter BoardPainter painter = new BoardPainter(blocksMap, BlockImage.IRON_FLOOR_S); // Create a dummy board Board board = createBoard(); - Cell freeCell = new Cell(2,1); - Cell shadowedFreeCell = new Cell(1,1); - Cell walledCell = new Cell(0,0); + Cell freeCell = new Cell(2, 1); + Cell shadowedFreeCell = new Cell(1, 1); + Cell walledCell = new Cell(0, 0); Assert.assertEquals(painter.byteForCell(board, freeCell), BlockImage.IRON_FLOOR.ordinal()); Assert.assertEquals(painter.byteForCell(board, shadowedFreeCell), BlockImage.IRON_FLOOR_S.ordinal()); Assert.assertEquals(painter.byteForCell(board, walledCell), BlockImage.DARK_BLOCK.ordinal()); - } - } diff --git a/test/ch/epfl/xblast/painter/ExplosionPainterTest.java b/test/ch/epfl/xblast/painter/ExplosionPainterTest.java index 204b1ad..a6df54b 100644 --- a/test/ch/epfl/xblast/painter/ExplosionPainterTest.java +++ b/test/ch/epfl/xblast/painter/ExplosionPainterTest.java @@ -1,19 +1,21 @@ package ch.epfl.xblast.painter; -import ch.epfl.xblast.*; -import ch.epfl.xblast.server.*; -import ch.epfl.xblast.server.painter.*; - +import ch.epfl.xblast.Cell; +import ch.epfl.xblast.PlayerID; +import ch.epfl.xblast.server.Bomb; +import ch.epfl.xblast.server.painter.ExplosionPainter; import org.junit.Assert; import org.junit.Test; /** * @author Timothée Floure (257420) + * @author Pacien TRAN-GIRARD (261948) */ public class ExplosionPainterTest { + @Test public void byteForBombTest() { - Cell cell = new Cell(1,1); + Cell cell = new Cell(1, 1); int range = 5; Bomb bomb1 = new Bomb(PlayerID.PLAYER_1, cell, 8, range); @@ -29,9 +31,10 @@ public class ExplosionPainterTest { @Test public void byteForBlastTest() { - Assert.assertEquals((byte) 15,ExplosionPainter.byteForBlast(true,true,true,true)); // NESW - Assert.assertEquals((byte) 0,ExplosionPainter.byteForBlast(false,false,false,false)); // nesw - Assert.assertEquals((byte) 13,ExplosionPainter.byteForBlast(true,true,false,true)); // NEsW - Assert.assertEquals((byte) 4,ExplosionPainter.byteForBlast(false,true,false,false)); // nEsw + Assert.assertEquals((byte) 15, ExplosionPainter.byteForBlast(true, true, true, true)); // NESW + Assert.assertEquals((byte) 0, ExplosionPainter.byteForBlast(false, false, false, false)); // nesw + Assert.assertEquals((byte) 13, ExplosionPainter.byteForBlast(true, true, false, true)); // NEsW + Assert.assertEquals((byte) 4, ExplosionPainter.byteForBlast(false, true, false, false)); // nEsw } -} \ No newline at end of file + +} diff --git a/test/ch/epfl/xblast/painter/PlayerPainterTest.java b/test/ch/epfl/xblast/painter/PlayerPainterTest.java index 32b14a9..5eb20f4 100644 --- a/test/ch/epfl/xblast/painter/PlayerPainterTest.java +++ b/test/ch/epfl/xblast/painter/PlayerPainterTest.java @@ -1,22 +1,24 @@ package ch.epfl.xblast.painter; import ch.epfl.cs108.Sq; -import ch.epfl.xblast.*; -import ch.epfl.xblast.server.*; -import ch.epfl.xblast.server.painter.*; - +import ch.epfl.xblast.Direction; +import ch.epfl.xblast.PlayerID; +import ch.epfl.xblast.SubCell; +import ch.epfl.xblast.server.Player; +import ch.epfl.xblast.server.painter.PlayerPainter; import org.junit.Assert; import org.junit.Test; /** * @author Timothée Floure (257420) + * @author Pacien TRAN-GIRARD (261948) */ public class PlayerPainterTest { - private Player playerGenerator(PlayerID id,Direction direction,Player.LifeState.State state,SubCell position,int lives) { + private Player playerGenerator(PlayerID id, Direction direction, Player.LifeState.State state, SubCell position, int lives) { Sq lifeStates = Sq.constant(new Player.LifeState(lives, state)); Sq directedPositions = Player.DirectedPosition.stopped( - new Player.DirectedPosition(position,direction) + new Player.DirectedPosition(position, direction) ); // id, lifeStates, DirectedPositions, MaxBombs, BombRange return new Player(id, lifeStates, directedPositions, 1, 1); @@ -24,38 +26,39 @@ public class PlayerPainterTest { @Test public void byteForPlayerTest() { - SubCell position = new SubCell(1,1); + SubCell position = new SubCell(1, 1); // Build the players Player player1 = playerGenerator(PlayerID.PLAYER_1, Direction.S, Player.LifeState.State.VULNERABLE, position, - 5 //lives - ); + 5 // lives + ); Player player2 = playerGenerator(PlayerID.PLAYER_2, Direction.S, Player.LifeState.State.DYING, position, - 1 //lives - ); + 1 // lives + ); Player player3 = playerGenerator(PlayerID.PLAYER_3, Direction.N, Player.LifeState.State.VULNERABLE, position, 5 // lives - ); + ); Player player4 = playerGenerator(PlayerID.PLAYER_4, Direction.E, Player.LifeState.State.VULNERABLE, position, 5 // lives - ); + ); // Assert - Assert.assertEquals((byte) 7,PlayerPainter.byteForPlayer(player1,1)); // P1 S1 - Assert.assertEquals((byte) 32,PlayerPainter.byteForPlayer(player2,1)); // P2 losing life - Assert.assertEquals((byte) 40,PlayerPainter.byteForPlayer(player3,2)); // P3 N0 - Assert.assertEquals((byte) 65,PlayerPainter.byteForPlayer(player4,3)); // P4 E2 + Assert.assertEquals((byte) 7, PlayerPainter.byteForPlayer(player1, 1)); // P1 S1 + Assert.assertEquals((byte) 32, PlayerPainter.byteForPlayer(player2, 1)); // P2 losing life + Assert.assertEquals((byte) 40, PlayerPainter.byteForPlayer(player3, 2)); // P3 N0 + Assert.assertEquals((byte) 65, PlayerPainter.byteForPlayer(player4, 3)); // P4 E2 } -} \ No newline at end of file + +} -- cgit v1.2.3