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

test_merge_in_radiuses_*: refactor #275

Merged
merged 5 commits into from
Jan 28, 2024
Merged
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
104 changes: 43 additions & 61 deletions tests/rotomap/test_automark.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,35 @@
"""Test suite for mel.rotomap.relate."""

import pytest

import mel.rotomap.automark as automark

TARGETS = [
{"uuid": "1", "x": 0, "y": 0},
{"uuid": "2", "x": 1, "y": 1},
{"uuid": "3", "x": 2, "y": 2}
]

RADII_SOURCES = [
{"uuid": "4", "radius": 7, "x": 0, "y": 0},
{"uuid": "5", "radius": 12, "x": 1, "y": 1},
{"uuid": "6", "radius": 18, "x": 2, "y": 2},
{"uuid": "7", "radius": 24, "x": 3, "y": 3},
]

def test_merge_in_radiuses_happy():
# Arrange
targets = [
{"uuid": "1", "x": 0, "y": 0},
{"uuid": "2", "x": 1, "y": 1},
{"uuid": "3", "x": 2, "y": 2}
]
radii_sources = [
{"uuid": "4", "radius": 7, "x": 0, "y": 0},
{"uuid": "5", "radius": 12, "x": 1, "y": 1},
{"uuid": "6", "radius": 18, "x": 2, "y": 2},
]
error_distance = 3
only_merge = False

# Act
result = automark.merge_in_radiuses(targets, radii_sources, error_distance, only_merge)

# Assert
assert len(result) == 3
assert result[0]["uuid"] == "1"
assert result[0]["radius"] == 7
assert result[1]["uuid"] == "2"
assert result[1]["radius"] == 12
assert result[2]["uuid"] == "3"
assert result[2]["radius"] == 18

@pytest.mark.parametrize("only_merge", [True, False])
@pytest.mark.parametrize("error_distance", [0, 1, 2, 3, 4, 5])
def test_merge_in_radiuses_happy(only_merge, error_distance):
"""Test merge_in_radiuses() with happy path.

def test_merge_in_radiuses_happy_only_merge():
targets = [
{"uuid": "1", "x": 0, "y": 0},
{"uuid": "2", "x": 1, "y": 1},
{"uuid": "3", "x": 2, "y": 2}
]
radii_sources = [
{"uuid": "4", "radius": 7, "x": 0, "y": 0},
{"uuid": "5", "radius": 12, "x": 1, "y": 1},
{"uuid": "6", "radius": 18, "x": 2, "y": 2},
{"uuid": "7", "radius": 24, "x": 3, "y": 3}, # This one is ignored.
]
error_distance = 3
only_merge = True
For simplicity, there are no radius sources that are not matched to a target.

result = automark.merge_in_radiuses(targets, radii_sources, error_distance, only_merge)
Each target is matched to a radius source, and the radius value is merged.

"""
radii_sources = [x for x in RADII_SOURCES if x["uuid"] != "7"]
result = automark.merge_in_radiuses(TARGETS, radii_sources, error_distance, only_merge)

assert len(result) == 3
assert result[0]["uuid"] == "1"
Expand All @@ -57,29 +40,28 @@ def test_merge_in_radiuses_happy_only_merge():
assert result[2]["radius"] == 18


def test_merge_in_radiuses_happy_not_only_merge():
targets = [
{"uuid": "1", "x": 0, "y": 0},
{"uuid": "2", "x": 1, "y": 1},
{"uuid": "3", "x": 2, "y": 2}
]
radii_sources = [
{"uuid": "4", "radius": 7, "x": 0, "y": 0},
{"uuid": "5", "radius": 12, "x": 1, "y": 1},
{"uuid": "6", "radius": 18, "x": 2, "y": 2},
{"uuid": "7", "radius": 24, "x": 3, "y": 3},
]
error_distance = 3
only_merge = False

result = automark.merge_in_radiuses(targets, radii_sources, error_distance, only_merge)

assert len(result) == 4
@pytest.mark.parametrize("only_merge", [True, False])
@pytest.mark.parametrize("error_distance", [0, 1, 2, 3, 4, 5])
def test_merge_in_radiuses_happy_merge_extra(only_merge, error_distance):
"""Test merge_in_radiuses() with happy path and extra radius sources.

There is one radius source that is not matched to a target.

It is either included or not included in the result, depending on only_merge.

"""
result = automark.merge_in_radiuses(TARGETS, RADII_SOURCES, error_distance, only_merge)

if only_merge:
assert len(result) == 3
else:
assert len(result) == 4
assert result[0]["uuid"] == "1"
assert result[0]["radius"] == 7
assert result[1]["uuid"] == "2"
assert result[1]["radius"] == 12
assert result[2]["uuid"] == "3"
assert result[2]["radius"] == 18
assert result[3]["uuid"] == "7"
assert result[3]["radius"] == 24
if not only_merge:
assert result[3]["uuid"] == "7"
assert result[3]["radius"] == 24
Loading