From 8767031ccc991e391149c31d1d3a9d760497e632 Mon Sep 17 00:00:00 2001 From: Tejasrahane <161036451+Tejasrahane@users.noreply.github.com> Date: Thu, 23 Oct 2025 10:19:29 +0530 Subject: [PATCH 1/7] Add comprehensive doctests to arc_length.py - 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 #9943 --- maths/arc_length.py | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/maths/arc_length.py b/maths/arc_length.py index 4c518f321dc7..4bc1702f3da8 100644 --- a/maths/arc_length.py +++ b/maths/arc_length.py @@ -1,17 +1,55 @@ from math import pi -def arc_length(angle: int, radius: int) -> float: +def arc_length(angle: float, radius: float) -> float: """ + Calculate the arc length of a circle. + + The arc length is the distance along the curved line making up the arc. + Formula: arc_length = 2 * pi * radius * (angle / 360) + + Wikipedia: https://en.wikipedia.org/wiki/Arc_length + + Args: + angle: The angle in degrees + radius: The radius of the circle + + Returns: + The arc length as a float + >>> arc_length(45, 5) 3.9269908169872414 >>> arc_length(120, 15) 31.415926535897928 >>> arc_length(90, 10) 15.707963267948966 + >>> arc_length(0, 10) + 0.0 + >>> arc_length(360, 5) + 31.41592653589793 + >>> arc_length(180, 10) + 31.41592653589793 + >>> arc_length(45.5, 10.5) + 8.329618601250994 + >>> arc_length(-90, 10) + Traceback (most recent call last): + ... + ValueError: arc_length() only accepts non-negative values + >>> arc_length(90, -10) + Traceback (most recent call last): + ... + ValueError: arc_length() only accepts non-negative values + >>> arc_length(-45, -5) + Traceback (most recent call last): + ... + ValueError: arc_length() only accepts non-negative values """ + if angle < 0 or radius < 0: + raise ValueError("arc_length() only accepts non-negative values") return 2 * pi * radius * (angle / 360) if __name__ == "__main__": - print(arc_length(90, 10)) + import doctest + + doctest.testmod() From 31b04af491812bdd8eb5559c1d4a999add710c2b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 23 Oct 2025 04:53:03 +0000 Subject: [PATCH 2/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/arc_length.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/maths/arc_length.py b/maths/arc_length.py index 4bc1702f3da8..c016cad4120d 100644 --- a/maths/arc_length.py +++ b/maths/arc_length.py @@ -4,19 +4,19 @@ def arc_length(angle: float, radius: float) -> float: """ Calculate the arc length of a circle. - + The arc length is the distance along the curved line making up the arc. Formula: arc_length = 2 * pi * radius * (angle / 360) - + Wikipedia: https://en.wikipedia.org/wiki/Arc_length - + Args: angle: The angle in degrees radius: The radius of the circle - + Returns: The arc length as a float - + >>> arc_length(45, 5) 3.9269908169872414 >>> arc_length(120, 15) From c52813dd31a939b1c16b8e56eb8b70bfe835de26 Mon Sep 17 00:00:00 2001 From: Tejasrahane <161036451+Tejasrahane@users.noreply.github.com> Date: Sat, 25 Oct 2025 10:18:39 +0530 Subject: [PATCH 3/7] Fix doctest expected value for arc_length(45.5, 10.5) --- maths/arc_length.py | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/maths/arc_length.py b/maths/arc_length.py index c016cad4120d..37c2d6340c65 100644 --- a/maths/arc_length.py +++ b/maths/arc_length.py @@ -1,22 +1,16 @@ from math import pi - def arc_length(angle: float, radius: float) -> float: """ Calculate the arc length of a circle. - The arc length is the distance along the curved line making up the arc. Formula: arc_length = 2 * pi * radius * (angle / 360) - Wikipedia: https://en.wikipedia.org/wiki/Arc_length - Args: angle: The angle in degrees radius: The radius of the circle - Returns: The arc length as a float - >>> arc_length(45, 5) 3.9269908169872414 >>> arc_length(120, 15) @@ -30,26 +24,7 @@ def arc_length(angle: float, radius: float) -> float: >>> arc_length(180, 10) 31.41592653589793 >>> arc_length(45.5, 10.5) - 8.329618601250994 + 8.33831050140291 >>> arc_length(-90, 10) Traceback (most recent call last): ... - ValueError: arc_length() only accepts non-negative values - >>> arc_length(90, -10) - Traceback (most recent call last): - ... - ValueError: arc_length() only accepts non-negative values - >>> arc_length(-45, -5) - Traceback (most recent call last): - ... - ValueError: arc_length() only accepts non-negative values - """ - if angle < 0 or radius < 0: - raise ValueError("arc_length() only accepts non-negative values") - return 2 * pi * radius * (angle / 360) - - -if __name__ == "__main__": - import doctest - - doctest.testmod() From af54e714d4a69a91501bfed1fc8970c1297d9481 Mon Sep 17 00:00:00 2001 From: Tejasrahane <161036451+Tejasrahane@users.noreply.github.com> Date: Sat, 25 Oct 2025 10:30:48 +0530 Subject: [PATCH 4/7] Fix arc_length.py: Complete docstring, add error handling, and add main block --- maths/arc_length.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/maths/arc_length.py b/maths/arc_length.py index 37c2d6340c65..525dcfded906 100644 --- a/maths/arc_length.py +++ b/maths/arc_length.py @@ -28,3 +28,18 @@ def arc_length(angle: float, radius: float) -> float: >>> arc_length(-90, 10) Traceback (most recent call last): ... + ValueError: angle and radius must be positive + >>> arc_length(90, -10) + Traceback (most recent call last): + ... + ValueError: angle and radius must be positive + """ + if angle < 0 or radius < 0: + raise ValueError("angle and radius must be positive") + return 2 * pi * radius * (angle / 360) + + +if __name__ == "__main__": + import doctest + + doctest.testmod() From a9006a4d6abe0f1baac0827a28eb88cdc007596b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 25 Oct 2025 05:01:07 +0000 Subject: [PATCH 5/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/arc_length.py | 1 + 1 file changed, 1 insertion(+) diff --git a/maths/arc_length.py b/maths/arc_length.py index 525dcfded906..d87d91828a63 100644 --- a/maths/arc_length.py +++ b/maths/arc_length.py @@ -1,5 +1,6 @@ from math import pi + def arc_length(angle: float, radius: float) -> float: """ Calculate the arc length of a circle. From 9aba6127bcdaa257d4b51950243f0f6e5d7145da Mon Sep 17 00:00:00 2001 From: Tejasrahane <161036451+Tejasrahane@users.noreply.github.com> Date: Sat, 25 Oct 2025 10:33:59 +0530 Subject: [PATCH 6/7] Restore complete file with correct doctest value and error handling --- maths/arc_length.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/maths/arc_length.py b/maths/arc_length.py index d87d91828a63..ede57134ca04 100644 --- a/maths/arc_length.py +++ b/maths/arc_length.py @@ -1,17 +1,20 @@ from math import pi - def arc_length(angle: float, radius: float) -> float: """ Calculate the arc length of a circle. + The arc length is the distance along the curved line making up the arc. Formula: arc_length = 2 * pi * radius * (angle / 360) Wikipedia: https://en.wikipedia.org/wiki/Arc_length + Args: angle: The angle in degrees radius: The radius of the circle + Returns: The arc length as a float + >>> arc_length(45, 5) 3.9269908169872414 >>> arc_length(120, 15) @@ -39,8 +42,6 @@ def arc_length(angle: float, radius: float) -> float: raise ValueError("angle and radius must be positive") return 2 * pi * radius * (angle / 360) - if __name__ == "__main__": import doctest - doctest.testmod() From 7a1a3a6e399405b238127a99a38ab7450eccb4bb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 25 Oct 2025 05:04:18 +0000 Subject: [PATCH 7/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/arc_length.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/maths/arc_length.py b/maths/arc_length.py index ede57134ca04..90c200fc5291 100644 --- a/maths/arc_length.py +++ b/maths/arc_length.py @@ -1,5 +1,6 @@ from math import pi + def arc_length(angle: float, radius: float) -> float: """ Calculate the arc length of a circle. @@ -42,6 +43,8 @@ def arc_length(angle: float, radius: float) -> float: raise ValueError("angle and radius must be positive") return 2 * pi * radius * (angle / 360) + if __name__ == "__main__": import doctest + doctest.testmod()