Skip to content

Commit

Permalink
clean up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ajfriend committed Dec 31, 2024
1 parent c627dca commit 0a5eac0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
9 changes: 5 additions & 4 deletions src/h3/api/basic_int/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,13 @@ def polygon_to_cells(h3shape, res):
return h3shape_to_cells(h3shape, res)


# TODO: better docstring explaining experimental options
def h3shape_to_cells_experimental(h3shape, res, containment='center'):
"""
Return the collection of H3 cells at a given resolution whose center points
are contained within an ``LatLngPoly`` or ``LatLngMultiPoly``.
Experimental function similar to ``h3shape_to_cells``, but with support for
multiple cell containment modes.
Using ``containment='center'`` should give identical behavior as
``h3shape_to_cells``.
Parameters
----------
Expand All @@ -543,7 +545,6 @@ def h3shape_to_cells_experimental(h3shape, res, containment='center'):
- 'overlap': Cell is partially contained in shape
- 'bbox_overlap': Cell bounding box is partially contained in shape
Returns
-------
list of H3Cell
Expand Down
57 changes: 28 additions & 29 deletions tests/test_lib/polyfill/test_h3.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,53 +119,52 @@ def test_polygon_to_cells():

def test_h3shape_to_cells_experimental():
poly = h3.LatLngPoly(sf_7x7)
for flags in ['center']:
out = h3.h3shape_to_cells_experimental(poly, res=9, containment=flags)

assert len(out) == 1253
assert '89283080527ffff' in out
assert '89283095edbffff' in out
out = h3.h3shape_to_cells_experimental(poly, res=9, containment='center')

assert len(out) == 1253
assert '89283080527ffff' in out
assert '89283095edbffff' in out


def test_h3shape_to_cells_experimental_full():
poly = h3.LatLngPoly(sf_7x7)
for flags in ['full']:
out = h3.h3shape_to_cells_experimental(poly, res=9, containment=flags)

assert len(out) == 1175
assert '89283082a1bffff' in out
assert '89283080527ffff' not in out
assert '89283095edbffff' in out
out = h3.h3shape_to_cells_experimental(poly, res=9, containment='full')

assert len(out) == 1175
assert '89283082a1bffff' in out
assert '89283080527ffff' not in out
assert '89283095edbffff' in out


def test_h3shape_to_cells_experimental_overlapping():
poly = h3.LatLngPoly(sf_7x7)
for flags in ['overlap']:
out = h3.h3shape_to_cells_experimental(poly, res=9, containment=flags)

assert len(out) == 1334
assert '89283080527ffff' in out
assert '89283095edbffff' in out
out = h3.h3shape_to_cells_experimental(poly, res=9, containment='overlap')

assert len(out) == 1334
assert '89283080527ffff' in out
assert '89283095edbffff' in out


# TODO: fix these for flags loops
def test_h3shape_to_cells_experimental_overlapping_bbox():
poly = h3.LatLngPoly(sf_7x7)
for flags in [
'bbox_overlap'
]:
out = h3.h3shape_to_cells_experimental(poly, res=9, containment=flags)
out = h3.h3shape_to_cells_experimental(poly, res=9, containment='bbox_overlap')

assert len(out) == 1416
assert '89283080527ffff' in out
assert '89283095edbffff' in out
assert len(out) == 1416
assert '89283080527ffff' in out
assert '89283095edbffff' in out


def test_h3shape_to_cells_experimental_invalid_mode():
poly = h3.LatLngPoly(sf_7x7)
for flags in ['containment_overlapping_bbox_abc']:
with pytest.raises(KeyError):
h3.h3shape_to_cells_experimental(poly, res=9, containment=flags)
with pytest.raises(KeyError):
h3.h3shape_to_cells_experimental(
poly,
res = 9,
containment = 'containment_overlapping_bbox_abc',
)


def test_poly_to_cells_experimental_mpoly():
Expand All @@ -185,8 +184,8 @@ def test_poly_to_cells_experimental_mpoly():
<
set(h3.h3shape_to_cells_experimental(
mpoly,
res=9,
containment='overlap'
res = 9,
containment = 'overlap'
))
)

Expand Down

0 comments on commit 0a5eac0

Please sign in to comment.