Add comprehensive doctests to arc_length.py#13702
Add comprehensive doctests to arc_length.py#13702Tejasrahane wants to merge 7 commits intoTheAlgorithms:masterfrom
Conversation
- Improved type hints (int -> float) - Added edge case tests (angle=0, 360, 180) - Added float value tests - Added error handling for negative values - Enhanced docstring with formula and Wikipedia link - Added proper error messages Contributes to TheAlgorithms#9943
for more information, see https://pre-commit.ci
Tejasrahane
left a comment
There was a problem hiding this comment.
Great improvements to the arc_length.py file! Here's my review:
Strengths:
-
Comprehensive Doctests: Excellent addition of edge case tests (angle=0, 360, 180) and error handling tests for negative values.
-
Improved Type Hints: Changing from
inttofloatin the function signature is correct since arc length calculations typically work with floating-point numbers. -
Better Documentation: The enhanced docstring with formula, Wikipedia link, and clear parameter descriptions makes the function much more understandable.
-
Proper Error Handling: Adding ValueError for negative inputs with descriptive messages is a solid improvement.
Suggestions for Improvement:
-
Doctest Import Location: Consider moving
import doctestto the top of the file with other imports rather than at the bottom, following PEP 8 conventions. -
Float Value Tests: Some of the doctest examples use float inputs (e.g.,
arc_length(45.5, 10.5)), which is great for testing, but the expected output values should be verified for accuracy. -
Consider Testing Larger Angles: While you test 0, 180, and 360, it might be worth noting in the docstring whether angles > 360 are expected or should also raise an error.
Overall, this is a quality PR that significantly improves the code quality and testing coverage. Nice work!
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Contributes to #9943
Describe your change:
Checklist: