Beispiel #1
0
    def test_get_spawn(self):
        # Initial case, just test that it will return something acceptable
        # The snake head is irrelevant here.
        food_coords = self.spawn_manager_rect.get_spawn(Snake())
        self.assertTrue(food_coords[0] >= 0)
        self.assertTrue(food_coords[0] < 4)
        self.assertTrue(food_coords[1] >= 0)
        self.assertTrue(food_coords[1] < 6)

        # Construct a snake that loops around itself.
        snake = Snake()
        snake.head = (3, 7)
        snake.joints = [(6, 7), (6, 3), (5, 3), (5, 2), (7, 2), (7, 8), (3, 8)]
        snake_squares = snake.enumerate_snake_squares()

        # Repeat 100 times so that the test may include all branches
        for _ in range(100):
            food_coords = self.spawn_manager_playtest.get_spawn(snake)
            self.assertTrue(food_coords not in snake_squares)

        movements = (QuadraticGrid.Movements.UP, QuadraticGrid.Movements.DOWN,
          QuadraticGrid.Movements.LEFT, QuadraticGrid.Movements.RIGHT)

        for _ in range(100):
            self.spawn_manager_playtest.note_movement(random.choice(movements))

        for _ in range(100):
            food_coords = self.spawn_manager_playtest.get_spawn(snake)
            self.assertTrue(food_coords not in snake_squares)
Beispiel #2
0
    def test_get_spawn(self):
        snake = Snake()
        snake.head = (3, 7)
        snake.joints = [(6, 7), (6, 3), (5, 3), (5, 2), (7, 2), (7, 8), (3, 8)]
        snake_squares = snake.enumerate_snake_squares()

        for _ in range(100):
            food_coords = self.spawn_manager.get_spawn(snake)
            self.assertTrue(food_coords not in snake_squares)
    def test_enumerate_snake_squares(self):
        snake = Snake()
        snake.head = (6, 7)
        snake.joints = [(6, 4), (3, 4), (3, 3), (8, 3), (8, 0), (0, 0)]
        expected_squares = set()
        expected_squares.add((6, 7))

        for r in range(8):
            expected_squares.add((r, 0))

        for c in range(3):
            expected_squares.add((8, c))

        for r in range(3, 9):
            expected_squares.add((r, 3))

        for r in range(3, 7):
            expected_squares.add((r, 4))

        for c in range(4, 7):
            expected_squares.add((6, c))

        self.assertEquals(expected_squares, snake.enumerate_snake_squares())