Compare commits

...

3 Commits

Author SHA1 Message Date
Sam
4775b59936 Add pytest dependency for improved testing capabilities
Some checks failed
Build Simulation and Test / Run All Tests (push) Failing after 8m31s
2025-05-31 19:26:02 -05:00
Sam
a8103af866 Add GitHub Actions workflow for automated testing and setup 2025-05-31 19:25:46 -05:00
Sam
34f790ca18 Optimize grid line drawing by precomputing line coordinates for improved performance 2025-05-31 19:25:36 -05:00
4 changed files with 60 additions and 15 deletions

View File

@ -0,0 +1,30 @@
name: Build Simulation and Test
on:
push:
branches:
- master
jobs:
tests:
name: Run All Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version-file: "pyproject.toml"
- name: Install the project
run: uv sync --locked --all-extras --dev
- name: Run tests
run: uv run pytest tests.py --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html

24
main.py
View File

@ -141,22 +141,36 @@ def draw_grid(screen, camera, showing_grid=True):
# Draw vertical grid lines (only if zoom is high enough to see them clearly)
if effective_cell_size > 4:
for i in range(GRID_WIDTH + 1):
# Precompute grid boundaries
vertical_lines = []
horizontal_lines = []
for i in range(max(GRID_WIDTH, GRID_HEIGHT) + 1):
# Vertical lines
if i <= GRID_WIDTH:
line_x = grid_left + i * effective_cell_size
if 0 <= line_x <= SCREEN_WIDTH:
start_y = max(0, grid_top)
end_y = min(SCREEN_HEIGHT, grid_bottom)
if start_y < end_y:
pygame.draw.line(screen, GRAY, (line_x, start_y), (line_x, end_y))
vertical_lines.append(((line_x, start_y), (line_x, end_y)))
# Draw horizontal grid lines
for i in range(GRID_HEIGHT + 1):
# Horizontal lines
if i <= GRID_HEIGHT:
line_y = grid_top + i * effective_cell_size
if 0 <= line_y <= SCREEN_HEIGHT:
start_x = max(0, grid_left)
end_x = min(SCREEN_WIDTH, grid_right)
if start_x < end_x:
pygame.draw.line(screen, GRAY, (start_x, line_y), (end_x, line_y))
horizontal_lines.append(((start_x, line_y), (end_x, line_y)))
# Draw all vertical lines in one batch
for start, end in vertical_lines:
pygame.draw.line(screen, GRAY, start, end)
# Draw all horizontal lines in one batch
for start, end in horizontal_lines:
pygame.draw.line(screen, GRAY, start, end)
def main():

View File

@ -5,4 +5,5 @@ description = "Add your description here"
requires-python = ">=3.11"
dependencies = [
"pygame>=2.6.1",
"pytest>=8.3.5",
]

0
tests.py Normal file
View File