aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTimothée Floure2016-05-02 12:51:34 +0200
committerTimothée Floure2016-05-02 12:51:34 +0200
commitda02a1baebad3ec350694ee097d9fc25612d8bdc (patch)
treed8acc64fd1e62f6908c45c0ad80ba44113586afc /test
parentd60cd3c353b4132e3d37122a274ecc3cbe43b78e (diff)
parenta73178cc0c313b675d370672c6bd2a5b8d18d817 (diff)
downloadxblast-da02a1baebad3ec350694ee097d9fc25612d8bdc.tar.gz
Merge branch 'master' of ssh://gitlab-ssh.gnugen.ch:2200/floure/cs108-xblast
Diffstat (limited to 'test')
-rw-r--r--test/ch/epfl/xblast/painter/BoardPainterTest.java42
-rw-r--r--test/ch/epfl/xblast/painter/ExplosionPainterTest.java23
-rw-r--r--test/ch/epfl/xblast/painter/PlayerPainterTest.java39
3 files changed, 57 insertions, 47 deletions
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 @@
1package ch.epfl.xblast.painter; 1package ch.epfl.xblast.painter;
2 2
3import ch.epfl.xblast.*; 3import ch.epfl.xblast.Cell;
4import ch.epfl.xblast.server.*; 4import ch.epfl.xblast.server.Block;
5import ch.epfl.xblast.server.painter.*; 5import ch.epfl.xblast.server.Board;
6 6import ch.epfl.xblast.server.painter.BlockImage;
7import java.util.Arrays; 7import ch.epfl.xblast.server.painter.BoardPainter;
8import java.util.HashMap;
9
10import org.junit.Assert; 8import org.junit.Assert;
11import org.junit.Test; 9import org.junit.Test;
12 10
11import java.util.Arrays;
12import java.util.HashMap;
13
13/** 14/**
14 * @author Timothée Floure (257420) 15 * @author Timothée Floure (257420)
16 * @author Pacien TRAN-GIRARD (261948)
15 */ 17 */
16public class BoardPainterTest { 18public class BoardPainterTest {
17 19
18 public static Board createBoard() { 20 private static Board createBoard() {
19 Block __ = Block.FREE; 21 Block __ = Block.FREE;
20 Block XX = Block.INDESTRUCTIBLE_WALL; 22 Block XX = Block.INDESTRUCTIBLE_WALL;
21 Block xx = Block.DESTRUCTIBLE_WALL; 23 Block xx = Block.DESTRUCTIBLE_WALL;
22 return Board.ofQuadrantNWBlocksWalled(Arrays.asList(Arrays.asList(__, __, __, __, __, xx, __), 24 return Board.ofQuadrantNWBlocksWalled(
23 Arrays.asList(__, XX, xx, XX, xx, XX, xx), Arrays.asList(__, xx, __, __, __, xx, __), 25 Arrays.asList(
24 Arrays.asList(xx, XX, __, XX, XX, XX, XX), Arrays.asList(__, xx, __, xx, __, __, __), 26 Arrays.asList(__, __, __, __, __, xx, __),
25 Arrays.asList(xx, XX, xx, XX, xx, XX, __))); 27 Arrays.asList(__, XX, xx, XX, xx, XX, xx),
28 Arrays.asList(__, xx, __, __, __, xx, __),
29 Arrays.asList(xx, XX, __, XX, XX, XX, XX),
30 Arrays.asList(__, xx, __, xx, __, __, __),
31 Arrays.asList(xx, XX, xx, XX, xx, XX, __)));
26 } 32 }
27 33
28 @Test 34 @Test
29 public void byteForCellTest() { 35 public void byteForCellTest() {
30 // Create the blocks map 36 // Create the blocks map
31 HashMap<Block,BlockImage> blocksMap = new HashMap<>(); 37 HashMap<Block, BlockImage> blocksMap = new HashMap<>();
32 38
33 // Fill the blocks map 39 // Fill the blocks map
34 blocksMap.put(Block.FREE, BlockImage.IRON_FLOOR); 40 blocksMap.put(Block.FREE, BlockImage.IRON_FLOOR);
@@ -38,20 +44,18 @@ public class BoardPainterTest {
38 blocksMap.put(Block.BONUS_BOMB, BlockImage.BONUS_BOMB); 44 blocksMap.put(Block.BONUS_BOMB, BlockImage.BONUS_BOMB);
39 blocksMap.put(Block.BONUS_RANGE, BlockImage.BONUS_RANGE); 45 blocksMap.put(Block.BONUS_RANGE, BlockImage.BONUS_RANGE);
40 46
41 // Instanciates the painter 47 // Instantiates the painter
42 BoardPainter painter = new BoardPainter(blocksMap, BlockImage.IRON_FLOOR_S); 48 BoardPainter painter = new BoardPainter(blocksMap, BlockImage.IRON_FLOOR_S);
43 49
44 // Create a dummy board 50 // Create a dummy board
45 Board board = createBoard(); 51 Board board = createBoard();
46 Cell freeCell = new Cell(2,1); 52 Cell freeCell = new Cell(2, 1);
47 Cell shadowedFreeCell = new Cell(1,1); 53 Cell shadowedFreeCell = new Cell(1, 1);
48 Cell walledCell = new Cell(0,0); 54 Cell walledCell = new Cell(0, 0);
49 55
50 Assert.assertEquals(painter.byteForCell(board, freeCell), BlockImage.IRON_FLOOR.ordinal()); 56 Assert.assertEquals(painter.byteForCell(board, freeCell), BlockImage.IRON_FLOOR.ordinal());
51 Assert.assertEquals(painter.byteForCell(board, shadowedFreeCell), BlockImage.IRON_FLOOR_S.ordinal()); 57 Assert.assertEquals(painter.byteForCell(board, shadowedFreeCell), BlockImage.IRON_FLOOR_S.ordinal());
52 Assert.assertEquals(painter.byteForCell(board, walledCell), BlockImage.DARK_BLOCK.ordinal()); 58 Assert.assertEquals(painter.byteForCell(board, walledCell), BlockImage.DARK_BLOCK.ordinal());
53
54 } 59 }
55 60
56
57} 61}
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 @@
1package ch.epfl.xblast.painter; 1package ch.epfl.xblast.painter;
2 2
3import ch.epfl.xblast.*; 3import ch.epfl.xblast.Cell;
4import ch.epfl.xblast.server.*; 4import ch.epfl.xblast.PlayerID;
5import ch.epfl.xblast.server.painter.*; 5import ch.epfl.xblast.server.Bomb;
6 6import ch.epfl.xblast.server.painter.ExplosionPainter;
7import org.junit.Assert; 7import org.junit.Assert;
8import org.junit.Test; 8import org.junit.Test;
9 9
10/** 10/**
11 * @author Timothée Floure (257420) 11 * @author Timothée Floure (257420)
12 * @author Pacien TRAN-GIRARD (261948)
12 */ 13 */
13public class ExplosionPainterTest { 14public class ExplosionPainterTest {
15
14 @Test 16 @Test
15 public void byteForBombTest() { 17 public void byteForBombTest() {
16 Cell cell = new Cell(1,1); 18 Cell cell = new Cell(1, 1);
17 int range = 5; 19 int range = 5;
18 20
19 Bomb bomb1 = new Bomb(PlayerID.PLAYER_1, cell, 8, range); 21 Bomb bomb1 = new Bomb(PlayerID.PLAYER_1, cell, 8, range);
@@ -29,9 +31,10 @@ public class ExplosionPainterTest {
29 31
30 @Test 32 @Test
31 public void byteForBlastTest() { 33 public void byteForBlastTest() {
32 Assert.assertEquals((byte) 15,ExplosionPainter.byteForBlast(true,true,true,true)); // NESW 34 Assert.assertEquals((byte) 15, ExplosionPainter.byteForBlast(true, true, true, true)); // NESW
33 Assert.assertEquals((byte) 0,ExplosionPainter.byteForBlast(false,false,false,false)); // nesw 35 Assert.assertEquals((byte) 0, ExplosionPainter.byteForBlast(false, false, false, false)); // nesw
34 Assert.assertEquals((byte) 13,ExplosionPainter.byteForBlast(true,true,false,true)); // NEsW 36 Assert.assertEquals((byte) 13, ExplosionPainter.byteForBlast(true, true, false, true)); // NEsW
35 Assert.assertEquals((byte) 4,ExplosionPainter.byteForBlast(false,true,false,false)); // nEsw 37 Assert.assertEquals((byte) 4, ExplosionPainter.byteForBlast(false, true, false, false)); // nEsw
36 } 38 }
37} \ No newline at end of file 39
40}
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 @@
1package ch.epfl.xblast.painter; 1package ch.epfl.xblast.painter;
2 2
3import ch.epfl.cs108.Sq; 3import ch.epfl.cs108.Sq;
4import ch.epfl.xblast.*; 4import ch.epfl.xblast.Direction;
5import ch.epfl.xblast.server.*; 5import ch.epfl.xblast.PlayerID;
6import ch.epfl.xblast.server.painter.*; 6import ch.epfl.xblast.SubCell;
7 7import ch.epfl.xblast.server.Player;
8import ch.epfl.xblast.server.painter.PlayerPainter;
8import org.junit.Assert; 9import org.junit.Assert;
9import org.junit.Test; 10import org.junit.Test;
10 11
11/** 12/**
12 * @author Timothée Floure (257420) 13 * @author Timothée Floure (257420)
14 * @author Pacien TRAN-GIRARD (261948)
13 */ 15 */
14public class PlayerPainterTest { 16public class PlayerPainterTest {
15 17
16 private Player playerGenerator(PlayerID id,Direction direction,Player.LifeState.State state,SubCell position,int lives) { 18 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)); 19 Sq<Player.LifeState> lifeStates = Sq.constant(new Player.LifeState(lives, state));
18 Sq<Player.DirectedPosition> directedPositions = Player.DirectedPosition.stopped( 20 Sq<Player.DirectedPosition> directedPositions = Player.DirectedPosition.stopped(
19 new Player.DirectedPosition(position,direction) 21 new Player.DirectedPosition(position, direction)
20 ); 22 );
21 // id, lifeStates, DirectedPositions, MaxBombs, BombRange 23 // id, lifeStates, DirectedPositions, MaxBombs, BombRange
22 return new Player(id, lifeStates, directedPositions, 1, 1); 24 return new Player(id, lifeStates, directedPositions, 1, 1);
@@ -24,38 +26,39 @@ public class PlayerPainterTest {
24 26
25 @Test 27 @Test
26 public void byteForPlayerTest() { 28 public void byteForPlayerTest() {
27 SubCell position = new SubCell(1,1); 29 SubCell position = new SubCell(1, 1);
28 30
29 // Build the players 31 // Build the players
30 Player player1 = playerGenerator(PlayerID.PLAYER_1, 32 Player player1 = playerGenerator(PlayerID.PLAYER_1,
31 Direction.S, 33 Direction.S,
32 Player.LifeState.State.VULNERABLE, 34 Player.LifeState.State.VULNERABLE,
33 position, 35 position,
34 5 //lives 36 5 // lives
35 ); 37 );
36 Player player2 = playerGenerator(PlayerID.PLAYER_2, 38 Player player2 = playerGenerator(PlayerID.PLAYER_2,
37 Direction.S, 39 Direction.S,
38 Player.LifeState.State.DYING, 40 Player.LifeState.State.DYING,
39 position, 41 position,
40 1 //lives 42 1 // lives
41 );