aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/ch/epfl/xblast/ArgumentCheckerTest.java36
-rw-r--r--test/ch/epfl/xblast/BlockEnumTests.java87
-rw-r--r--test/ch/epfl/xblast/BoardTests.java217
-rw-r--r--test/ch/epfl/xblast/CellTest.java60
-rw-r--r--test/ch/epfl/xblast/CellTest05.java22
-rw-r--r--test/ch/epfl/xblast/DirectionTest.java11
-rw-r--r--test/ch/epfl/xblast/GameStateTest05.java512
-rw-r--r--test/ch/epfl/xblast/GameStateTestUtils.java119
-rw-r--r--test/ch/epfl/xblast/ListsTests.java105
-rw-r--r--test/ch/epfl/xblast/SubCellTest.java72
-rw-r--r--test/ch/epfl/xblast/SubCellTest05.java27
-rw-r--r--test/ch/epfl/xblast/TestEtape4.java332
-rw-r--r--test/ch/epfl/xblast/TicksTest.java30
-rw-r--r--test/ch/epfl/xblast/etape6/BonusTest.java209
-rw-r--r--test/ch/epfl/xblast/etape6/DirectionChangeTest.java324
-rw-r--r--test/ch/epfl/xblast/etape6/DirectionEvents.java98
-rw-r--r--test/ch/epfl/xblast/etape6/GameSimulation.java143
-rw-r--r--test/ch/epfl/xblast/etape6/LifeTest.java176
-rw-r--r--test/ch/epfl/xblast/etape6/RandomTestGame.java86
-rw-r--r--test/ch/epfl/xblast/etape6/events/Event.java8
-rw-r--r--test/ch/epfl/xblast/etape6/events/EventSequence.java56
-rw-r--r--test/ch/epfl/xblast/etape6/events/PlayerEvent.java52
-rw-r--r--test/ch/epfl/xblast/etape6/events/PlayerState.java80
-rw-r--r--test/ch/epfl/xblast/etape6/generator/EventsGenerator.java81
-rw-r--r--test/ch/epfl/xblast/etape6/generator/PlayersEventsGenerator.java42
-rw-r--r--test/ch/epfl/xblast/server/BombTest.java201
-rw-r--r--test/ch/epfl/xblast/server/PlayerTest.java553
-rw-r--r--test/stage6files/direction_changes_players_positions.txt12
-rw-r--r--test/stage6files/playerleavesbombedcell_positions.txt72
-rw-r--r--test/stage6files/playerstopsnextcentral_positions.txt72
-rw-r--r--test/stage6files/randomgame_positions.txt3512
-rw-r--r--test/stage6files/stuckonbomb_positions.txt920
-rw-r--r--test/stage6files/stuckoncrumblingwall_positions.txt540
-rw-r--r--test/stage6files/stuckonwall_positions.txt16
34 files changed, 8879 insertions, 4 deletions
diff --git a/test/ch/epfl/xblast/ArgumentCheckerTest.java b/test/ch/epfl/xblast/ArgumentCheckerTest.java
new file mode 100644
index 0000000..b439700
--- /dev/null
+++ b/test/ch/epfl/xblast/ArgumentCheckerTest.java
@@ -0,0 +1,36 @@
1package ch.epfl.xblast;
2
3import org.junit.Test;
4
5import static ch.epfl.xblast.ArgumentChecker.requireNonNegative;
6import static org.junit.Assert.assertEquals;
7
8/**
9 * @author EPFL
10 */
11public class ArgumentCheckerTest {
12
13 @Test
14 public void requireNonNegativeAcceptPositives() {
15 assertEquals("Zero is accepted", 0, requireNonNegative(0));
16 assertEquals("One is accepted", 1, requireNonNegative(1));
17 assertEquals("42 is accepted", 42, requireNonNegative(42));
18 assertEquals("Max integer is accepted", Integer.MAX_VALUE, requireNonNegative(Integer.MAX_VALUE));
19 }
20
21 @Test(expected = IllegalArgumentException.class)
22 public void requireNonNegativeRejectMinusOne() {
23 requireNonNegative(-1);
24 }
25
26 @Test(expected = IllegalArgumentException.class)
27 public void requireNonNegativeRejectMinus42() {
28 requireNonNegative(-42);
29 }
30
31 @Test(expected = IllegalArgumentException.class)
32 public void requireNonNegativeRejectMinInteger() {
33 requireNonNegative(Integer.MIN_VALUE);
34 }
35
36}
diff --git a/test/ch/epfl/xblast/BlockEnumTests.java b/test/ch/epfl/xblast/BlockEnumTests.java
new file mode 100644
index 0000000..dcf2939
--- /dev/null
+++ b/test/ch/epfl/xblast/BlockEnumTests.java
@@ -0,0 +1,87 @@
1package ch.epfl.xblast;
2
3import org.junit.Test;
4
5import java.util.NoSuchElementException;
6
7import static ch.epfl.xblast.server.Block.*;
8import static ch.epfl.xblast.server.Bonus.INC_BOMB;
9import static ch.epfl.xblast.server.Bonus.INC_RANGE;
10import static org.junit.Assert.*;
11
12/**
13 * @author EPFL
14 */
15public class BlockEnumTests {
16
17 @Test
18 public void isFreeBehaviourIsCorrect() {
19 assertTrue(FREE.isFree());
20 assertFalse(INDESTRUCTIBLE_WALL.isFree());
21 assertFalse(DESTRUCTIBLE_WALL.isFree());
22 assertFalse(CRUMBLING_WALL.isFree());
23 assertFalse(BONUS_BOMB.isFree());
24 assertFalse(BONUS_RANGE.isFree());
25 }
26
27 @Test
28 public void canHostPlayerBehaviorIsCorrect() {
29 assertTrue(FREE.canHostPlayer());
30 assertTrue(BONUS_BOMB.canHostPlayer());
31 assertTrue(BONUS_RANGE.canHostPlayer());
32 assertFalse(INDESTRUCTIBLE_WALL.canHostPlayer());
33 assertFalse(DESTRUCTIBLE_WALL.canHostPlayer());
34 assertFalse(CRUMBLING_WALL.canHostPlayer());
35 }
36
37 @Test
38 public void castsShadowBehaviourIsCorrect() {
39 assertTrue(INDESTRUCTIBLE_WALL.castsShadow());
40 assertTrue(DESTRUCTIBLE_WALL.castsShadow());
41 assertTrue(CRUMBLING_WALL.castsShadow());
42 assertFalse(FREE.castsShadow());
43 assertFalse(BONUS_BOMB.castsShadow());
44 assertFalse(BONUS_RANGE.castsShadow());
45 }
46
47 @Test(expected = NoSuchElementException.class)
48 public void freeBlockThrowsExceptionWhenRetrievingBonus() {
49 FREE.associatedBonus();
50 }
51
52 @Test(expected = NoSuchElementException.class)
53 public void indestructibleWallBlockThrowsExceptionWhenRetrievingBonus() {
54 INDESTRUCTIBLE_WALL.associatedBonus();
55 }
56
57 @Test(expected = NoSuchElementException.class)
58 public void destructibleWallBlockThrowsExceptionWhenRetrievingBonus() {
59 DESTRUCTIBLE_WALL.associatedBonus();
60 }
61
62 @Test(expected = NoSuchElementException.class)
63 public void crumblingWallBlockThrowsExceptionWhenRetrievingBonus() {
64 CRUMBLING_WALL.associatedBonus();
65 }
66
67 @Test
68 public void bonusBombBlockHasCorrectBonus() {
69 assertEquals(INC_BOMB, BONUS_BOMB.associatedBonus());
70 }
71
72 @Test
73 public void bonusRangeBlockHasCorrectBonus() {
74 assertEquals(INC_RANGE, BONUS_RANGE.associatedBonus());
75 }
76
77 @Test
78 public void isBonusBehaviourIsCorrect() {
79 assertTrue(BONUS_RANGE.isBonus());
80 assertTrue(BONUS_BOMB.isBonus());
81 assertFalse(FREE.isBonus());
82 assertFalse(INDESTRUCTIBLE_WALL.isBonus());
83 assertFalse(DESTRUCTIBLE_WALL.isBonus());
84 assertFalse(CRUMBLING_WALL.isBonus());
85 }
86
87}
diff --git a/test/ch/epfl/xblast/BoardTests.java b/test/ch/epfl/xblast/BoardTests.java
new file mode 100644
index 0000000..7add23f
--- /dev/null
+++ b/test/ch/epfl/xblast/BoardTests.java
@@ -0,0 +1,217 @@
1package ch.epfl.xblast;
2
3import ch.epfl.cs108.Sq;
4import ch.epfl.xblast.server.Block;
5import ch.epfl.xblast.server.Board;
6import org.junit.Test;
7
8import java.util.ArrayList;
9import java.util.Collections;
10import java.util.List;
11
12import static ch.epfl.xblast.server.Block.*;
13import static org.junit.Assert.*;
14
15/**
16 * @author EPFL
17 */
18public class BoardTests {
19
20 @Test
21 public void boardClassIsImmutable() {
22 List<Sq<Block>> matrix = new ArrayList<>(Cell.COUNT);
23
24 for (int i = 0; i < Cell.COUNT; i++) {
25 matrix.add(Sq.constant(INDESTRUCTIBLE_WALL));
26 }
27
28 Board b = new Board(matrix);
29
30 for (int i = 0; i < Cell.COUNT; i++) {
31 matrix.set(i, matrix.get(i).limit(1).concat(Sq.constant(FREE)));
32 }
33
34 for (int y = 0; y < Cell.ROWS; y++) {
35 for (int x = 0; x < Cell.COLUMNS; x++) {
36 assertNotEquals(FREE, b.blocksAt(new Cell(x, y)).tail().head());
37 }
38 }
39
40 }
41
42 @Test(expected = IllegalArgumentException.class)
43 public void emptyListOfBlockSequencesRaisesException() {
44 new Board(new ArrayList<Sq<Block>>());
45 }
46
47 @Test(expected = IllegalArgumentException.class)
48 public void invalidNumberOfBlockSequencesRaisesException() {
49 Sq<Block> freeBlockSequence = Sq.constant(FREE);
50 List<Sq<Block>> wholeBoardList = new ArrayList<>(Cell.COUNT);
51
52 //Creates a board
53 for (int k = 0; k < Cell.COUNT - 1; k++) {
54 wholeBoardList.add(freeBlockSequence);
55 }