From 655ac88f4e73b2df532a451aedf5a561ea1b0d2c Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 21 Nov 2015 10:36:18 +0100 Subject: Import project structure --- src/ch/epfl/maze/tests/AnimalTest.java | 100 +++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/ch/epfl/maze/tests/AnimalTest.java (limited to 'src/ch/epfl/maze/tests/AnimalTest.java') 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 @@ +package ch.epfl.maze.tests; + +import junit.framework.TestCase; + +import org.junit.Test; + +import ch.epfl.maze.physical.Animal; +import ch.epfl.maze.util.Direction; +import ch.epfl.maze.util.Vector2D; + +/** + * 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; + } + } +} -- cgit v1.2.3