-
Notifications
You must be signed in to change notification settings - Fork 1
/
passenger.py
56 lines (42 loc) · 1.35 KB
/
passenger.py
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
"""The Passenger class tracks who has entered the plane, at which row they are
currently, and to which row they need to get before sitting down.
Usage:
from airplane import Seat
from passenger import PassengerQueue
seat = Seat(row=10, seat=0, window_middle_aisle='window')
passenger = Passenger(seat=seat)
"""
from airplane import Seat
class Passenger(object):
def __init__(self, seat: Seat) -> None:
"""Passengers board the plane.
Args:
seat (Seat)
"""
self._seat = seat
self.current_row = None
def __lt__(self, other):
"""Passengers are ordered by their seat"""
return self._seat < other._seat
def __gt__(self, other):
"""Passengers are ordered by their seat"""
return self._seat > other._seat
@property
def row(self):
return self._seat.row
@property
def seat(self):
return self._seat.seat
@property
def arrived_at_row(self) -> bool:
return self.current_row == self.row
def board(self) -> None:
"""Sets the row counter to -1 so that the next row is row 0."""
self.current_row = -1
def move(self) -> None:
"""Moves forward 1 row."""
try:
self.current_row += 1
except TypeError:
# The passenger has not yet boarded. Skip.
pass