Fix food spawn test and optimize test performance
This commit is contained in:
parent
fcab6ec766
commit
afd17d257e
@ -3,7 +3,7 @@ testpaths = tests
|
|||||||
python_files = test_*.py
|
python_files = test_*.py
|
||||||
python_classes = Test*
|
python_classes = Test*
|
||||||
python_functions = test_*
|
python_functions = test_*
|
||||||
addopts = -v --tb=short -n auto
|
addopts = -v --tb=short -n 4 # Limit to 4 parallel workers
|
||||||
markers =
|
markers =
|
||||||
slow: marks tests as slow (deselect with '-m "not slow"')
|
slow: marks tests as slow (deselect with '-m "not slow"')
|
||||||
integration: marks tests as integration tests
|
integration: marks tests as integration tests
|
||||||
|
@ -8,6 +8,9 @@ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')
|
|||||||
|
|
||||||
def pytest_configure(config):
|
def pytest_configure(config):
|
||||||
"""Initialize pygame once before any tests run"""
|
"""Initialize pygame once before any tests run"""
|
||||||
|
# Set SDL to use software rendering and disable audio to reduce resource usage
|
||||||
|
os.environ['SDL_VIDEODRIVER'] = 'dummy'
|
||||||
|
os.environ['SDL_AUDIODRIVER'] = 'dummy'
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
def pytest_unconfigure(config):
|
def pytest_unconfigure(config):
|
||||||
@ -18,8 +21,8 @@ def pytest_unconfigure(config):
|
|||||||
def game_config():
|
def game_config():
|
||||||
"""Basic game configuration"""
|
"""Basic game configuration"""
|
||||||
return {
|
return {
|
||||||
'width': 800,
|
'width': 400, # Smaller dimensions for testing
|
||||||
'height': 600,
|
'height': 300,
|
||||||
'block_size': 20,
|
'block_size': 20,
|
||||||
'fps': 60
|
'fps': 60
|
||||||
}
|
}
|
||||||
|
@ -44,15 +44,17 @@ def test_food_spawn_full_grid():
|
|||||||
food = Food(20)
|
food = Food(20)
|
||||||
width, height = 60, 60 # Small grid
|
width, height = 60, 60 # Small grid
|
||||||
|
|
||||||
# Create a snake that occupies most of the grid
|
# Create a snake that occupies all positions except (40, 40)
|
||||||
snake_body = [(x, y) for x in range(0, 60, 20) for y in range(0, 40, 20)]
|
all_positions = [(x, y) for x in range(0, 60, 20) for y in range(0, 60, 20)]
|
||||||
|
|
||||||
# Leave one spot free at (40, 40)
|
|
||||||
free_spot = (40, 40)
|
free_spot = (40, 40)
|
||||||
|
snake_body = [pos for pos in all_positions if pos != free_spot]
|
||||||
|
|
||||||
|
# Verify our test setup is correct
|
||||||
|
assert len(snake_body) == len(all_positions) - 1
|
||||||
assert free_spot not in snake_body
|
assert free_spot not in snake_body
|
||||||
|
|
||||||
# Spawn food
|
# Spawn food
|
||||||
food.spawn(width, height, snake_body)
|
food.spawn(width, height, snake_body)
|
||||||
|
|
||||||
# Food should spawn in the only free spot
|
# Food must spawn in the only free spot
|
||||||
assert food.position == free_spot
|
assert food.position == free_spot
|
Loading…
Reference in New Issue
Block a user