diff --git a/src/test_/java/SnakeTest.java b/src/test_/java/SnakeTest.java new file mode 100644 index 0000000..6c79afc --- /dev/null +++ b/src/test_/java/SnakeTest.java @@ -0,0 +1,71 @@ +import Snake.Snake; +import org.junit.jupiter.api.Test; + +import java.awt.*; +import java.util.ArrayList; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; + +class SnakeTest { + @Test + public void testReset() { + int gridSize = 20; + Snake snake = new Snake(gridSize); + snake.reset(); + + ArrayList bodySegments = snake.getBodySegments(); + Snake.SnakeDirection direction = Snake.SnakeDirection.UP; + + assertEquals(3, bodySegments.size()); + assertEquals(new Point(gridSize / 2, gridSize / 2), bodySegments.get(0)); + assertEquals(new Point(gridSize / 2, gridSize / 2 + 1), bodySegments.get(1)); + assertEquals(new Point(gridSize / 2, gridSize / 2 + 2), bodySegments.get(2)); + assertEquals(Snake.SnakeDirection.UP, direction); + + } + + @Test + public void testUpdate() { + int gridSize = 20; + Snake snake = new Snake(gridSize); + snake.reset(); + + snake.setDirection(Snake.SnakeDirection.UP); + snake.update(); + ArrayList bodySegments = snake.getBodySegments(); + assertEquals(new Point(gridSize / 2, gridSize / 2 - 1), bodySegments.get(0)); + assertEquals(new Point(gridSize / 2, gridSize / 2), bodySegments.get(1)); + + snake.setDirection(Snake.SnakeDirection.RIGHT); + snake.update(); + bodySegments = snake.getBodySegments(); + assertEquals(new Point(gridSize / 2 + 1, gridSize / 2 - 1), bodySegments.get(0)); + assertEquals(new Point(gridSize / 2, gridSize / 2 - 1), bodySegments.get(1)); + + snake.setDirection(Snake.SnakeDirection.DOWN); + snake.update(); + bodySegments = snake.getBodySegments(); + assertEquals(new Point(gridSize / 2 + 1, gridSize / 2), bodySegments.get(0)); + assertEquals(new Point(gridSize / 2 + 1, gridSize / 2 - 1), bodySegments.get(1)); + + snake.setDirection(Snake.SnakeDirection.LEFT); + snake.update(); + bodySegments = snake.getBodySegments(); + assertEquals(new Point(gridSize / 2, gridSize / 2), bodySegments.get(0)); + assertEquals(new Point(gridSize / 2 + 1, gridSize / 2), bodySegments.get(1)); + + snake.setDirection(Snake.SnakeDirection.UP); + snake.update(); + + } + + + @Test + public void testIsSelfColliding() { + int gridSize = 20; + Snake snake = new Snake(gridSize); + + assertFalse(snake.isSelfColliding()); + } +}