Skip to content

Commit

Permalink
addtl lei testing
Browse files Browse the repository at this point in the history
  • Loading branch information
elbeejay committed Mar 23, 2024
1 parent 98aaf7d commit 1b095bb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/GOSTurban/LEI.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def summarize_LEI(in_file, leap_val=0.05, exp_val=0.9):
if "area" not in res.columns:
res["area"] = res["geometry"].apply(lambda x: x.area)

def calculate_LEI(val, leap_val, exp_val):
def calculate_LEI_class(val, leap_val, exp_val):
"""
Calculate the LEI class based on the input value
Expand All @@ -270,7 +270,7 @@ def calculate_LEI(val, leap_val, exp_val):
else:
return "Infill"

res["class"] = res["LEI"].apply(lambda x: calculate_LEI(x, leap_val, exp_val))
res["class"] = res["LEI"].apply(lambda x: calculate_LEI_class(x, leap_val, exp_val))
xx = res.groupby("class")

return xx["area"].sum()
29 changes: 29 additions & 0 deletions tests/test_LEI.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from GOSTurban import LEI
import pandas as pd
from shapely.geometry import Polygon
from unittest.mock import MagicMock


class TestSummarizeLEI:
Expand All @@ -26,3 +27,31 @@ def test_summarize_lei(self):
# assert things about the result
assert isinstance(result, pd.Series)
assert result.name == "area"

def test_mp_lei(self):
# mock the calculate_LEI function
LEI.calculate_LEI = MagicMock(
return_value=[
(Polygon(), 1, 2),
(Polygon(), 3, 4),
(Polygon(), 5, 6),
(Polygon(), 7, 8),
(Polygon(), 9, 10),
(Polygon(), 11, 12),
(Polygon(), 13, 14),
(Polygon(), 15, 16),
(Polygon(), 17, 18),
]
)
# run the function
result = LEI.mp_lei(
curRxx=None,
transformxx=None,
idx_xx=0,
old_list=[4, 5, 6],
new_list=[3],
buffer_dist=300,
)
# assert things about the result
assert isinstance(result, pd.Series)
assert result.name == "area"

0 comments on commit 1b095bb

Please sign in to comment.