summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/tests/MazeTest.java
blob: c0660dbb593ff975a5345cce5b8922aa6a1173fe (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
package ch.epfl.maze.tests;

import ch.epfl.maze.physical.Animal;
import ch.epfl.maze.physical.Maze;
import ch.epfl.maze.physical.zoo.Mouse;
import ch.epfl.maze.util.Vector2D;
import junit.framework.TestCase;
import org.junit.Test;

/**
 * Test case for {@code Maze} implementation.
 */

public class MazeTest extends TestCase {

    private final static int[][] LABYRINTH = {
            {1, 1, 1, 3, 1},
            {1, 0, 0, 0, 1},
            {1, 2, 1, 1, 1}
    };

    /**
     * Test case for several methods in {@code Maze}.
     */

    @Test
    public void testGeneral() {
        Maze maze = new Maze(LABYRINTH);

        // initial maze should be solved
        assertTrue("Initial maze should be solved", maze.isSolved());
        assertTrue("Initial maze should NOT have animals in it",
                maze.getAnimals().size() == 0);

        // adds dummy animal
        Animal dummy = new Mouse(new Vector2D(3, 0));
        maze.addAnimal(dummy);

        assertTrue("Maze Animals should contain one Animal",
                maze.getAnimals().size() == 1);

        // retrieves dummy anima from Maze
        Animal retrieved = maze.getAnimals().get(0);

        assertTrue("Maze should contain the Mouse, even at the exit",
                maze.hasAnimal(dummy));
        assertTrue("Mouse inside the Maze should be the same as Mouse added",
                retrieved == dummy);
        assertFalse("Maze with one Mouse even at the exit should NOT be solved",
                maze.isSolved());

        // removes dummy animal
        maze.removeAnimal(dummy);

        assertFalse("Maze should NOT contain the Mouse anymore",
                maze.hasAnimal(dummy));
        assertTrue("Maze should NOT have anymore Animal in it",
                maze.getAnimals().size() == 0);
        assertTrue("Maze without any animal should be solved", maze.isSolved());
    }

    /**
     * Test case for {@code reset()}.
     */

    @Test
    public void testReset() {
        Maze maze = new Maze(LABYRINTH);

        // adds dummy animal
        Animal dummy = new Mouse(new Vector2D(2, 2));
        maze.addAnimal(dummy);

        // removes dummy animal
        maze.removeAnimal(dummy);

        // checks reset method
        maze.reset();

        assertFalse("Maze should NOT be solved anymore", maze.isSolved());
        assertTrue("Maze should contain the Mouse again", maze.getAnimals().size() == 1);

        // checks that animal in maze is not null
        Animal retrieved = maze.getAnimals().get(0);

        assertTrue("Animal in Maze should be a Mouse", retrieved != null);
    }
}