Spaces:
Sleeping
Sleeping
File size: 3,117 Bytes
47bba68 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
"""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
@pytest.fixture
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
@pytest.fixture
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
@pytest.fixture
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
@pytest.fixture
def sample_stores():
"""Create sample stores."""
return [
Store(id=1, position=(0, 0)),
Store(id=2, position=(2, 2)),
]
@pytest.fixture
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)),
]
@pytest.fixture
def sample_tunnels():
"""Create sample tunnels."""
return [
Tunnel(entrance1=(0, 0), entrance2=(2, 2)),
Tunnel(entrance1=(0, 2), entrance2=(2, 0)),
]
@pytest.fixture
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,
)
@pytest.fixture
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
|