summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/tests/AnimalTest.java
blob: 4a590ae912dd8eea69a763669fa214645c299628 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package ch.epfl.maze.tests;

import ch.epfl.maze.physical.Animal;
import ch.epfl.maze.util.Direction;
import ch.epfl.maze.util.Vector2D;
import junit.framework.TestCase;
import org.junit.Test;

/**
 * Test case for {@code Animal} implementation.
 */

public class AnimalTest extends TestCase {

    /**
     * Test case for {@code getPosition()}.
     */

    @Test
    public void testGetPosition() {
        Animal animal = new MockAnimal(new Vector2D(2, 1));

        // checks getPosition()
        assertEquals(new Vector2D(2, 1), animal.getPosition());
    }

    /**
     * Test case for {@code setPosition(Vector2D position)}.
     */

    @Test
    public void testSetPosition() {
        Animal animal = new MockAnimal(new Vector2D(2, 1));

        // checks setPosition(Vector2D position)
        animal.setPosition(new Vector2D(3, 5));
        assertEquals(new Vector2D(3, 5), animal.getPosition());
    }

    /**
     * Test case for {@code update(Direction dir)}.
     */

    @Test
    public void testUpdate() {
        Animal animal = new MockAnimal(new Vector2D(2, 1));

        // checks update(Direction dir) with NONE
        animal.update(Direction.NONE);
        assertEquals(new Vector2D(2, 1), animal.getPosition());

        // checks update(Direction dir) with DOWN
        animal.update(Direction.DOWN);
        assertEquals(new Vector2D(2, 2), animal.getPosition());

        // checks update(Direction dir) with UP
        animal.update(Direction.UP);
        assertEquals(new Vector2D(2, 1), animal.getPosition());

        // checks update(Direction dir) with RIGHT
        animal.update(Direction.RIGHT);
        assertEquals(new Vector2D(3, 1), animal.getPosition());

        // checks update(Direction dir) with LEFT
        animal.update(Direction.LEFT);
        assertEquals(new Vector2D(2, 1), animal.getPosition());
    }

    /**
     * Mock class that makes {@code Animal} concrete.
     */

    private class MockAnimal extends Animal {

        /**
         * Creates a concrete instance of the {@code Animal} class.
         *
         * @param labyrinth Actual maze
         */

        public MockAnimal(Vector2D position) {
            super(position);
        }

        @Override
        public Direction move(Direction[] choices) {
            return null;
        }

        @Override
        public Animal copy() {
            return null;
        }
    }
}