Skip to content

Commit

Permalink
Add more tests for CrossSectionCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-kipawa committed Mar 6, 2024
1 parent 9c993c7 commit 689ded7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 15 deletions.
22 changes: 16 additions & 6 deletions mikeio1d/cross_sections/cross_section_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Dict
from typing import Tuple
from typing import List
from typing import Set

if TYPE_CHECKING:
import geopandas as gpd
Expand Down Expand Up @@ -85,16 +86,25 @@ def __or__(self, other) -> CrossSectionCollection:
super().__or__(other)

@property
def location_ids(self) -> List[str]:
return list(set([k[0] for k in self.keys()]))
def location_ids(self) -> Set[str]:
"""
Unique location IDs in the collection.
"""
return set([k[0] for k in self.keys()])

@property
def chainages(self) -> List[str]:
return list(set([k[1] for k in self.keys()]))
def chainages(self) -> Set[str]:
"""
Unique chainages in the collection (as string with 3 decimals).
"""
return set([k[1] for k in self.keys()])

@property
def topo_ids(self) -> List[str]:
return list(set([k[2] for k in self.keys()]))
def topo_ids(self) -> Set[str]:
"""
Unique topo IDs in the collection.
"""
return set([k[2] for k in self.keys()])

def sel(
self, location_id: str = ..., chainage: str | float = ..., topo_id: str = ...
Expand Down
45 changes: 36 additions & 9 deletions tests/test_cross_section_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,6 @@ def test_get_item_slice(self, many_dummy_cross_sections, slice_char):
"csc['loc0', '",
[
"0.000",
"10.000",
"20.000",
"30.000",
"40.000",
"50.000",
"60.000",
"70.000",
"80.000",
"90.000",
],
),
(
Expand All @@ -157,3 +148,39 @@ def test_index_autocompletion(
shell.push({"csc": CrossSectionCollection(cross_sections)})
completions = complete(shell, prompt)
assert completions == expected_completions

def test_joining_cross_section_collections(self, many_dummy_cross_sections):
csc1 = CrossSectionCollection(many_dummy_cross_sections[:10])
csc2 = CrossSectionCollection(many_dummy_cross_sections[10:])
csc = csc1 | csc2
assert len(csc) == 20

def test_location_ids(self, many_dummy_cross_sections):
csc = CrossSectionCollection(many_dummy_cross_sections)
assert csc.location_ids == {
"loc0",
"loc10",
"loc20",
"loc30",
"loc40",
"loc50",
"loc60",
"loc70",
"loc80",
"loc90",
}

def test_chainages(self, many_dummy_cross_sections):
csc = CrossSectionCollection(many_dummy_cross_sections)
assert csc.chainages == {
"0.000",
"10.000",
"20.000",
"30.000",
"40.000",
"50.000",
"60.000",
"70.000",
"80.000",
"90.000",
}

0 comments on commit 689ded7

Please sign in to comment.