Skip to content

Commit

Permalink
address PR comments:
Browse files Browse the repository at this point in the history
- add a step to example in docstring
- refine assertions in tests
  • Loading branch information
KasiaKoz committed Nov 13, 2024
1 parent f239f12 commit 2a6ba91
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/genet/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,11 @@ def split_links_on_mode(self, mode: str, link_id_prefix: Optional[str] = None) -
[out] {"id": "LINK_ID", "modes": {"car", "bike"}, "freespeed": 5, ...}
```
```python
[2] network.split_links_on_mode("bike")
[out] {"bike---LINK_ID"}
```
The new bike link will assume all the same attributes apart from the "modes":
```python
[3] network.link("bike---LINK_ID")`
Expand Down
16 changes: 9 additions & 7 deletions tests/test_core_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2445,11 +2445,10 @@ def test_splitting_links_uses_desired_prefix_for_new_link_ids():

new_links = n.split_links_on_mode("bike", link_id_prefix="HEYO-")

assert len(new_links) > 0, "No new links were generated"
for link_id in new_links:
assert link_id.startswith(
"HEYO-"
), "The ID of a new link did not start with the desired prefix"
assert len(new_links) == 1, "No new links were generated"
assert list(new_links)[0].startswith(
"HEYO-"
), "The ID of a new link did not start with the desired prefix"


def test_splitting_links_generates_unique_ids_for_new_links():
Expand All @@ -2459,12 +2458,15 @@ def test_splitting_links_generates_unique_ids_for_new_links():

new_links = n.split_links_on_mode("bike", link_id_prefix="HEYO-")

new_links = set(new_links) # To force uniqueness
assert isinstance(new_links, set) # To force uniqueness
assert len(new_links) == 10, "The number of link IDs is incorrect"
for link_id in new_links:
assert (
n.link(link_id)["id"] == link_id
), "The ID declared in attributes does not match the ID in the Network object"
assert link_id.startswith(
"HEYO-"
), "The ID of a new link did not start with the desired prefix"


def test_splitting_links_generates_unique_ids_for_new_links_if_given_empty_prefix():
Expand All @@ -2475,7 +2477,7 @@ def test_splitting_links_generates_unique_ids_for_new_links_if_given_empty_prefi

new_links = n.split_links_on_mode("bike", link_id_prefix="")

new_links = set(new_links) # To force uniqueness
assert isinstance(new_links, set) # To force uniqueness
assert len(new_links) == 10, "The number of link IDs is incorrect"
assert new_links & link_ids == set(), "There is an overlap between IDs already used and new"
for link_id in new_links:
Expand Down

0 comments on commit 2a6ba91

Please sign in to comment.