aboutsummaryrefslogtreecommitdiff
path: root/test/ch/epfl/xblast/TestEtape4.java
diff options
context:
space:
mode:
Diffstat (limited to 'test/ch/epfl/xblast/TestEtape4.java')
-rw-r--r--test/ch/epfl/xblast/TestEtape4.java332
1 files changed, 332 insertions, 0 deletions
diff --git a/test/ch/epfl/xblast/TestEtape4.java b/test/ch/epfl/xblast/TestEtape4.java
new file mode 100644
index 0000000..e1c14cd
--- /dev/null
+++ b/test/ch/epfl/xblast/TestEtape4.java
@@ -0,0 +1,332 @@
1package ch.epfl.xblast;
2
3import ch.epfl.cs108.Sq;
4import ch.epfl.xblast.server.*;
5import org.junit.Assert;
6import org.junit.Test;
7
8import java.util.ArrayList;
9import java.util.Arrays;
10import java.util.List;
11import java.util.function.BiConsumer;
12
13import static org.junit.Assert.*;
14
15/**
16 * @author EPFL
17 */
18public class TestEtape4 {
19
20 private static final Cell POS_NW = new Cell(1, 1);
21 private static final Cell POS_NE = new Cell(-2, 1);
22 private static final Cell POS_SE = new Cell(-2, -2);
23 private static final Cell POS_SW = new Cell(1, -2);
24
25 private static Board createBoard() {
26 Block __ = Block.FREE;
27 Block XX = Block.INDESTRUCTIBLE_WALL;
28 Block xx = Block.DESTRUCTIBLE_WALL;
29 return Board.ofQuadrantNWBlocksWalled(
30 Arrays.asList(
31 Arrays.asList(__, __, __, __, __, xx, __),
32 Arrays.asList(__, XX, xx, XX, xx, XX, xx),
33 Arrays.asList(__, xx, __, __, __, xx, __),
34 Arrays.asList(xx, XX, __, XX, XX, XX, XX),
35 Arrays.asList(__, xx, __, xx, __, __, __),
36 Arrays.asList(xx, XX, xx, XX, xx, XX, __)));
37 }
38
39 private static List<Player> createPlayers(int lives, int maxBombs, int bombRange, Cell p1, Cell p2, Cell p3, Cell p4) {
40 return Arrays.asList(
41 new Player(PlayerID.PLAYER_1, lives, p1, maxBombs, bombRange),
42 new Player(PlayerID.PLAYER_2, lives, p2, maxBombs, bombRange),
43 new Player(PlayerID.PLAYER_3, lives, p3, maxBombs, bombRange),
44 new Player(PlayerID.PLAYER_4, lives, p4, maxBombs, bombRange));
45 }
46
47 private static GameState createGameState(int tick) {
48 List<Player> players = new ArrayList<>(createPlayers(3, 2, 3, POS_NW, POS_NE, POS_SE, POS_SW));
49 return new GameState(tick,
50 createBoard(),
51 players,
52 new ArrayList<>(),
53 new ArrayList<>(),
54 new ArrayList<>());
55 }
56
57 @Test
58 public void testApplyBombBonus() {
59 Player p = new Player(PlayerID.PLAYER_1, 3, new Cell(1, 1), 2, 3);
60 int oldBombs = p.maxBombs();
61 Bonus b = Bonus.INC_BOMB;
62
63 p = b.applyTo(p);
64 assertEquals("Bomb bonus should increase maxBombs by one", oldBombs + 1, p.maxBombs());
65 }
66
67 @Test
68 public void testMaxBomb() {
69 Player p = new Player(PlayerID.PLAYER_1, 3, new Cell(1, 1), 2, 3);
70
71 Bonus b = Bonus.INC_BOMB;
72
73 p = b.applyTo(p);
74 for (int i = 0; i < 10; i++) {
75 p = b.applyTo(p);
76 }
77
78 assertEquals("Max bombs can't be greater than 9", 9, p.maxBombs());
79 }
80
81 @Test
82 public void testApplyRangeBonus() {
83 Player p = new Player(PlayerID.PLAYER_1, 3, new Cell(1, 1), 2, 3);
84 int oldRange = p.bombRange();
85 Bonus b = Bonus.INC_RANGE;
86
87 p = b.applyTo(p);
88 assertEquals("Range bonus should increase range by one", oldRange + 1, p.bombRange());
89 }
90
91 @Test
92 public void testMaxRange() {
93 Player p = new Player(PlayerID.PLAYER_1, 3, new Cell(1, 1), 2, 3);
94 Bonus b = Bonus.INC_RANGE;
95
96 p = b.applyTo(p);
97 for (int i = 0; i < 10; i++) {
98 p = b.applyTo(p);
99 }
100
101 assertEquals("Max range can't be greater than 9", 9, p.bombRange());
102 }
103
104 @Test
105 public void testIsBonus() {
106 for (Block block : Block.values()) {
107 switch (block) {
108 case BONUS_BOMB:
109 case BONUS_RANGE:
110 assertTrue("isBonus on bonus should be true", block.isBonus());
111 break;
112 default:
113 assertFalse("isBonus on non bonus should be false", block.isBonus());
114
115 }
116 }
117 }
118
119 /*
120 // Team 2 is doing those tests
121 @Test(expected = NoSuchElementException.class)
122 public void testNonAssociatedBonus() {
123
124 }
125
126 public void testAssociatedBonus() {
127
128 }
129
130 @Test
131 public void testCanHostPlayerBonus() {
132
133 }
134 */
135
136 @Test
137 public void testTimeEnum() {
138 assertEquals(Time.S_PER_MIN, 60);
139 assertEquals(Time.MS_PER_S, 1_000);
140 assertEquals(Time.US_PER_S, 1_000 * 1_000);
141 assertEquals(Time.NS_PER_S, 1_000 * 1_000 * 1_000);
142 }
143
144 @Test(expected = IllegalArgumentException.class)
145 public void testGameStateNegativeTick() {
146 new GameState(-1,
147 createBoard(),
148 createPlayers(3, 2, 3, POS_NW, POS_NE, POS_SE, POS_SW),
149 new ArrayList<>(),
150 new ArrayList<>(),
151 new ArrayList<>());
152 }
153
154 private void constructGameState(List<Player> players) {
155 new GameState(0,
156 createBoard(),
157 players,
158 new ArrayList<>(),
159 new ArrayList<>(),
160 new ArrayList<>());
161 }
162
163 @Test(expected = IllegalArgumentException.class)
164 public void testGameStateLess4Players() {
165 List<Player> p = new ArrayList<>(createPlayers(3, 2, 3, POS_NW, POS_NE, POS_SE, POS_SW));
166 p.remove(0);
167 constructGameState(p);
168 }
169
170 @Test(expected = IllegalArgumentException.class)
171 public void testGameStateGreater4Players() {
172 List<Player> p = new ArrayList<>(createPlayers(3, 2, 3, POS_NW, POS_NE, POS_SE, POS_SW));
173 p.add(new Player(PlayerID.PLAYER_1, 3, new Cell(1, 1), 2, 3));
174 constructGameState(p);
175 }
176
177 @Test(expected = NullPointerException.class)
178 public void testGameStateNullBoard() {
179 List<Player> p = new ArrayList<>(createPlayers(3, 2, 3, POS_NW, POS_NE, POS_SE, POS_SW));
180 new GameState(0,
181 null,
182 p,
183 new ArrayList<>(),
184 new ArrayList<>(),
185 new ArrayList<>());
186 }
187
188 @Test(expected = NullPointerException.class)
189 public void testGameStateNullPlayers() {
190 new GameState(0,
191 createBoard(),
192 null,
193 new ArrayList<>(),
194 new ArrayList<>(),
195 new ArrayList<>());
196 }
197
198 @Test(expected = NullPointerException.class)
199 public void testGameStateNullBombs() {
200 List<Player> p = new ArrayList<>(createPlayers(3, 2, 3, POS_NW, POS_NE, POS_SE, POS_SW));
201 new GameState(0,
202 createBoard(),
203 p,
204 null,
205 new ArrayList<>(),
206 new ArrayList<>());
207 }
208
209 @Test(expected = NullPointerException.class)
210 public void testGameStateNullExplosions() {
211 List<Player> p = new ArrayList<>(createPlayers(3, 2, 3, POS_NW, POS_NE, POS_SE, POS_SW));
212 new GameState(0,
213 createBoard(),
214 p,
215 new ArrayList<>(),
216 null,
217 new ArrayList<>());
218 }
219
220 @Test(expected = NullPointerException.class)
221 public void testGameStateNullBlasts() {
222 List<Player> p = new ArrayList<>(createPlayers(3, 2, 3, POS_NW, POS_NE, POS_SE, POS_SW));
223 new GameState(0,
224 createBoard(),
225 p,
226 new ArrayList<>(),
227 new ArrayList<>(),
228 null);
229 }
230
231 // GameState methods
232 @Test
233 public void testIsGameOverDead() {
234 List<Player> players = new ArrayList<>(createPlayers(0, 2, 3, POS_NW, POS_NE, POS_SE, POS_SW));
235 players.remove(0);
236 players.add(new Player(PlayerID.PLAYER_1, 3, new Cell(1, 1), 2, 3));