|
@ -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<Point> 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<Point> 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()); |
|
|
|
|
|
} |
|
|
|
|
|
} |