-
Notifications
You must be signed in to change notification settings - Fork 45
Add edge case tests for refactored make_line functions #648
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
base: 263-refactor_make_line
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -56,5 +56,325 @@ def test_a_b_same(): | |||||||||
| make_line(Vector([1, 1]), (10, 10), (10, 10)) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| # ============================================================================ | ||||||||||
| # EDGE CASE TESTS FOR make_line_straight | ||||||||||
| # ============================================================================ | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def test_horizontal_line(): | ||||||||||
| """Test horizontal line (slope = 0).""" | ||||||||||
| grid_size = Vector([10, 10]) | ||||||||||
| startpoint = (5, 2) | ||||||||||
| endpoint = (5, 8) | ||||||||||
| line = make_line(grid_size, startpoint, endpoint) | ||||||||||
|
|
||||||||||
| # Check that the line is horizontal | ||||||||||
| assert np.sum(line) > 0, "Line should have some points" | ||||||||||
| # All points should be on row 5 (index 4) | ||||||||||
| assert np.sum(line[4, :]) == np.sum(line), "All points should be on the same row" | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def test_vertical_line(): | ||||||||||
| """Test vertical line (slope = infinity).""" | ||||||||||
| grid_size = Vector([10, 10]) | ||||||||||
| startpoint = (2, 5) | ||||||||||
| endpoint = (8, 5) | ||||||||||
| line = make_line(grid_size, startpoint, endpoint) | ||||||||||
|
|
||||||||||
| # Check that the line is vertical | ||||||||||
| assert np.sum(line) > 0, "Line should have some points" | ||||||||||
| # All points should be on column 5 (index 4) | ||||||||||
| assert np.sum(line[:, 4]) == np.sum(line), "All points should be on the same column" | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def test_diagonal_45_degree(): | ||||||||||
| """Test diagonal line at 45 degrees (slope = 1).""" | ||||||||||
| grid_size = Vector([10, 10]) | ||||||||||
| startpoint = (2, 2) | ||||||||||
| endpoint = (8, 8) | ||||||||||
| line = make_line(grid_size, startpoint, endpoint) | ||||||||||
|
|
||||||||||
| # Check that the line has points | ||||||||||
| assert np.sum(line) > 0, "Line should have some points" | ||||||||||
| # For 45 degree line, we expect roughly equal number of x and y steps | ||||||||||
| assert np.sum(line) >= 6, "Should have at least 6 points for this diagonal" | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def test_diagonal_negative_45_degree(): | ||||||||||
| """Test diagonal line at -45 degrees (slope = -1).""" | ||||||||||
| grid_size = Vector([10, 10]) | ||||||||||
| startpoint = (2, 8) | ||||||||||
| endpoint = (8, 2) | ||||||||||
| line = make_line(grid_size, startpoint, endpoint) | ||||||||||
|
|
||||||||||
| # Check that the line has points | ||||||||||
| assert np.sum(line) > 0, "Line should have some points" | ||||||||||
| assert np.sum(line) >= 6, "Should have at least 6 points for this diagonal" | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def test_steep_slope(): | ||||||||||
| """Test line with very steep slope (|m| > 1).""" | ||||||||||
| grid_size = Vector([20, 10]) | ||||||||||
| startpoint = (2, 5) | ||||||||||
| endpoint = (18, 7) # Steep line, mostly vertical | ||||||||||
| line = make_line(grid_size, startpoint, endpoint) | ||||||||||
|
|
||||||||||
| # Check that the line has points | ||||||||||
| assert np.sum(line) > 0, "Line should have some points" | ||||||||||
| # Should have many points since it's a long line | ||||||||||
| assert np.sum(line) >= 10, "Should have at least 10 points" | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def test_shallow_slope(): | ||||||||||
| """Test line with very shallow slope (|m| < 1).""" | ||||||||||
| grid_size = Vector([10, 20]) | ||||||||||
| startpoint = (5, 2) | ||||||||||
| endpoint = (7, 18) # Shallow line, mostly horizontal | ||||||||||
|
Comment on lines
+131
to
+132
|
||||||||||
| startpoint = (5, 2) | |
| endpoint = (7, 18) # Shallow line, mostly horizontal | |
| startpoint = (2, 5) | |
| endpoint = (18, 7) # Shallow line, mostly horizontal |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using == True is redundant in boolean assertions. Use assert line[0, 0] instead of assert line[0, 0] == True for more Pythonic code.
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using == True is redundant in boolean assertions. Use assert line[9, 0] instead of assert line[9, 0] == True for more Pythonic code.
| assert line[9, 0] == True, "First point should be at bottom-left" | |
| assert line[9, 0], "First point should be at bottom-left" |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using == True is redundant in boolean assertions. Use assert line[0, 0] instead of assert line[0, 0] == True for more Pythonic code.
| assert line[0, 0] == True, "First point should be at top-left corner" | |
| assert line[0, 0], "First point should be at top-left corner" |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using == True is redundant in boolean assertions. Use assert line[0, 9] instead of assert line[0, 9] == True for more Pythonic code.
| assert line[0, 9] == True, "First point should be at top-right corner" | |
| assert line[0, 9], "First point should be at top-right corner" |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using == True is redundant in boolean assertions. Use assert line[4, 4] instead of assert line[4, 4] == True for more Pythonic code.
| assert line[4, 4] == True, "Starting point should be marked" | |
| assert line[4, 4], "Starting point should be marked" |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using np.allclose for comparing boolean arrays is not ideal. Consider using np.array_equal(line, line_pi) instead, which is more appropriate for exact boolean array comparison.
| assert np.allclose(line, line_pi), "Angle wrapping should work correctly" | |
| assert np.array_equal(line, line_pi), "Angle wrapping should work correctly" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states "Steep line, mostly vertical" but the coordinates suggest otherwise. With startpoint (2, 5) and endpoint (18, 7), the line has a slope of approximately 0.125 (delta_y=2, delta_x=16), making it a shallow, mostly horizontal line, not steep and vertical. Please correct the comment or adjust the test parameters.