-
Notifications
You must be signed in to change notification settings - Fork 0
102 task add GridCell model #119
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
77f5a19
Add GridCell model and unit tests for stroke containment
kimit0310 4d6ac33
using half-open intervals for GridCell boundary checks
kimit0310 1d8d55c
Updated the class docstring to note the half-open interval policy and…
kimit0310 f2c46d7
Refactor boundary tests for GridCell to use parameterized inputs
kimit0310 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| """Test cases for the GridCell model.""" | ||
|
|
||
| import pandas as pd | ||
| import pytest | ||
|
|
||
| from graphomotor.core import models | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def cell() -> models.GridCell: | ||
| """Create a grid cell representing one letter region.""" | ||
| return models.GridCell( | ||
| x_min=10.0, x_max=25.0, y_min=80.0, y_max=97.0, index=0, label="A" | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "x_min,x_max,y_min,y_max,expected_error", | ||
| [ | ||
| (10.0, 5.0, 0.0, 1.0, "x_min .* must be less than x_max"), | ||
| (5.0, 5.0, 0.0, 1.0, "x_min .* must be less than x_max"), | ||
| (0.0, 1.0, 10.0, 5.0, "y_min .* must be less than y_max"), | ||
| (0.0, 1.0, 5.0, 5.0, "y_min .* must be less than y_max"), | ||
| ], | ||
| ) | ||
| def test_grid_cell_invalid_bounds( | ||
| x_min: float, | ||
| x_max: float, | ||
| y_min: float, | ||
| y_max: float, | ||
| expected_error: str, | ||
| ) -> None: | ||
| """Test that invalid or equal bounds raise ValueError.""" | ||
| with pytest.raises(ValueError, match=expected_error): | ||
| models.GridCell(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) | ||
|
|
||
|
|
||
| def test_stroke_centroid_inside_cell(cell: models.GridCell) -> None: | ||
| """Stroke whose centroid falls inside the cell should be contained.""" | ||
| stroke_points = pd.DataFrame({"x": [15.0, 20.0, 17.0], "y": [85.0, 90.0, 95.0]}) | ||
| assert cell.contains_points(stroke_points) | ||
|
|
||
|
|
||
| def test_stroke_centroid_outside_cell(cell: models.GridCell) -> None: | ||
| """Stroke whose centroid falls outside the cell should not be contained.""" | ||
| stroke_points = pd.DataFrame({"x": [33.8, 37.8, 35.3], "y": [85.8, 95.4, 90.1]}) | ||
| assert not cell.contains_points(stroke_points) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "x_vals,y_vals", | ||
| [ | ||
| ([10.0, 10.0], [88.0, 89.0]), | ||
| ([17.0, 18.0], [80.0, 80.0]), | ||
| ], | ||
| ids=["left_boundary", "bottom_boundary"], | ||
| ) | ||
| def test_stroke_centroid_on_lower_boundary( | ||
| cell: models.GridCell, x_vals: list[float], y_vals: list[float] | ||
| ) -> None: | ||
| """Stroke whose centroid lands on the lower/left boundary (min) is included.""" | ||
|
kimit0310 marked this conversation as resolved.
|
||
| stroke_points = pd.DataFrame({"x": x_vals, "y": y_vals}) | ||
| assert cell.contains_points(stroke_points) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "x_vals,y_vals", | ||
| [ | ||
| ([25.0, 25.0], [88.0, 89.0]), | ||
| ([17.0, 18.0], [97.0, 97.0]), | ||
| ], | ||
| ids=["right_boundary", "top_boundary"], | ||
| ) | ||
| def test_stroke_centroid_on_upper_boundary( | ||
| cell: models.GridCell, x_vals: list[float], y_vals: list[float] | ||
| ) -> None: | ||
| """Stroke whose centroid lands on the upper/right boundary (max) is excluded.""" | ||
|
kimit0310 marked this conversation as resolved.
|
||
| stroke_points = pd.DataFrame({"x": x_vals, "y": y_vals}) | ||
| assert not cell.contains_points(stroke_points) | ||
|
|
||
|
|
||
| def test_stroke_points_span_outside_but_centroid_inside( | ||
| cell: models.GridCell, | ||
| ) -> None: | ||
| """Stroke with points outside the cell but centroid inside should be contained.""" | ||
| stroke_points = pd.DataFrame({"x": [8.0, 22.0], "y": [78.0, 98.0]}) | ||
| assert cell.contains_points(stroke_points) | ||
|
|
||
|
|
||
| def test_single_point_stroke(cell: models.GridCell) -> None: | ||
| """Single-point stroke should use that point as its centroid.""" | ||
| stroke_points = pd.DataFrame({"x": [17.5], "y": [90.0]}) | ||
| assert cell.contains_points(stroke_points) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.