-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_dispatch_engine.py
More file actions
36 lines (29 loc) · 1.05 KB
/
Copy pathtest_dispatch_engine.py
File metadata and controls
36 lines (29 loc) · 1.05 KB
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
from datetime import datetime, timezone
from matching_engine import MatchingEngine
from models import DriverLocationEvent, TripRequestEvent
def test_dispatch_engine_selects_closest_driver():
engine = MatchingEngine()
timestamp = datetime.now(timezone.utc)
drivers = [
DriverLocationEvent(
driver_id="A", lat=40.0, lon=-74.0, timestamp=timestamp, status="available"
),
DriverLocationEvent(
driver_id="B", lat=40.1, lon=-74.0, timestamp=timestamp, status="available"
),
DriverLocationEvent(
driver_id="C", lat=41.0, lon=-74.0, timestamp=timestamp, status="available"
),
]
rider = TripRequestEvent(
rider_id="rider-1",
pickup_lat=40.05,
pickup_lon=-74.0,
dropoff_lat=40.8,
dropoff_lon=-73.9,
timestamp=timestamp,
)
selected = engine.select_best_match(drivers, rider, surge_multiplier=1.0)
assert selected is not None
assert selected.driver_id in {"A", "B"}
# Both A and B are close; acceptable tie