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