summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/tests/DaedalusTest.java
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2015-11-21 10:36:18 +0100
committerPacien TRAN-GIRARD2015-11-21 10:36:18 +0100
commit655ac88f4e73b2df532a451aedf5a561ea1b0d2c (patch)
treeef6f914a465575f313e2b280bf0639d87a4cbd58 /src/ch/epfl/maze/tests/DaedalusTest.java
parent56279eb59ccdea48b18daa027a5095d861b4e2f4 (diff)
downloadmaze-solver-655ac88f4e73b2df532a451aedf5a561ea1b0d2c.tar.gz
Import project structure
Diffstat (limited to 'src/ch/epfl/maze/tests/DaedalusTest.java')
-rw-r--r--src/ch/epfl/maze/tests/DaedalusTest.java123
1 files changed, 123 insertions, 0 deletions
diff --git a/src/ch/epfl/maze/tests/DaedalusTest.java b/src/ch/epfl/maze/tests/DaedalusTest.java
new file mode 100644
index 0000000..34e302f
--- /dev/null
+++ b/src/ch/epfl/maze/tests/DaedalusTest.java
@@ -0,0 +1,123 @@
1package ch.epfl.maze.tests;
2
3import junit.framework.TestCase;
4
5import org.junit.Test;
6
7import ch.epfl.maze.physical.Animal;
8import ch.epfl.maze.physical.Daedalus;
9import ch.epfl.maze.physical.Predator;
10import ch.epfl.maze.physical.Prey;
11import ch.epfl.maze.physical.pacman.Blinky;
12import ch.epfl.maze.physical.pacman.PacMan;
13import ch.epfl.maze.util.Vector2D;
14
15/**
16 * Test case for {@code Daedalus} implementation.
17 *
18 */
19
20public class DaedalusTest extends TestCase {
21
22 private final static int[][] LABYRINTH = {
23 { 1, 1, 1, 1, 1 },
24 { 1, 0, 0, 0, 1 },
25 { 1, 1, 1, 1, 1 }
26 };
27
28 /**
29 * Test case for several methods in {@code Daedalus}.
30 */
31
32 @Test
33 public void testGeneral() {
34 Daedalus daedalus = new Daedalus(LABYRINTH);
35
36 // initial maze should be solved
37 assertTrue("Initial maze should be solved", daedalus.isSolved());
38 assertTrue("Initial maze should NOT have animals in it",
39 daedalus.getAnimals().size() == 0);
40
41 // adds dummy predator and prey
42 Predator dummyPred = new Blinky(new Vector2D(3, 1));
43 Prey dummyPrey = new PacMan(new Vector2D(3, 1));
44 daedalus.addPredator(dummyPred);
45 daedalus.addPrey(dummyPrey);
46
47 assertTrue("Daedalus Predators should contain one Predator",
48 daedalus.getPredators().size() == 1);
49 assertTrue("Daedalus Preys should contain one Prey",
50 daedalus.getPreys().size() == 1);
51 assertTrue("Daedalus Animals should contain one Predator and one Prey",
52 daedalus.getAnimals().size() == 2);
53
54 // retrieves dummy predator and prey from Daedalus
55 Predator retrievedPred = daedalus.getPredators().get(0);
56 Prey retrievedPrey = daedalus.getPreys().get(0);
57
58 assertTrue("Daedalus should contain the added Blinky",
59 daedalus.hasPredator(dummyPred));
60 assertTrue("Daedalus should contain the added PacMan",
61 daedalus.hasPrey(dummyPrey));
62 assertTrue("Predator inside the Daedalus should be the same as Predator added",
63 retrievedPred == dummyPred);
64 assertTrue("Prey inside the Daedalus should be the same as Prey added",
65 retrievedPrey == dummyPrey);
66 assertFalse("Daedalus with one Prey should NOT be solved",
67 daedalus.isSolved());
68
69 // removes dummy predator
70 daedalus.removePredator(dummyPred);
71 daedalus.removePrey(dummyPrey);
72
73 assertFalse("Daedalus should NOT contain Blinky anymore",
74 daedalus.hasPredator(dummyPred));
75 assertFalse("Daedalus should NOT contain PacMan anymore",
76 daedalus.hasPrey(dummyPrey));
77 assertTrue("Daedalus should NOT have anymore Predator in it",
78 daedalus.getPredators().size() == 0);
79 assertTrue("Daedalus should NOT have anymore Prey in it",
80 daedalus.getPreys().size() == 0);
81 assertTrue("Daedalus should NOT have anymore Animal in it",
82 daedalus.getAnimals().size() == 0);
83 assertTrue("Daedalus without any animal should be solved", daedalus.isSolved());
84 }
85
86 /**
87 * Test case for {@code reset()}.
88 */
89
90 @Test
91 public void testReset() {
92 Daedalus daedalus = new Daedalus(LABYRINTH);
93
94 // adds dummy predator and prey
95 Predator dummyPred = new Blinky(new Vector2D(3, 1));
96 Prey dummyPrey = new PacMan(new Vector2D(3, 1));
97 daedalus.addPredator(dummyPred);
98 daedalus.addPrey(dummyPrey);
99
100 // removes dummy animal
101 daedalus.removePredator(dummyPred);
102 daedalus.removePrey(dummyPrey);
103
104 // checks reset method
105 daedalus.reset();
106
107 assertFalse("Daedalus should NOT be solved anymore",
108 daedalus.isSolved());
109 assertTrue("Daedalus should contain Blinky again",
110 daedalus.getPredators().size() == 1);
111 assertTrue("Daedalus should contain PacMan again",
112 daedalus.getPreys().size() == 1);
113 assertTrue("Daedalus should contain Blinky and PacMan again",
114 daedalus.getAnimals().size() == 2);
115
116 // checks that predator in maze is not null
117 Animal retrievedPred = daedalus.getAnimals().get(0);
118 Animal retrievedPrey = daedalus.getAnimals().get(1);
119
120 assertTrue("Animals in Daedalus should be not null", retrievedPred != null);
121 assertTrue("Animals in Daedalus should be not null", retrievedPrey != null);
122 }
123}