Skip to content
Snippets Groups Projects
Verified Commit e9e3b85f authored by Marco Aceti's avatar Marco Aceti
Browse files

Add __hash__ methods to Station and Train

parent d73c55db
No related branches found
No related tags found
No related merge requests found
Pipeline #2628 passed
......@@ -181,3 +181,6 @@ class Station:
t.List[Train]: a list of trains departing from the station
"""
return api.ViaggiaTrenoAPI._station_departures_or_arrivals("arrivi", self.code)
def __hash__(self) -> int:
return hash(self.name)
......@@ -105,3 +105,9 @@ def test_by_region(region_code):
# Recheck with the *actually* correct _region_code:
# sometimes the 'elencoStazioni' call can be misleading.
assert station.region_code == Station._region_code(station.code)
def test_hash():
milan: Station = Station.by_code("S01700")
rome: Station = Station.by_code("S08409")
assert hash(milan) != hash(rome)
......@@ -45,3 +45,9 @@ def test_unfetched_repr_2():
}
)
assert repr(train) == "Treno [D] REG 10911 : Milano Centrale [S01700@1] -> ???"
def test_hash():
milan: Station = Station.by_code("S01700")
train: Train = Train(10911, milan)
assert hash(train) is not None
......@@ -152,3 +152,6 @@ class Train:
f"{self.category} {self.number} : {self.origin} -> {self.destination}"
f"\n{chr(10).join([str(stop) for stop in self.stops])}"
)
def __hash__(self) -> int:
return hash(self.number) + hash(self.origin.code)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment