forked from MIT-Emerging-Talent/ET6-practice-code-review
-
Notifications
You must be signed in to change notification settings - Fork 1
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
7f99f0c
commit d856abf
Showing
1 changed file
with
54 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,54 @@ | ||
""" " | ||
Created on 0084/01/2025 | ||
@author: Arwa Mohamed | ||
""" | ||
|
||
|
||
def kg_to_lbs(kg): | ||
"""Converts a given weight from kilograms (kg) to pounds (lbs). | ||
Parameters: | ||
kg (float): Weight in kilograms. | ||
Returns: | ||
float: Equivalent weight in pounds. | ||
>>> kg_to_lbs(75): | ||
165.347 | ||
>>> kg_to_lbs(34): | ||
74.957 | ||
>>> kg_to_lbs(10): | ||
22.046 | ||
Raises: | ||
ValueError: If the input is not a positive number. | ||
""" | ||
if kg < 0: | ||
raise ValueError("Weight cannot be negative.") | ||
return kg * 2.20462 | ||
|
||
|
||
import unittest | ||
Check failure on line 34 in solutions/tests/test_kgs_to_lbs.py GitHub Actions / py_lintingRuff (E402)
|
||
|
||
|
||
class TestKgToLbs(unittest.TestCase): | ||
def test_positive_conversion(self): | ||
self.assertAlmostEqual(kg_to_lbs(1), 2.20462, places=5) | ||
self.assertAlmostEqual(kg_to_lbs(5), 11.0231, places=4) | ||
|
||
def test_zero_conversion(self): | ||
self.assertEqual(kg_to_lbs(0), 0) | ||
|
||
def test_negative_input(self): | ||
with self.assertRaises(ValueError): | ||
kg_to_lbs(-1) | ||
|
||
def test_large_value(self): | ||
self.assertAlmostEqual(kg_to_lbs(1000), 2204.62, places=2) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |