Spaces:
Sleeping
Sleeping
| """Pytest configuration and fixtures for backend tests.""" | |
| import pytest | |
| from app.models.grid import Grid, Segment | |
| from app.models.entities import Store, Destination, Tunnel | |
| from app.models.state import SearchState | |
| def simple_grid(): | |
| """Create a simple 3x3 grid with all segments having traffic level 1.""" | |
| grid = Grid(width=3, height=3) | |
| # Horizontal segments | |
| for x in range(2): | |
| for y in range(3): | |
| grid.add_segment((x, y), (x + 1, y), 1) | |
| # Vertical segments | |
| for x in range(3): | |
| for y in range(2): | |
| grid.add_segment((x, y), (x, y + 1), 1) | |
| return grid | |
| def grid_with_blocked(): | |
| """Create a 3x3 grid with some blocked segments.""" | |
| grid = Grid(width=3, height=3) | |
| # Add all segments with traffic level 1 | |
| for x in range(2): | |
| for y in range(3): | |
| grid.add_segment((x, y), (x + 1, y), 1) | |
| for x in range(3): | |
| for y in range(2): | |
| grid.add_segment((x, y), (x, y + 1), 1) | |
| # Block segment from (1,1) to (2,1) | |
| grid.add_segment((1, 1), (2, 1), 0) | |
| return grid | |
| def grid_with_varied_traffic(): | |
| """Create a 3x3 grid with varied traffic levels.""" | |
| grid = Grid(width=3, height=3) | |
| # Horizontal segments with different traffic | |
| grid.add_segment((0, 0), (1, 0), 1) | |
| grid.add_segment((1, 0), (2, 0), 2) | |
| grid.add_segment((0, 1), (1, 1), 3) | |
| grid.add_segment((1, 1), (2, 1), 4) | |
| grid.add_segment((0, 2), (1, 2), 1) | |
| grid.add_segment((1, 2), (2, 2), 1) | |
| # Vertical segments | |
| grid.add_segment((0, 0), (0, 1), 2) | |
| grid.add_segment((0, 1), (0, 2), 1) | |
| grid.add_segment((1, 0), (1, 1), 1) | |
| grid.add_segment((1, 1), (1, 2), 2) | |
| grid.add_segment((2, 0), (2, 1), 1) | |
| grid.add_segment((2, 1), (2, 2), 1) | |
| return grid | |
| def sample_stores(): | |
| """Create sample stores.""" | |
| return [ | |
| Store(id=1, position=(0, 0)), | |
| Store(id=2, position=(2, 2)), | |
| ] | |
| def sample_destinations(): | |
| """Create sample destinations.""" | |
| return [ | |
| Destination(id=1, position=(2, 0)), | |
| Destination(id=2, position=(0, 2)), | |
| Destination(id=3, position=(1, 1)), | |
| ] | |
| def sample_tunnels(): | |
| """Create sample tunnels.""" | |
| return [ | |
| Tunnel(entrance1=(0, 0), entrance2=(2, 2)), | |
| Tunnel(entrance1=(0, 2), entrance2=(2, 0)), | |
| ] | |
| def sample_search_state(simple_grid, sample_stores, sample_destinations, sample_tunnels): | |
| """Create a complete search state.""" | |
| return SearchState( | |
| grid=simple_grid, | |
| stores=sample_stores, | |
| destinations=sample_destinations, | |
| tunnels=sample_tunnels, | |
| ) | |
| def larger_grid(): | |
| """Create a 5x5 grid for more complex tests.""" | |
| grid = Grid(width=5, height=5) | |
| # Add all segments with traffic level 1 | |
| for x in range(4): | |
| for y in range(5): | |
| grid.add_segment((x, y), (x + 1, y), 1) | |
| for x in range(5): | |
| for y in range(4): | |
| grid.add_segment((x, y), (x, y + 1), 1) | |
| return grid | |