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