diff options
Diffstat (limited to 'test/ch/epfl')
-rw-r--r-- | test/ch/epfl/xblast/painter/BoardPainterTest.java | 57 | ||||
-rw-r--r-- | test/ch/epfl/xblast/painter/ExplosionPainterTest.java | 37 | ||||
-rw-r--r-- | test/ch/epfl/xblast/painter/PlayerPainterTest.java | 61 |
3 files changed, 155 insertions, 0 deletions
diff --git a/test/ch/epfl/xblast/painter/BoardPainterTest.java b/test/ch/epfl/xblast/painter/BoardPainterTest.java new file mode 100644 index 0000000..9ac8ad4 --- /dev/null +++ b/test/ch/epfl/xblast/painter/BoardPainterTest.java | |||
@@ -0,0 +1,57 @@ | |||
1 | package ch.epfl.xblast.painter; | ||
2 | |||
3 | import ch.epfl.xblast.*; | ||
4 | import ch.epfl.xblast.server.*; | ||
5 | import ch.epfl.xblast.server.painter.*; | ||
6 | |||
7 | import java.util.Arrays; | ||
8 | import java.util.HashMap; | ||
9 | |||
10 | import org.junit.Assert; | ||
11 | import org.junit.Test; | ||
12 | |||
13 | /** | ||
14 | * @author Timothée Floure (257420) | ||
15 | */ | ||
16 | public class BoardPainterTest { | ||
17 | |||
18 | public static Board createBoard() { | ||
19 | Block __ = Block.FREE; | ||
20 | Block XX = Block.INDESTRUCTIBLE_WALL; | ||
21 | Block xx = Block.DESTRUCTIBLE_WALL; | ||
22 | return Board.ofQuadrantNWBlocksWalled(Arrays.asList(Arrays.asList(__, __, __, __, __, xx, __), | ||
23 | Arrays.asList(__, XX, xx, XX, xx, XX, xx), Arrays.asList(__, xx, __, __, __, xx, __), | ||
24 | Arrays.asList(xx, XX, __, XX, XX, XX, XX), Arrays.asList(__, xx, __, xx, __, __, __), | ||
25 | Arrays.asList(xx, XX, xx, XX, xx, XX, __))); | ||
26 | } | ||
27 | |||
28 | @Test | ||
29 | public void byteForCellTest() { | ||
30 | // Create the blocks map | ||
31 | HashMap<Block,BlockImage> blocksMap = new HashMap<>(); | ||
32 | |||
33 | // Fill the blocks map | ||
34 | blocksMap.put(Block.FREE, BlockImage.IRON_FLOOR); | ||
35 | blocksMap.put(Block.DESTRUCTIBLE_WALL, BlockImage.EXTRA); | ||
36 | blocksMap.put(Block.CRUMBLING_WALL, BlockImage.EXTRA_O); | ||
37 | blocksMap.put(Block.INDESTRUCTIBLE_WALL, BlockImage.DARK_BLOCK); | ||
38 | blocksMap.put(Block.BONUS_BOMB, BlockImage.BONUS_BOMB); | ||
39 | blocksMap.put(Block.BONUS_RANGE, BlockImage.BONUS_RANGE); | ||
40 | |||
41 | // Instanciates the painter | ||
42 | BoardPainter painter = new BoardPainter(blocksMap, BlockImage.IRON_FLOOR_S); | ||
43 | |||
44 | // Create a dummy board | ||
45 | Board board = createBoard(); | ||
46 | Cell freeCell = new Cell(2,1); | ||
47 | Cell shadowedFreeCell = new Cell(1,1); | ||
48 | Cell walledCell = new Cell(0,0); | ||
49 | |||
50 | Assert.assertEquals(painter.byteForCell(board, freeCell), BlockImage.IRON_FLOOR.ordinal()); | ||
51 | Assert.assertEquals(painter.byteForCell(board, shadowedFreeCell), BlockImage.IRON_FLOOR_S.ordinal()); | ||
52 | Assert.assertEquals(painter.byteForCell(board, walledCell), BlockImage.DARK_BLOCK.ordinal()); | ||
53 | |||
54 | } | ||
55 | |||
56 | |||
57 | } | ||
diff --git a/test/ch/epfl/xblast/painter/ExplosionPainterTest.java b/test/ch/epfl/xblast/painter/ExplosionPainterTest.java new file mode 100644 index 0000000..204b1ad --- /dev/null +++ b/test/ch/epfl/xblast/painter/ExplosionPainterTest.java | |||
@@ -0,0 +1,37 @@ | |||
1 | package ch.epfl.xblast.painter; | ||
2 | |||
3 | import ch.epfl.xblast.*; | ||
4 | import ch.epfl.xblast.server.*; | ||
5 | import ch.epfl.xblast.server.painter.*; | ||
6 | |||
7 | import org.junit.Assert; | ||
8 | import org.junit.Test; | ||
9 | |||
10 | /** | ||
11 | * @author Timothée Floure (257420) | ||
12 | */ | ||
13 | public class ExplosionPainterTest { | ||
14 | @Test | ||
15 | public void byteForBombTest() { | ||
16 | Cell cell = new Cell(1,1); | ||
17 | int range = 5; | ||
18 | |||
19 | Bomb bomb1 = new Bomb(PlayerID.PLAYER_1, cell, 8, range); | ||
20 | Bomb bomb2 = new Bomb(PlayerID.PLAYER_1, cell, 6, range); | ||
21 | Bomb bomb3 = new Bomb(PlayerID.PLAYER_1, cell, 2, range); | ||
22 | Bomb bomb4 = new Bomb(PlayerID.PLAYER_1, cell, 1, range); | ||
23 | |||
24 | Assert.assertEquals(ExplosionPainter.byteForBomb(bomb1), (byte) 21); // white | ||
25 | Assert.assertEquals(ExplosionPainter.byteForBomb(bomb2), (byte) 20); // black | ||
26 | Assert.assertEquals(ExplosionPainter.byteForBomb(bomb3), (byte) 21); // white | ||
27 | Assert.assertEquals(ExplosionPainter.byteForBomb(bomb4), (byte) 21); // white | ||
28 | } | ||
29 | |||
30 | @Test | ||
31 | public void byteForBlastTest() { | ||
32 | Assert.assertEquals((byte) 15,ExplosionPainter.byteForBlast(true,true,true,true)); // NESW | ||
33 | Assert.assertEquals((byte) 0,ExplosionPainter.byteForBlast(false,false,false,false)); // nesw | ||
34 | Assert.assertEquals((byte) 13,ExplosionPainter.byteForBlast(true,true,false,true)); // NEsW | ||
35 | Assert.assertEquals((byte) 4,ExplosionPainter.byteForBlast(false,true,false,false)); // nEsw | ||
36 | } | ||
37 | } \ No newline at end of file | ||
diff --git a/test/ch/epfl/xblast/painter/PlayerPainterTest.java b/test/ch/epfl/xblast/painter/PlayerPainterTest.java new file mode 100644 index 0000000..32b14a9 --- /dev/null +++ b/test/ch/epfl/xblast/painter/PlayerPainterTest.java | |||
@@ -0,0 +1,61 @@ | |||
1 | package ch.epfl.xblast.painter; | ||
2 | |||
3 | import ch.epfl.cs108.Sq; | ||
4 | import ch.epfl.xblast.*; | ||
5 | import ch.epfl.xblast.server.*; | ||
6 | import ch.epfl.xblast.server.painter.*; | ||
7 | |||
8 | import org.junit.Assert; | ||
9 | import org.junit.Test; | ||
10 | |||
11 | /** | ||
12 | * @author Timothée Floure (257420) | ||
13 | */ | ||
14 | public class PlayerPainterTest { | ||
15 | |||
16 | private Player playerGenerator(PlayerID id,Direction direction,Player.LifeState.State state,SubCell position,int lives) { | ||
17 | Sq<Player.LifeState> lifeStates = Sq.constant(new Player.LifeState(lives, state)); | ||
18 | Sq<Player.DirectedPosition> directedPositions = Player.DirectedPosition.stopped( | ||
19 | new Player.DirectedPosition(position,direction) | ||
20 | ); | ||
21 | // id, lifeStates, DirectedPositions, MaxBombs, BombRange | ||
22 | return new Player(id, lifeStates, directedPositions, 1, 1); | ||
23 | } | ||
24 | |||
25 | @Test | ||
26 | public void byteForPlayerTest() { | ||
27 | SubCell position = new SubCell(1,1); | ||
28 | |||
29 | // Build the players | ||
30 | Player player1 = playerGenerator(PlayerID.PLAYER_1, | ||
31 | Direction.S, | ||
32 | Player.LifeState.State.VULNERABLE, | ||
33 | position, | ||
34 | 5 //lives | ||
35 | ); | ||
36 | Player player2 = playerGenerator(PlayerID.PLAYER_2, | ||
37 | Direction.S, | ||
38 | Player.LifeState.State.DYING, | ||
39 | position, | ||
40 | 1 //lives | ||
41 | ); | ||
42 | Player player3 = playerGenerator(PlayerID.PLAYER_3, | ||
43 | Direction.N, | ||
44 | Player.LifeState.State.VULNERABLE, | ||
45 | position, | ||
46 | 5 // lives | ||
47 | ); | ||
48 | Player player4 = playerGenerator(PlayerID.PLAYER_4, | ||
49 | Direction.E, | ||
50 | Player.LifeState.State.VULNERABLE, | ||
51 | position, | ||
52 | 5 // lives | ||
53 | ); | ||
54 | |||
55 | // Assert | ||
56 | Assert.assertEquals((byte) 7,PlayerPainter.byteForPlayer(player1,1)); // P1 S1 | ||
57 | Assert.assertEquals((byte) 32,PlayerPainter.byteForPlayer(player2,1)); // P2 losing life | ||
58 | Assert.assertEquals((byte) 40,PlayerPainter.byteForPlayer(player3,2)); // P3 N0 | ||
59 | Assert.assertEquals((byte) 65,PlayerPainter.byteForPlayer(player4,3)); // P4 E2 | ||
60 | } | ||
61 | } \ No newline at end of file | ||