forked from MIT-Emerging-Talent/ET6-practice-code-review
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
262dad7
commit e24946c
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,14 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Python Debugger: Python File", | ||
"type": "debugpy", | ||
"request": "launch", | ||
"program": "${file}" | ||
} | ||
] | ||
} |
This file contains 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,32 @@ | ||
""" | ||
This module provides a function to calculate the area of a circle given its radius. | ||
""" | ||
|
||
import math | ||
|
||
|
||
def area_of_circle(radius: float) -> float: | ||
""" | ||
Calculate the area of a circle given its radius. | ||
Args: | ||
radius (float): The radius of the circle. Must be a non-negative number. | ||
Returns: | ||
float: The area of the circle. | ||
Raises: | ||
ValueError: If the radius is negative. | ||
Examples: | ||
>>> area_of_circle(1) | ||
3.141592653589793 | ||
>>> area_of_circle(0) | ||
0.0 | ||
>>> area_of_circle(2.5) | ||
19.634954084936208 | ||
""" | ||
if radius < 0: | ||
raise ValueError("The radius must be a non-negative number.") | ||
|
||
return math.pi * radius * radius |
This file contains 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,35 @@ | ||
""" | ||
Test suite for the area_of_circle function. | ||
""" | ||
|
||
import math | ||
import unittest | ||
from area_circle import area_of_circle | ||
|
||
|
||
class TestAreaOfCircle(unittest.TestCase): | ||
""" | ||
Unit tests for the area_of_circle function. | ||
""" | ||
|
||
def test_positive_radius(self): | ||
"""Test area calculation with a positive radius.""" | ||
self.assertAlmostEqual(area_of_circle(1), 3.141592653589793) | ||
self.assertAlmostEqual(area_of_circle(2.5), 19.634954084936208) | ||
|
||
def test_zero_radius(self): | ||
"""Test area calculation with a radius of zero.""" | ||
self.assertAlmostEqual(area_of_circle(0), 0.0) | ||
|
||
def test_negative_radius(self): | ||
"""Test area calculation with a negative radius.""" | ||
with self.assertRaises(ValueError): | ||
area_of_circle(-1) | ||
|
||
def test_large_radius(self): | ||
"""Test area calculation with a large radius.""" | ||
self.assertAlmostEqual(area_of_circle(1e6), math.pi * 1e6 * 1e6) | ||
|
||
|
||
if __name__ == "main": | ||
unittest.main() |