diff options
Diffstat (limited to 'test')
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 @@ | |||
1 | package ch.epfl.xblast; | ||
2 | |||
3 | import org.junit.Test; | ||
4 | |||
5 | import static ch.epfl.xblast.ArgumentChecker.requireNonNegative; | ||
6 | import static org.junit.Assert.assertEquals; | ||
7 | |||
8 | /** | ||
9 | * @author EPFL | ||
10 | */ | ||
11 | public 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 @@ | |||
1 | package ch.epfl.xblast; | ||
2 | |||
3 | import org.junit.Test; | ||
4 | |||
5 | import java.util.NoSuchElementException; | ||
6 | |||
7 | import static ch.epfl.xblast.server.Block.*; | ||
8 | import static ch.epfl.xblast.server.Bonus.INC_BOMB; | ||
9 | import static ch.epfl.xblast.server.Bonus.INC_RANGE; | ||
10 | import static org.junit.Assert.*; | ||
11 | |||
12 | /** | ||
13 | * @author EPFL | ||
14 | */ | ||
15 | public 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 @@ | |||
1 | package ch.epfl.xblast; | ||
2 | |||
3 | import ch.epfl.cs108.Sq; | ||
4 | import ch.epfl.xblast.server.Block; | ||
5 | import ch.epfl.xblast.server.Board; | ||
6 | import org.junit.Test; | ||
7 | |||
8 | import java.util.ArrayList; | ||
9 | import java.util.Collections; | ||
10 | import java.util.List; | ||
11 | |||
12 | import static ch.epfl.xblast.server.Block.*; | ||
13 | import static org.junit.Assert.*; | ||
14 | |||
15 | /** | ||
16 | * @author EPFL | ||
17 | */ | ||
18 | public 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); | ||