Skip to content

Commit

Permalink
address changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedKhalifa7 committed Jan 13, 2025
1 parent 05cf757 commit b727cea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This module provides a function to calculate the area of a square.
Expand Down Expand Up @@ -30,7 +32,8 @@ def calculate_square_area(side_length: float) -> float:
"""
# Defensive assertion
assert isinstance(side_length, (int, float))
assert isinstance(side_length, float)

if side_length <= 0:
raise ValueError("side_length must be a positive number.")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This module contains unit tests for the calculate_square_area function.
Expand All @@ -20,7 +22,7 @@ def test_positive_integer_side(self):
"""
Test the function with a positive integer side length.
"""
self.assertEqual(calculate_square_area(5), 25.0)
self.assertEqual(calculate_square_area(5.0), 25.0)

def test_positive_float_side(self):
"""
Expand All @@ -32,34 +34,34 @@ def test_very_small_float_side(self):
"""
Test the function with a very small float side length.
"""
self.assertEqual(calculate_square_area(0.00000005), 0.0000000000000025)
self.assertEqual(calculate_square_area(0.00000005), 2.4999999999999996e-15)

def test_large_side(self):
"""
Test the function with a very large side length.
"""
self.assertEqual(calculate_square_area(10000000), 10000000000000000)
self.assertEqual(calculate_square_area(10000000.0), 100000000000000.0)

def test_zero_side(self):
"""
Test the function with a side length of zero.
This should raise a ValueError.
"""
with self.assertRaises(ValueError):
calculate_square_area(0)
calculate_square_area(0.0)

def test_negative_side(self):
"""
Test the function with a negative side length.
This should raise a ValueError.
"""
with self.assertRaises(ValueError):
calculate_square_area(-3)
calculate_square_area(-3.0)

def test_non_numeric_side(self):
"""
Test the function with a non-numeric side length.
This should raise a ValueError.
This should raise a AssertionError.
"""
with self.assertRaises(ValueError):
with self.assertRaises(AssertionError):
calculate_square_area("invalid")

0 comments on commit b727cea

Please sign in to comment.