summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/tests/ZooTest.java
blob: c0daa61fe33dec72f6ca7157274aa45c07db5db1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package ch.epfl.maze.tests;

import ch.epfl.maze.graphics.Display;
import ch.epfl.maze.physical.Maze;
import ch.epfl.maze.physical.zoo.*;
import ch.epfl.maze.simulation.MazeSimulation;
import ch.epfl.maze.simulation.Simulation;
import ch.epfl.maze.util.LabyrinthGenerator;
import junit.framework.TestCase;
import org.junit.Test;

/**
 * Test cases for animals implementation.
 *
 * @author EPFL
 * @author Pacien TRAN-GIRARD
 */
public class ZooTest extends TestCase {

    public static final boolean DEBUG = false;

    /**
     * Tests the behaviour of the Mouse A.I.
     * <p>
     * The Mouse should go forward and never retrace its steps.
     */
    @Test
    public void testMouse() {
        int[][] labyrinth = LabyrinthGenerator.getDebugMouse();

        Maze m = new Maze(labyrinth);
        Simulation simulation = new MazeSimulation(m);

        m.addAnimal(new Mouse(m.getStart()));

        Display display = new Display(simulation);
        display.setDebug(ZooTest.DEBUG);
        display.run();
    }

    /**
     * Tests the behaviour of the Hamster A.I.
     * <p>
     * The Hamster should never revisit a dead-end it has already visited.
     */
    @Test
    public void testHamster() {
        int[][] labyrinth = LabyrinthGenerator.getDebugHamster();

        Maze m = new Maze(labyrinth);
        Simulation simulation = new MazeSimulation(m);

        m.addAnimal(new Hamster(m.getStart()));

        Display display = new Display(simulation);
        display.setDebug(ZooTest.DEBUG);
        display.run();
    }

    /**
     * Tests the behaviour of the Monkey A.I.
     * <p>
     * The Monkey should go directly to the exit without taking any dead-end.
     */
    @Test
    public void testMonkey() {
        int[][] labyrinth = LabyrinthGenerator.getDebugMonkey();

        Maze m = new Maze(labyrinth);
        Simulation simulation = new MazeSimulation(m);

        m.addAnimal(new Monkey(m.getStart()));

        Display display = new Display(simulation);
        display.setDebug(ZooTest.DEBUG);
        display.run();
    }

    /**
     * Tests the behaviour of the Bear A.I.
     * <p>
     * The Bear must follow the entire wall in front of him until the exit. If
     * it loops infinitely in this maze, it means that it does not properly
     * count the turns it makes.
     */
    @Test
    public void testBear1() {
        int[][] labyrinth = LabyrinthGenerator.getDebugBear1();

        Maze m = new Maze(labyrinth);
        Simulation simulation = new MazeSimulation(m);

        m.addAnimal(new Bear(m.getStart()));

        Display display = new Display(simulation);
        display.setDebug(ZooTest.DEBUG);
        display.run();
    }

    /**
     * Tests the behaviour of the Bear A.I.
     * <p>
     * If the Bear loops infinitely in this maze, it means that it does not
     * properly count the turns it makes.
     */
    @Test
    public void testBear2() {
        int[][] labyrinth = LabyrinthGenerator.getDebugBear2();

        Maze m = new Maze(labyrinth);
        Simulation simulation = new MazeSimulation(m);

        m.addAnimal(new Bear(m.getStart()));

        Display display = new Display(simulation);
        display.setDebug(ZooTest.DEBUG);
        display.run();
    }

    /**
     * Tests the behaviour of the Panda A.I.
     * <p>
     * When the Panda comes back to the intersection, then it must leave the
     * position marked once and go back into the loop.
     */
    @Test
    public void testPanda1() {
        int[][] labyrinth = LabyrinthGenerator.getDebugPanda1();

        Maze m = new Maze(labyrinth);
        Simulation simulation = new MazeSimulation(m);

        m.addAnimal(new Panda(m.getStart()));

        Display display = new Display(simulation);
        display.setDebug(ZooTest.DEBUG);
        display.run();
    }

    /**
     * Tests the behaviour of the Panda A.I.
     * <p>
     * The Panda must mark the intersection twice only the very last time it
     * walks on it.
     */
    @Test
    public void testPanda2() {
        int[][] labyrinth = LabyrinthGenerator.getDebugPanda2();

        Maze m = new Maze(labyrinth);
        Simulation simulation = new MazeSimulation(m);

        m.addAnimal(new Panda(m.getStart()));

        Display display = new Display(simulation);
        display.setDebug(ZooTest.DEBUG);
        display.run();
    }

    /**
     * Tests the behaviour of the Bear A.I versus the Monkey A.I.
     * <p>
     * The Bear should leave the maze while the Monkey should loop infinitely.
     */
    @Test
    public void testBearVsMonkey() {
        int[][] labyrinth = LabyrinthGenerator.getBearVsMonkey();

        Maze m = new Maze(labyrinth);
        Simulation simulation = new MazeSimulation(m);

        m.addAnimal(new Bear(m.getStart()));
        m.addAnimal(new Monkey(m.getStart()));

        Display display = new Display(simulation);
        display.run();
    }

    /**
     * Tests the behaviour of the Panda A.I versus the Hamster A.I.
     * <p>
     * The Panda should leave the maze earlier than the Hamster with a higher
     * probability than the Hamster.
     */
    @Test
    public void testPandaVsHamster() {
        int[][] labyrinth = LabyrinthGenerator.getPandaVsHamster();

        Maze m = new Maze(labyrinth);
        Simulation simulation = new MazeSimulation(m);

        m.addAnimal(new Panda(m.getStart()));
        m.addAnimal(new Hamster(m.getStart()));

        Display display = new Display(simulation);
        display.run();
    }

}