diff options
Diffstat (limited to 'src/ch/epfl/maze/tests/WorldTest.java')
-rw-r--r-- | src/ch/epfl/maze/tests/WorldTest.java | 625 |
1 files changed, 309 insertions, 316 deletions
diff --git a/src/ch/epfl/maze/tests/WorldTest.java b/src/ch/epfl/maze/tests/WorldTest.java index 6d551b1..dccd1ab 100644 --- a/src/ch/epfl/maze/tests/WorldTest.java +++ b/src/ch/epfl/maze/tests/WorldTest.java | |||
@@ -1,330 +1,323 @@ | |||
1 | package ch.epfl.maze.tests; | 1 | package ch.epfl.maze.tests; |
2 | 2 | ||
3 | import static org.junit.Assert.assertArrayEquals; | ||
4 | |||
5 | import java.util.Arrays; | ||
6 | import java.util.List; | ||
7 | |||
8 | import junit.framework.TestCase; | ||
9 | |||
10 | import org.junit.Test; | ||
11 | |||
12 | import ch.epfl.maze.physical.Animal; | 3 | import ch.epfl.maze.physical.Animal; |
13 | import ch.epfl.maze.physical.World; | 4 | import ch.epfl.maze.physical.World; |
14 | import ch.epfl.maze.util.Direction; | 5 | import ch.epfl.maze.util.Direction; |
15 | import ch.epfl.maze.util.Vector2D; | 6 | import ch.epfl.maze.util.Vector2D; |
7 | import junit.framework.TestCase; | ||
8 | import org.junit.Test; | ||
9 | |||
10 | import java.util.Arrays; | ||
11 | import java.util.List; | ||
12 | |||
13 | import static org.junit.Assert.assertArrayEquals; | ||
16 | 14 | ||
17 | /** | 15 | /** |
18 | * Test case for {@code World} implementation. | 16 | * Test case for {@code World} implementation. |
19 | * | ||
20 | */ | 17 | */ |
21 | 18 | ||
22 | public class WorldTest extends TestCase { | 19 | public class WorldTest extends TestCase { |
23 | 20 | ||
24 | /* sample labyrinth */ | 21 | /* sample labyrinth */ |
25 | private static final int[][] LABYRINTH_SAMPLE = { | 22 | private static final int[][] LABYRINTH_SAMPLE = { |
26 | {1, 1, 1, 1, 1, 3, 1}, | 23 | {1, 1, 1, 1, 1, 3, 1}, |
27 | {1, 0, 0, 0, 0, 0, 1}, | 24 | {1, 0, 0, 0, 0, 0, 1}, |
28 | {1, 2, 1, 1, 1, 1, 1} | 25 | {1, 2, 1, 1, 1, 1, 1} |
29 | }; | 26 | }; |
30 | 27 | ||
31 | /* constants labyrinth for testing getChoices(Vector2D) */ | 28 | /* constants labyrinth for testing getChoices(Vector2D) */ |
32 | private static final int[][] LABYRINTH_STUCK = { | 29 | private static final int[][] LABYRINTH_STUCK = { |
33 | {1, 1, 1}, | 30 | {1, 1, 1}, |
34 | {1, 0, 1}, | 31 | {1, 0, 1}, |
35 | {1, 1, 1} | 32 | {1, 1, 1} |
36 | }; | 33 | }; |
37 | private static final int[][] LABYRINTH_CORRIDOR = { | 34 | private static final int[][] LABYRINTH_CORRIDOR = { |
38 | {1, 1, 1, 1, 1, 1}, | 35 | {1, 1, 1, 1, 1, 1}, |
39 | {1, 0, 1, 0, 0, 1}, | 36 | {1, 0, 1, 0, 0, 1}, |
40 | {1, 0, 1, 1, 1, 1}, | 37 | {1, 0, 1, 1, 1, 1}, |
41 | {1, 1, 1, 1, 1, 1} | 38 | {1, 1, 1, 1, 1, 1} |
42 | }; | 39 | }; |
43 | private static final int[][] LABYRINTH_DOGHNUT = { | 40 | private static final int[][] LABYRINTH_DOGHNUT = { |
44 | {1, 1, 1, 1, 1}, | 41 | {1, 1, 1, 1, 1}, |
45 | {1, 0, 0, 0, 1}, | 42 | {1, 0, 0, 0, 1}, |
46 | {1, 0, 1, 0, 1}, | 43 | {1, 0, 1, 0, 1}, |
47 | {1, 0, 0, 0, 1}, | 44 | {1, 0, 0, 0, 1}, |
48 | {1, 1, 1, 1, 1} | 45 | {1, 1, 1, 1, 1} |
49 | }; | 46 | }; |
50 | private static final int[][] LABYRINTH_SQUARE = { | 47 | private static final int[][] LABYRINTH_SQUARE = { |
51 | {1, 1, 1, 1, 1}, | 48 | {1, 1, 1, 1, 1}, |
52 | {1, 0, 0, 0, 1}, | 49 | {1, 0, 0, 0, 1}, |
53 | {1, 0, 0, 0, 1}, | 50 | {1, 0, 0, 0, 1}, |
54 | {1, 0, 0, 0, 1}, | 51 | {1, 0, 0, 0, 1}, |
55 | {1, 1, 1, 1, 1} | 52 | {1, 1, 1, 1, 1} |
56 | }; | 53 | }; |
57 | 54 | ||
58 | /** | 55 | /** |
59 | * Test case for {@code getTile(int x, int y)}. | 56 | * Test case for {@code getTile(int x, int y)}. |
60 | */ | 57 | */ |
61 | 58 | ||
62 | @Test | 59 | @Test |
63 | public void testGetTile() { | 60 | public void testGetTile() { |
64 | World world = new ConcreteWorld(LABYRINTH_SAMPLE); | 61 | World world = new ConcreteWorld(LABYRINTH_SAMPLE); |
65 | 62 | ||
66 | // checks if positions are reversed | 63 | // checks if positions are reversed |
67 | assertTrue("You reversed the coordinates in your method !", | 64 | assertTrue("You reversed the coordinates in your method !", |
68 | world.getTile(5, 1) != World.NOTHING); | 65 | world.getTile(5, 1) != World.NOTHING); |
69 | 66 | ||
70 | // checks every position on the sample labyrinth | 67 | // checks every position on the sample labyrinth |
71 | assertEquals(World.WALL, world.getTile(0, 0)); | 68 | assertEquals(World.WALL, world.getTile(0, 0)); |
72 | assertEquals(World.FREE, world.getTile(1, 1)); | 69 | assertEquals(World.FREE, world.getTile(1, 1)); |
73 | assertEquals(World.START, world.getTile(1, 2)); | 70 | assertEquals(World.START, world.getTile(1, 2)); |
74 | assertEquals(World.EXIT, world.getTile(5, 0)); | 71 | assertEquals(World.EXIT, world.getTile(5, 0)); |
75 | assertEquals(World.NOTHING, world.getTile(0, 3)); | 72 | assertEquals(World.NOTHING, world.getTile(0, 3)); |
76 | } | 73 | } |
77 | 74 | ||
78 | /** | 75 | /** |
79 | * Test case for {@code isFree(int x, int y)}. | 76 | * Test case for {@code isFree(int x, int y)}. |
80 | */ | 77 | */ |
81 | 78 | ||
82 | @Test | 79 | @Test |
83 | public void testIsFree() { | 80 | public void testIsFree() { |
84 | World world = new ConcreteWorld(LABYRINTH_SAMPLE); | 81 | World world = new ConcreteWorld(LABYRINTH_SAMPLE); |
85 | 82 | ||
86 | // checks FREE, START and EXIT positions | 83 | // checks FREE, START and EXIT positions |
87 | assertTrue("FREE tile should be free", world.isFree(3, 1)); | 84 | assertTrue("FREE tile should be free", world.isFree(3, 1)); |
88 | assertTrue("START tile should be free", world.isFree(1, 2)); | 85 | assertTrue("START tile should be free", world.isFree(1, 2)); |
89 | assertTrue("EXIT tile should be free", world.isFree(5, 0)); | 86 | assertTrue("EXIT tile should be free", world.isFree(5, 0)); |
90 | 87 | ||
91 | // checks WALL and NOTHING positions | 88 | // checks WALL and NOTHING positions |
92 | assertFalse("WALL tile should NOT be free", world.isFree(0, 0)); | 89 | assertFalse("WALL tile should NOT be free", world.isFree(0, 0)); |
93 | assertFalse("NOTHING tile should NOT be free", world.isFree(0, 3)); | 90 | assertFalse("NOTHING tile should NOT be free", world.isFree(0, 3)); |
94 | } | 91 | } |
95 | 92 | ||
96 | /** | 93 | /** |
97 | * Test case for {@code getWidth()}. | 94 | * Test case for {@code getWidth()}. |
98 | */ | 95 | */ |
99 | 96 | ||
100 | @Test | 97 | @Test |
101 | public void testGetWidth() { | 98 | public void testGetWidth() { |
102 | World world = new ConcreteWorld(LABYRINTH_SAMPLE); | 99 | World world = new ConcreteWorld(LABYRINTH_SAMPLE); |
103 | 100 | ||
104 | // checks width | 101 | // checks width |
105 | assertEquals(7, world.getWidth()); | 102 | assertEquals(7, world.getWidth()); |
106 | } | 103 | } |
107 | 104 | ||
108 | /** | 105 | /** |
109 | * Test case for {@code getHeight()}. | 106 | * Test case for {@code getHeight()}. |
110 | */ | 107 | */ |
111 | 108 | ||
112 | @Test | 109 | @Test |
113 | public void testGetHeight() { | 110 | public void testGetHeight() { |
114 | World world = new ConcreteWorld(LABYRINTH_SAMPLE); | 111 | World world = new ConcreteWorld(LABYRINTH_SAMPLE); |
115 | 112 | ||
116 | // checks height | 113 | // checks height |
117 | assertEquals(3, world.getHeight()); | 114 | assertEquals(3, world.getHeight()); |
118 | } | 115 | } |
119 | 116 | ||
120 | /** | 117 | /** |
121 | * Test case for {@code getStart()}. | 118 | * Test case for {@code getStart()}. |
122 | */ | 119 | */ |
123 | 120 | ||
124 | @Test | 121 | @Test |
125 | public void testGetStart() { | 122 | public void testGetStart() { |
126 | World world = new ConcreteWorld(LABYRINTH_SAMPLE); | 123 | World world = new ConcreteWorld(LABYRINTH_SAMPLE); |
127 | 124 | ||
128 | // checks starting position | 125 | // checks starting position |
129 | assertEquals(new Vector2D(1, 2), world.getStart()); | 126 | assertEquals(new Vector2D(1, 2), world.getStart()); |
130 | } | 127 | } |
131 | 128 | ||
132 | /** | 129 | /** |
133 | * Test case for {@code getExit()}. | 130 | * Test case for {@code getExit()}. |
134 | */ | 131 | */ |
135 | 132 | ||
136 | @Test | 133 | @Test |
137 | public void testGetExit() { | 134 | public void testGetExit() { |
138 | World world = new ConcreteWorld(LABYRINTH_SAMPLE); | 135 | World world = new ConcreteWorld(LABYRINTH_SAMPLE); |
139 | 136 | ||
140 | // checks exiting position | 137 | // checks exiting position |
141 | assertEquals(new Vector2D(5, 0), world.getExit()); | 138 | assertEquals(new Vector2D(5, 0), world.getExit()); |
142 | } | 139 | } |
143 | 140 | ||
144 | // ========================================================== | 141 | // ========================================================== |
145 | 142 | ||
146 | /** | 143 | /** |
147 | * Test case for {@code getChoices(Vector2D position)} | 144 | * Test case for {@code getCh |