diff options
author | Pacien TRAN-GIRARD | 2015-11-21 10:44:42 +0100 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2015-11-21 10:44:42 +0100 |
commit | 90bd766f361083f6fd9e39ff080c83fcc606832f (patch) | |
tree | df81a931c9565a4b227068680087f58fdace1859 /src/ch/epfl/maze/tests/DaedalusTest.java | |
parent | 655ac88f4e73b2df532a451aedf5a561ea1b0d2c (diff) | |
download | maze-solver-90bd766f361083f6fd9e39ff080c83fcc606832f.tar.gz |
Reformat imported code
Diffstat (limited to 'src/ch/epfl/maze/tests/DaedalusTest.java')
-rw-r--r-- | src/ch/epfl/maze/tests/DaedalusTest.java | 209 |
1 files changed, 103 insertions, 106 deletions
diff --git a/src/ch/epfl/maze/tests/DaedalusTest.java b/src/ch/epfl/maze/tests/DaedalusTest.java index 34e302f..070b70d 100644 --- a/src/ch/epfl/maze/tests/DaedalusTest.java +++ b/src/ch/epfl/maze/tests/DaedalusTest.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.physical.Animal; | 3 | import ch.epfl.maze.physical.Animal; |
8 | import ch.epfl.maze.physical.Daedalus; | 4 | import ch.epfl.maze.physical.Daedalus; |
9 | import ch.epfl.maze.physical.Predator; | 5 | import ch.epfl.maze.physical.Predator; |
@@ -11,113 +7,114 @@ import ch.epfl.maze.physical.Prey; | |||
11 | import ch.epfl.maze.physical.pacman.Blinky; | 7 | import ch.epfl.maze.physical.pacman.Blinky; |
12 | import ch.epfl.maze.physical.pacman.PacMan; | 8 | import ch.epfl.maze.physical.pacman.PacMan; |
13 | import ch.epfl.maze.util.Vector2D; | 9 | import ch.epfl.maze.util.Vector2D; |
10 | import junit.framework.TestCase; | ||
11 | import org.junit.Test; | ||
14 | 12 | ||
15 | /** | 13 | /** |
16 | * Test case for {@code Daedalus} implementation. | 14 | * Test case for {@code Daedalus} implementation. |
17 | * | ||
18 | */ | 15 | */ |
19 | 16 | ||
20 | public class DaedalusTest extends TestCase { | 17 | public class DaedalusTest extends TestCase { |
21 | 18 | ||
22 | private final static int[][] LABYRINTH = { | 19 | private final static int[][] LABYRINTH = { |
23 | { 1, 1, 1, 1, 1 }, | 20 | {1, 1, 1, 1, 1}, |
24 | { 1, 0, 0, 0, 1 }, | 21 | {1, 0, 0, 0, 1}, |
25 | { 1, 1, 1, 1, 1 } | 22 | {1, 1, 1, 1, 1} |
26 | }; | 23 | }; |
27 | 24 | ||
28 | /** | 25 | /** |
29 | * Test case for several methods in {@code Daedalus}. | 26 | * Test case for several methods in {@code Daedalus}. |
30 | */ | 27 | */ |
31 | 28 | ||
32 | @Test | 29 | @Test |
33 | public void testGeneral() { | 30 | public void testGeneral() { |
34 | Daedalus daedalus = new Daedalus(LABYRINTH); | 31 | Daedalus daedalus = new Daedalus(LABYRINTH); |
35 | 32 | ||
36 | // initial maze should be solved | 33 | // initial maze should be solved |
37 | assertTrue("Initial maze should be solved", daedalus.isSolved()); | 34 | assertTrue("Initial maze should be solved", daedalus.isSolved()); |
38 | assertTrue("Initial maze should NOT have animals in it", | 35 | assertTrue("Initial maze should NOT have animals in it", |
39 | daedalus.getAnimals().size() == 0); | 36 | daedalus.getAnimals().size() == 0); |
40 | 37 | ||
41 | // adds dummy predator and prey | 38 | // adds dummy predator and prey |
42 | Predator dummyPred = new Blinky(new Vector2D(3, 1)); | 39 | Predator dummyPred = new Blinky(new Vector2D(3, 1)); |
43 | Prey dummyPrey = new PacMan(new Vector2D(3, 1)); | 40 | Prey dummyPrey = new PacMan(new Vector2D(3, 1)); |
44 | daedalus.addPredator(dummyPred); | 41 | daedalus.addPredator(dummyPred); |
45 | daedalus.addPrey(dummyPrey); | 42 | daedalus.addPrey(dummyPrey); |
46 | 43 | ||
47 | assertTrue("Daedalus Predators should contain one Predator", | 44 | assertTrue("Daedalus Predators should contain one Predator", |
48 | daedalus.getPredators().size() == 1); | 45 | daedalus.getPredators().size() == 1); |
49 | assertTrue("Daedalus Preys should contain one Prey", | 46 | assertTrue("Daedalus Preys should contain one Prey", |
50 | daedalus.getPreys().size() == 1); | 47 | daedalus.getPreys().size() == 1); |
51 | assertTrue("Daedalus Animals should contain one Predator and one Prey", | 48 | assertTrue("Daedalus Animals should contain one Predator and one Prey", |
52 | daedalus.getAnimals().size() == 2); | 49 | daedalus.getAnimals().size() == 2); |
53 | 50 | ||
54 | // retrieves dummy predator and prey from Daedalus | 51 | // retrieves dummy predator and prey from Daedalus |
55 | Predator retrievedPred = daedalus.getPredators().get(0); | 52 | Predator retrievedPred = daedalus.getPredators().get(0); |
56 | Prey retrievedPrey = daedalus.getPreys().get(0); | 53 | Prey retrievedPrey = daedalus.getPreys().get(0); |
57 | 54 | ||
58 | assertTrue("Daedalus should contain the added Blinky", | 55 | assertTrue("Daedalus should contain the added Blinky", |
59 | daedalus.hasPredator(dummyPred)); | 56 | daedalus.hasPredator(dummyPred)); |
60 | assertTrue("Daedalus should contain the added PacMan", | 57 | assertTrue("Daedalus should contain the added PacMan", |
61 | daedalus.hasPrey(dummyPrey)); | 58 | daedalus.hasPrey(dummyPrey)); |
62 | assertTrue("Predator inside the Daedalus should be the same as Predator added", | 59 | assertTrue("Predator inside the Daedalus should be the same as Predator added", |
63 | retrievedPred == dummyPred); | 60 | retrievedPred == dummyPred); |
64 | assertTrue("Prey inside the Daedalus should be the same as Prey added", | 61 | assertTrue("Prey inside the Daedalus should be the same as Prey added", |
65 | retrievedPrey == dummyPrey); | 62 | retrievedPrey == dummyPrey); |
66 | assertFalse("Daedalus with one Prey should NOT be solved", | 63 | assertFalse("Daedalus with one Prey should NOT be solved", |
67 | daedalus.isSolved()); | 64 | daedalus.isSolved()); |
68 | 65 | ||
69 | // removes dummy predator | 66 | // removes dummy predator |
70 | daedalus.removePredator(dummyPred); | 67 | daedalus.removePredator(dummyPred); |
71 | daedalus.removePrey(dummyPrey); | 68 | daedalus.removePrey(dummyPrey); |
72 | 69 | ||
73 | assertFalse("Daedalus should NOT contain Blinky anymore", | 70 | assertFalse("Daedalus should NOT contain Blinky anymore", |
74 | daedalus.hasPredator(dummyPred)); | 71 | daedalus.hasPredator(dummyPred)); |
75 | assertFalse("Daedalus should NOT contain PacMan anymore", | 72 | assertFalse("Daedalus should NOT contain PacMan anymore", |
76 | daedalus.hasPrey(dummyPrey)); | 73 | daedalus.hasPrey(dummyPrey)); |
77 | assertTrue("Daedalus should NOT have anymore Predator in it", | 74 | assertTrue("Daedalus should NOT have anymore Predator in it", |
78 | daedalus.getPredators().size() == 0); | 75 | daedalus.getPredators().size() == 0); |
79 | assertTrue("Daedalus should NOT have anymore Prey in it", | 76 | assertTrue("Daedalus should NOT have anymore Prey in it", |
80 | daedalus.getPreys().size() == 0); | 77 | daedalus.getPreys().size() == 0); |
81 | assertTrue("Daedalus should NOT have anymore Animal in it", | 78 | assertTrue("Daedalus should NOT have anymore Animal in it", |
82 | daedalus.getAnimals().size() == 0); | 79 | daedalus.getAnimals().size() == 0); |
83 | assertTrue("Daedalus without any animal should be solved", daedalus.isSolved()); | 80 | assertTrue("Daedalus without any animal should be solved", daedalus.isSolved()); |
84 | } | 81 | } |
85 | 82 | ||
86 | /** | 83 | /** |
87 | * Test case for {@code reset()}. | 84 | * Test case for {@code reset()}. |
88 | */ | 85 | */ |
89 | 86 | ||
90 | @Test | 87 | @Test |
91 | public void testReset() { | 88 | public void testReset() { |
92 | Daedalus daedalus = new Daedalus(LABYRINTH); | 89 | Daedalus daedalus = new Daedalus(LABYRINTH); |
93 | 90 | ||
94 | // adds dummy predator and prey | 91 | // adds dummy predator and prey |
95 | Predator dummyPred = new Blinky(new Vector2D(3, 1)); | 92 | Predator dummyPred = new Blinky(new Vector2D(3, 1)); |
96 | Prey dummyPrey = new PacMan(new Vector2D(3, 1)); | 93 | Prey dummyPrey = new PacMan(new Vector2D(3, 1)); |
97 | daedalus.addPredator(dummyPred); | 94 | daedalus.addPredator(dummyPred); |
98 | daedalus.addPrey(dummyPrey); | 95 | daedalus.addPrey(dummyPrey); |
99 | 96 | ||
100 | // removes dummy animal | 97 | // removes dummy animal |
101 | daedalus.removePredator(dummyPred); | 98 | daedalus.removePredator(dummyPred); |
102 | daedalus.removePrey(dummyPrey); | 99 | daedalus.removePrey(dummyPrey); |
103 | 100 | ||
104 | // checks reset method | 101 | // checks reset method |
105 | daedalus.reset(); | 102 | daedalus.reset(); |
106 | 103 | ||
107 | assertFalse("Daedalus should NOT be solved anymore", | 104 | assertFalse("Daedalus should NOT be solved anymore", |
108 | daedalus.isSolved()); | 105 | daedalus.isSolved()); |
109 | assertTrue("Daedalus should contain Blinky again", | 106 | assertTrue("Daedalus should contain Blinky again", |
110 | daedalus.getPredators().size() == 1); | 107 | daedalus.getPredators().size() == 1); |
111 | assertTrue("Daedalus should contain PacMan again", | 108 | assertTrue("Daedalus should contain PacMan again", |
112 | daedalus.getPreys().size() == 1); | 109 | daedalus.getPreys().size() == 1); |
113 | assertTrue("Daedalus should contain Blinky and PacMan again", | 110 | assertTrue("Daedalus should contain Blinky and PacMan again", |
114 | daedalus.getAnimals().size() == 2); | 111 | daedalus.getAnimals().size() == 2); |
115 | 112 | ||
116 | // checks that predator in maze is not null | 113 | // checks that predator in maze is not null |
117 | Animal retrievedPred = daedalus.getAnimals().get(0); | 114 | Animal retrievedPred = daedalus.getAnimals().get(0); |
118 | Animal retrievedPrey = daedalus.getAnimals().get(1); | 115 | Animal retrievedPrey = daedalus.getAnimals().get(1); |
119 | 116 | ||
120 | assertTrue("Animals in Daedalus should be not null", retrievedPred != null); | 117 | assertTrue("Animals in Daedalus should be not null", retrievedPred != null); |
121 | assertTrue("Animals in Daedalus should be not null", retrievedPrey != null); | 118 | assertTrue("Animals in Daedalus should be not null", retrievedPrey != null); |
122 | } | 119 | } |
123 | } | 120 | } |