Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/nodes #9

Merged
merged 5 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog for releases

## v1.0.0
- asdf
- `orientation_to_neighbor` 45, 135, 225, and 315 degrees are all considered `east_west`. Previously, 45 and 225 degrees were considered `north_south`.

## v0.0.0
- Initial release
Expand Down
4 changes: 2 additions & 2 deletions naturf/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ def orientation_to_neighbor(angle_in_degrees_to_neighbor: pd.Series) -> pd.Serie
(((Settings.SOUTHEAST_DEGREES <= angle_in_degrees_to_neighbor) &
(angle_in_degrees_to_neighbor <= Settings.DEGREES_IN_CIRCLE))
| ((Settings.START_OF_CIRCLE_DEGREES <= angle_in_degrees_to_neighbor) &
(angle_in_degrees_to_neighbor < Settings.NORTHEAST_DEGREES)))
(angle_in_degrees_to_neighbor <= Settings.NORTHEAST_DEGREES)))
| ((Settings.NORTHWEST_DEGREES <= angle_in_degrees_to_neighbor) &
(angle_in_degrees_to_neighbor < Settings.SOUTHWEST_DEGREES)),
(angle_in_degrees_to_neighbor <= Settings.SOUTHWEST_DEGREES)),
"east_west",
"north_south"
),
Expand Down
32 changes: 29 additions & 3 deletions naturf/tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


from naturf.driver import Model
from naturf.nodes import angle_in_degrees_to_neighbor
import naturf.nodes as nodes


class TestNodes(unittest.TestCase):
Expand Down Expand Up @@ -70,7 +70,7 @@ class TestCase:
]

for case in testcases:
actual = angle_in_degrees_to_neighbor(gpd.GeoSeries(case.target_input), gpd.GeoSeries(case.neighbor_input))
actual = nodes.angle_in_degrees_to_neighbor(gpd.GeoSeries(case.target_input), gpd.GeoSeries(case.neighbor_input))
expected = pd.Series(case.expected)
pd.testing.assert_series_equal(
expected,
Expand All @@ -80,6 +80,32 @@ class TestCase:
),
)

def test_orientation_to_neighbor(self):
"""Test that the function `orientation_to_neighbor` returns either `east_west` or `north_south` correctly."""
@dataclass
class TestCase:
name: str
input: List[int]
expected: List[int]

east_west = "east_west"
north_south = "north_south"

testcases = [
TestCase(name="zero_degrees", input=[0.0, -0.0], expected=[east_west, east_west]),
TestCase(name="north_south", input=[90, 270], expected=[north_south, north_south]),
TestCase(name="east_west", input=[45, 135, 225, 315, 360], expected=[east_west, east_west, east_west, east_west, east_west]),
]

for case in testcases:
actual = nodes.orientation_to_neighbor(pd.Series(case.input))
expected = pd.Series(case.expected)
pd.testing.assert_series_equal(
expected,
actual,
f"failed test {case.name} expected {expected}, actual {actual}"
)


if __name__ == '__main__':
unittest.main()
unittest.main()