summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/tests/GhostsTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch/epfl/maze/tests/GhostsTest.java')
-rw-r--r--src/ch/epfl/maze/tests/GhostsTest.java149
1 files changed, 149 insertions, 0 deletions
diff --git a/src/ch/epfl/maze/tests/GhostsTest.java b/src/ch/epfl/maze/tests/GhostsTest.java
new file mode 100644
index 0000000..4929b5d
--- /dev/null
+++ b/src/ch/epfl/maze/tests/GhostsTest.java
@@ -0,0 +1,149 @@
1package ch.epfl.maze.tests;
2
3import junit.framework.TestCase;
4
5import org.junit.Test;
6
7import ch.epfl.maze.graphics.Display;
8import ch.epfl.maze.physical.Animal;
9import ch.epfl.maze.physical.Daedalus;
10import ch.epfl.maze.physical.Prey;
11import ch.epfl.maze.physical.pacman.Blinky;
12import ch.epfl.maze.physical.pacman.Clyde;
13import ch.epfl.maze.physical.pacman.Inky;
14import ch.epfl.maze.physical.pacman.Pinky;
15import ch.epfl.maze.simulation.DaedalusSimulation;
16import ch.epfl.maze.simulation.Simulation;
17import ch.epfl.maze.util.Direction;
18import ch.epfl.maze.util.LabyrinthGenerator;
19import ch.epfl.maze.util.Vector2D;
20
21/**
22 * Test suite for ghosts implementation.
23 *
24 */
25
26public class GhostsTest extends TestCase {
27
28 /**
29 * Tests the behavior of Blinky.
30 * <p>
31 * In this case, Blinky should go straight to the PacMan's position.
32 */
33
34 @Test
35 public void testBlinky() {
36 int[][] labyrinth = LabyrinthGenerator.getDebugBlinky();
37
38 Daedalus d = new Daedalus(labyrinth);
39 Simulation simulation = new DaedalusSimulation(d);
40
41 d.addPredator(new Blinky(new Vector2D(6, 1)));
42 d.addPrey(new PacMan(new Vector2D(1, 5), false));
43
44 Display display = new Display(simulation);
45 display.setDebug(true);
46 display.run();
47 }
48
49 /**
50 * Tests the behavior of Pinky.
51 * <p>
52 * In this case, Pinky should go back and forth.
53 */
54
55 @Test
56 public void testPinky() {
57 int[][] labyrinth = LabyrinthGenerator.getDebugPinky();
58
59 Daedalus d = new Daedalus(labyrinth);
60 Simulation simulation = new DaedalusSimulation(d);
61
62 d.addPredator(new Pinky(new Vector2D(1, 1)));
63 d.addPrey(new PacMan(new Vector2D(6, 3), true));
64
65 Display display = new Display(simulation);
66 display.setDebug(true);
67 display.run();
68 }
69
70 /**
71 * Tests the behavior of Inky.
72 * <p>
73 * In this case, Inky should target the red tile of the labyrinth.
74 */
75
76 @Test
77 public void testInky() {
78 int[][] labyrinth = LabyrinthGenerator.getDebugInky();
79
80 Daedalus d = new Daedalus(labyrinth);
81 Simulation simulation = new DaedalusSimulation(d);
82
83 d.addPredator(new Inky(new Vector2D(9, 9)));
84 d.addPredator(new Blinky(new Vector2D(7, 7)));
85 d.addPrey(new PacMan(new Vector2D(5, 5), false));
86
87 Display display = new Display(simulation);
88 display.setDebug(true);
89 display.run();
90 }
91
92 /**
93 * Tests the behavior of Clyde.
94 * <p>
95 * In this case, Clyde should go back and forth.
96 */
97
98 @Test
99 public void testClyde() {
100 int[][] labyrinth = LabyrinthGenerator.getDebugClyde();
101
102 Daedalus d = new Daedalus(labyrinth);
103 Simulation simulation = new DaedalusSimulation(d);
104
105 d.addPredator(new Clyde(new Vector2D(1, 3)));
106 d.addPrey(new PacMan(new Vector2D(8, 3), false));
107
108 Display display = new Display(simulation);
109 display.setDebug(true);
110 display.run();
111 }
112
113 /**
114 * Mock class to create a dummy PacMan in our testing unit.
115 *
116 */
117
118 private class PacMan extends Prey {
119
120 private boolean mMoves;
121
122 /**
123 * Constructs a dummy PacMan that can move back and forth.
124 *
125 * @param position
126 * Starting position of PacMan in the labyrinth
127 * @param moves
128 * Determines if the dummy PacMan will move back and forth
129 */
130
131 public PacMan(Vector2D position, boolean moves) {
132 super(position);
133 mMoves = moves;
134 }
135
136 @Override
137 public Direction move(Direction[] choices, Daedalus daedalus) {
138 if (mMoves) {
139 return getPosition().getX() % 2 == 0 ? Direction.RIGHT : Direction.LEFT;
140 }
141 return Direction.NONE;
142 }
143
144 @Override
145 public Animal copy() {
146 return new PacMan(getPosition(), mMoves);
147 }
148 }
149}