def test_direction(self): world_center = Point((WORLD_SIZE // 2, WORLD_SIZE // 2)) snake = Snake(start=world_center, start_length=6) self.assertEqual(snake.get_head(), world_center) snake.change_direction(DIRECTION_LEFT) snake.timer = 0 snake.update() # opposite direction changes nothing self.assertEqual(snake.get_head(), world_center+DIRECTION_RIGHT) # no changes in the scales self.assertFalse(snake.update())
def test_crash(self): """ Tests the following crash: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 1 1 0 1 1 1 1 1 0 -> 0 1 1 1 1 0 -> 0 0 1 1 1 0 -> 0 0 0 2 1 0 <--- overlap 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 at 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 """ world_center = Point((WORLD_SIZE // 2, WORLD_SIZE // 2)) snake = Snake(start=world_center, start_length=6) self.assertFalse(snake.self_intersecting()) snake.change_direction(DIRECTION_UP) snake.timer = 0 snake.update() self.assertFalse(snake.self_intersecting()) snake.change_direction(DIRECTION_LEFT) snake.timer = 0 snake.update() self.assertFalse(snake.self_intersecting()) snake.change_direction(DIRECTION_DOWN) snake.timer = 0 snake.update() self.assertTrue(snake.self_intersecting())