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