diff options
Diffstat (limited to 'src/ch/epfl/maze/tests/AnimalTest.java')
-rw-r--r-- | src/ch/epfl/maze/tests/AnimalTest.java | 169 |
1 files changed, 82 insertions, 87 deletions
diff --git a/src/ch/epfl/maze/tests/AnimalTest.java b/src/ch/epfl/maze/tests/AnimalTest.java index c4c9220..4a590ae 100644 --- a/src/ch/epfl/maze/tests/AnimalTest.java +++ b/src/ch/epfl/maze/tests/AnimalTest.java | |||
@@ -1,100 +1,95 @@ | |||
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.util.Direction; | 4 | import ch.epfl.maze.util.Direction; |
9 | import ch.epfl.maze.util.Vector2D; | 5 | import ch.epfl.maze.util.Vector2D; |
6 | import junit.framework.TestCase; | ||
7 | import org.junit.Test; | ||
10 | 8 | ||
11 | /** | 9 | /** |
12 | * Test case for {@code Animal} implementation. | 10 | * Test case for {@code Animal} implementation. |
13 | * | ||
14 | */ | 11 | */ |
15 | 12 | ||
16 | public class AnimalTest extends TestCase { | 13 | public class AnimalTest extends TestCase { |
17 | 14 | ||
18 | /** | 15 | /** |
19 | * Test case for {@code getPosition()}. | 16 | * Test case for {@code getPosition()}. |
20 | */ | 17 | */ |
21 | 18 | ||
22 | @Test | 19 | @Test |
23 | public void testGetPosition() { | 20 | public void testGetPosition() { |
24 | Animal animal = new MockAnimal(new Vector2D(2, 1)); | 21 | Animal animal = new MockAnimal(new Vector2D(2, 1)); |
25 | 22 | ||
26 | // checks getPosition() | 23 | // checks getPosition() |
27 | assertEquals(new Vector2D(2, 1), animal.getPosition()); | 24 | assertEquals(new Vector2D(2, 1), animal.getPosition()); |
28 | } | 25 | } |
29 | 26 | ||
30 | /** | 27 | /** |
31 | * Test case for {@code setPosition(Vector2D position)}. | 28 | * Test case for {@code setPosition(Vector2D position)}. |
32 | */ | 29 | */ |
33 | 30 | ||
34 | @Test | 31 | @Test |
35 | public void testSetPosition() { | 32 | public void testSetPosition() { |
36 | Animal animal = new MockAnimal(new Vector2D(2, 1)); | 33 | Animal animal = new MockAnimal(new Vector2D(2, 1)); |
37 | 34 | ||
38 | // checks setPosition(Vector2D position) | 35 | // checks setPosition(Vector2D position) |
39 | animal.setPosition(new Vector2D(3, 5)); | 36 | animal.setPosition(new Vector2D(3, 5)); |
40 | assertEquals(new Vector2D(3, 5), animal.getPosition()); | 37 | assertEquals(new Vector2D(3, 5), animal.getPosition()); |
41 | } | 38 | } |
42 | 39 | ||
43 | /** | 40 | /** |
44 | * Test case for {@code update(Direction dir)}. | 41 | * Test case for {@code update(Direction dir)}. |
45 | */ | 42 | */ |
46 | 43 | ||
47 | @Test | 44 | @Test |
48 | public void testUpdate() { | 45 | public void testUpdate() { |
49 | Animal animal = new MockAnimal(new Vector2D(2, 1)); | 46 | Animal animal = new MockAnimal(new Vector2D(2, 1)); |
50 | 47 | ||
51 | // checks update(Direction dir) with NONE | 48 | // checks update(Direction dir) with NONE |
52 | animal.update(Direction.NONE); | 49 | animal.update(Direction.NONE); |
53 | assertEquals(new Vector2D(2, 1), animal.getPosition()); | 50 | assertEquals(new Vector2D(2, 1), animal.getPosition()); |
54 | 51 | ||
55 | // checks update(Direction dir) with DOWN | 52 | // checks update(Direction dir) with DOWN |
56 | animal.update(Direction.DOWN); | 53 | animal.update(Direction.DOWN); |
57 | assertEquals(new Vector2D(2, 2), animal.getPosition()); | 54 | assertEquals(new Vector2D(2, 2), animal.getPosition()); |
58 | 55 | ||
59 | // checks update(Direction dir) with UP | 56 | // checks update(Direction dir) with UP |
60 | animal.update(Direction.UP); | 57 | animal.update(Direction.UP); |
61 | assertEquals(new Vector2D(2, 1), animal.getPosition()); | 58 | assertEquals(new Vector2D(2, 1), animal.getPosition()); |
62 | 59 | ||
63 | // checks update(Direction dir) with RIGHT | 60 | // checks update(Direction dir) with RIGHT |
64 | animal.update(Direction.RIGHT); | 61 | animal.update(Direction.RIGHT); |
65 | assertEquals(new Vector2D(3, 1), animal.getPosition()); | 62 | assertEquals(new Vector2D(3, 1), animal.getPosition()); |
66 | 63 | ||
67 | // checks update(Direction dir) with LEFT | 64 | // checks update(Direction dir) with LEFT |
68 | animal.update(Direction.LEFT); | 65 | animal.update(Direction.LEFT); |
69 | assertEquals(new Vector2D(2, 1), animal.getPosition()); | 66 | assertEquals(new Vector2D(2, 1), animal.getPosition()); |
70 | } | 67 | } |
71 | 68 | ||
72 | /** | 69 | /** |
73 | * Mock class that makes {@code Animal} concrete. | 70 | * Mock class that makes {@code Animal} concrete. |
74 | * | 71 | */ |
75 | */ | 72 | |
76 | 73 | private class MockAnimal extends Animal { | |
77 | private class MockAnimal extends Animal { | 74 | |
78 | 75 | /** | |
79 | /** | 76 | * Creates a concrete instance of the {@code Animal} class. |
80 | * Creates a concrete instance of the {@code Animal} class. | 77 | * |
81 | * | 78 | * @param labyrinth Actual maze |
82 | * @param labyrinth | 79 | */ |
83 | * Actual maze | 80 | |
84 | */ | 81 | public MockAnimal(Vector2D position) { |
85 | 82 | super(position); | |
86 | public MockAnimal(Vector2D position) { | 83 | } |
87 | super(position); | 84 | |
88 | } | 85 | @Override |
89 | 86 | public Direction move(Direction[] choices) { | |
90 | @Override | 87 | return null; |
91 | public Direction move(Direction[] choices) { | 88 | } |
92 | return null; | 89 | |
93 | } | 90 | @Override |
94 | 91 | public Animal copy() { | |
95 | @Override | 92 | return null; |
96 | public Animal copy() { | 93 | } |
97 | return null; | 94 | } |
98 | } | ||
99 | } | ||
100 | } | 95 | } |