Skip to content

Commit

Permalink
test_voronoi_regions_from_coords_italy complete
Browse files Browse the repository at this point in the history
  • Loading branch information
internaut committed Jan 29, 2021
1 parent 04a86df commit 0ea1889
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_get_points_to_poly_assignments_hypothesis(available_points, n_poly):


@settings(deadline=10000)
@given(n_pts=st.integers(0, 20),
@given(n_pts=st.integers(0, 200),
per_geom=st.booleans(),
return_unassigned_pts=st.booleans(),
results_per_geom=st.booleans())
Expand Down Expand Up @@ -136,12 +136,10 @@ def test_voronoi_regions_from_coords_italy(n_pts, per_geom, return_unassigned_pt
geom_area = area_shape.geoms[i_geom].area
else:
geom_area = sum(g.area for g in area_shape.geoms)
fig, ax = subplot_for_map()
plot_voronoi_polys_with_points_in_area(ax, area_shape, region_polys_in_geom, coords, region_pts_in_geom)
_check_region_polys(region_polys_in_geom.values(), region_pts_in_geom.values(), coords,
expected_sum_area=geom_area)
else:
# no polys generated -> must be insufficient number of points
# no polys generated -> must be insufficient number of points in geom
pass
else: # not results_per_geom
assert len(region_polys) <= n_pts
Expand All @@ -150,6 +148,19 @@ def test_voronoi_regions_from_coords_italy(n_pts, per_geom, return_unassigned_pt
if unassigned_pts is not None:
assert set(range(n_pts)) - set(pts_region.keys()) == unassigned_pts

assert isinstance(region_polys, dict)
assert isinstance(region_pts, dict)
assert list(region_polys.keys()) == list(region_pts.keys())

if region_polys:
if per_geom:
geom_area = None # can't determine this here
else:
geom_area = sum(g.area for g in area_shape.geoms)
_check_region_polys(region_polys.values(), region_pts.values(), coords, expected_sum_area=geom_area)
else:
# no polys generated -> must be insufficient number of points
assert n_pts < 4


# #%% realistic full tests with plotting
Expand Down Expand Up @@ -381,4 +392,5 @@ def _check_region_polys(region_polys, region_pts, coords, expected_sum_area, con

sum_area += poly.area

assert np.isclose(sum_area, expected_sum_area)
if expected_sum_area is not None:
assert np.isclose(sum_area, expected_sum_area)

0 comments on commit 0ea1889

Please sign in to comment.