diff options
Diffstat (limited to 'src/ch/epfl/maze/tests/MazeTest.java')
-rw-r--r-- | src/ch/epfl/maze/tests/MazeTest.java | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/ch/epfl/maze/tests/MazeTest.java b/src/ch/epfl/maze/tests/MazeTest.java new file mode 100644 index 0000000..09cbd01 --- /dev/null +++ b/src/ch/epfl/maze/tests/MazeTest.java | |||
@@ -0,0 +1,91 @@ | |||
1 | package ch.epfl.maze.tests; | ||
2 | |||
3 | import junit.framework.TestCase; | ||
4 | |||
5 | import org.junit.Test; | ||
6 | |||
7 | import ch.epfl.maze.physical.Animal; | ||
8 | import ch.epfl.maze.physical.Maze; | ||
9 | import ch.epfl.maze.physical.zoo.Mouse; | ||
10 | import ch.epfl.maze.util.Vector2D; | ||
11 | |||
12 | /** | ||
13 | * Test case for {@code Maze} implementation. | ||
14 | * | ||
15 | */ | ||
16 | |||
17 | public class MazeTest extends TestCase { | ||
18 | |||
19 | private final static int[][] LABYRINTH = { | ||
20 | { 1, 1, 1, 3, 1 }, | ||
21 | { 1, 0, 0, 0, 1 }, | ||
22 | { 1, 2, 1, 1, 1 } | ||
23 | }; | ||
24 | |||
25 | /** | ||
26 | * Test case for several methods in {@code Maze}. | ||
27 | */ | ||
28 | |||
29 | @Test | ||
30 | public void testGeneral() { | ||
31 | Maze maze = new Maze(LABYRINTH); | ||
32 | |||
33 | // initial maze should be solved | ||
34 | assertTrue("Initial maze should be solved", maze.isSolved()); | ||
35 | assertTrue("Initial maze should NOT have animals in it", | ||
36 | maze.getAnimals().size() == 0); | ||
37 | |||
38 | // adds dummy animal | ||
39 | Animal dummy = new Mouse(new Vector2D(3, 0)); | ||
40 | maze.addAnimal(dummy); | ||
41 | |||
42 | assertTrue("Maze Animals should contain one Animal", | ||
43 | maze.getAnimals().size() == 1); | ||
44 | |||
45 | // retrieves dummy anima from Maze | ||
46 | Animal retrieved = maze.getAnimals().get(0); | ||
47 | |||
48 | assertTrue("Maze should contain the Mouse, even at the exit", | ||
49 | maze.hasAnimal(dummy)); | ||
50 | assertTrue("Mouse inside the Maze should be the same as Mouse added", | ||
51 | retrieved == dummy); | ||
52 | assertFalse("Maze with one Mouse even at the exit should NOT be solved", | ||
53 | maze.isSolved()); | ||
54 | |||
55 | // removes dummy animal | ||
56 | maze.removeAnimal(dummy); | ||
57 | |||
58 | assertFalse("Maze should NOT contain the Mouse anymore", | ||
59 | maze.hasAnimal(dummy)); | ||
60 | assertTrue("Maze should NOT have anymore Animal in it", | ||
61 | maze.getAnimals().size() == 0); | ||
62 | assertTrue("Maze without any animal should be solved", maze.isSolved()); | ||
63 | } | ||
64 | |||
65 | /** | ||
66 | * Test case for {@code reset()}. | ||
67 | */ | ||
68 | |||
69 | @Test | ||
70 | public void testReset() { | ||
71 | Maze maze = new Maze(LABYRINTH); | ||
72 | |||
73 | // adds dummy animal | ||
74 | Animal dummy = new Mouse(new Vector2D(2, 2)); | ||
75 | maze.addAnimal(dummy); | ||
76 | |||
77 | // removes dummy animal | ||
78 | maze.removeAnimal(dummy); | ||
79 | |||
80 | // checks reset method | ||
81 | maze.reset(); | ||
82 | |||
83 | assertFalse("Maze should NOT be solved anymore", maze.isSolved()); | ||
84 | assertTrue("Maze should contain the Mouse again", maze.getAnimals().size() == 1); | ||
85 | |||
86 | // checks that animal in maze is not null | ||
87 | Animal retrieved = maze.getAnimals().get(0); | ||
88 | |||
89 | assertTrue("Animal in Maze should be a Mouse", retrieved != null); | ||
90 | } | ||
91 | } | ||