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

import ch.epfl.maze.physical.Animal;
import ch.epfl.maze.physical.Daedalus;
import ch.epfl.maze.physical.Predator;
import ch.epfl.maze.physical.Prey;
import ch.epfl.maze.physical.pacman.Blinky;
import ch.epfl.maze.physical.pacman.PacMan;
import ch.epfl.maze.util.Vector2D;
import junit.framework.TestCase;
import org.junit.Test;

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

public class DaedalusTest extends TestCase {

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

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

    @Test
    public void testGeneral() {
        Daedalus daedalus = new Daedalus(LABYRINTH);

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

        // adds dummy predator and prey
        Predator dummyPred = new Blinky(new Vector2D(3, 1));
        Prey dummyPrey = new PacMan(new Vector2D(3, 1));
        daedalus.addPredator(dummyPred);
        daedalus.addPrey(dummyPrey);

        assertTrue("Daedalus Predators should contain one Predator",
                daedalus.getPredators().size() == 1);
        assertTrue("Daedalus Preys should contain one Prey",
                daedalus.getPreys().size() == 1);
        assertTrue("Daedalus Animals should contain one Predator and one Prey",
                daedalus.getAnimals().size() == 2);

        // retrieves dummy predator and prey from Daedalus
        Predator retrievedPred = daedalus.getPredators().get(0);
        Prey retrievedPrey = daedalus.getPreys().get(0);

        assertTrue("Daedalus should contain the added Blinky",
                daedalus.hasPredator(dummyPred));
        assertTrue("Daedalus should contain the added PacMan",
                daedalus.hasPrey(dummyPrey));
        assertTrue("Predator inside the Daedalus should be the same as Predator added",
                retrievedPred == dummyPred);
        assertTrue("Prey inside the Daedalus should be the same as Prey added",
                retrievedPrey == dummyPrey);
        assertFalse("Daedalus with one Prey should NOT be solved",
                daedalus.isSolved());

        // removes dummy predator
        daedalus.removePredator(dummyPred);
        daedalus.removePrey(dummyPrey);

        assertFalse("Daedalus should NOT contain Blinky anymore",
                daedalus.hasPredator(dummyPred));
        assertFalse("Daedalus should NOT contain PacMan anymore",
                daedalus.hasPrey(dummyPrey));
        assertTrue("Daedalus should NOT have anymore Predator in it",
                daedalus.getPredators().size() == 0);
        assertTrue("Daedalus should NOT have anymore Prey in it",
                daedalus.getPreys().size() == 0);
        assertTrue("Daedalus should NOT have anymore Animal in it",
                daedalus.getAnimals().size() == 0);
        assertTrue("Daedalus without any animal should be solved", daedalus.isSolved());
    }

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

    @Test
    public void testReset() {
        Daedalus daedalus = new Daedalus(LABYRINTH);

        // adds dummy predator and prey
        Predator dummyPred = new Blinky(new Vector2D(3, 1));
        Prey dummyPrey = new PacMan(new Vector2D(3, 1));
        daedalus.addPredator(dummyPred);
        daedalus.addPrey(dummyPrey);

        // removes dummy animal
        daedalus.removePredator(dummyPred);
        daedalus.removePrey(dummyPrey);

        // checks reset method
        daedalus.reset();

        assertFalse("Daedalus should NOT be solved anymore",
                daedalus.isSolved());
        assertTrue("Daedalus should contain Blinky again",
                daedalus.getPredators().size() == 1);
        assertTrue("Daedalus should contain PacMan again",
                daedalus.getPreys().size() == 1);
        assertTrue("Daedalus should contain Blinky and PacMan again",
                daedalus.getAnimals().size() == 2);

        // checks that predator in maze is not null
        Animal retrievedPred = daedalus.getAnimals().get(0);
        Animal retrievedPrey = daedalus.getAnimals().get(1);

        assertTrue("Animals in Daedalus should be not null", retrievedPred != null);
        assertTrue("Animals in Daedalus should be not null", retrievedPrey != null);
    }
}