diff options
author | Pacien TRAN-GIRARD | 2015-11-21 10:36:18 +0100 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2015-11-21 10:36:18 +0100 |
commit | 655ac88f4e73b2df532a451aedf5a561ea1b0d2c (patch) | |
tree | ef6f914a465575f313e2b280bf0639d87a4cbd58 /src/ch/epfl/maze/tests/AnimalTest.java | |
parent | 56279eb59ccdea48b18daa027a5095d861b4e2f4 (diff) | |
download | maze-solver-655ac88f4e73b2df532a451aedf5a561ea1b0d2c.tar.gz |
Import project structure
Diffstat (limited to 'src/ch/epfl/maze/tests/AnimalTest.java')
-rw-r--r-- | src/ch/epfl/maze/tests/AnimalTest.java | 100 |
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 @@ | |||
1 | package ch.epfl.maze.tests; | ||
2 | |||
3 | import junit.framework.TestCase; | ||
4 | |||
5 | import org.junit.Test; | ||
6 | |||
7 | import ch.epfl.maze.physical.Animal; | ||
8 | import ch.epfl.maze.util.Direction; | ||
9 | import ch.epfl.maze.util.Vector2D; | ||
10 | |||
11 | /** | ||
12 | * Test case for {@code Animal} implementation. | ||
13 | * | ||
14 | */ | ||
15 | |||
16 | public 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 | } | ||