Skip to content

Commit

Permalink
another one
Browse files Browse the repository at this point in the history
  • Loading branch information
ArwaAbdelkhalik committed Jan 12, 2025
1 parent 22538d5 commit f022028
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions solutions/kgs_to_lbs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
""" "
Created on 0084/01/2025
"""
Created on 08/01/2025
@author: Arwa Mohamed
A function to convert weights from kilograms (kg) to pounds (lbs).
The kg_to_lbs function accepts a weight in kilograms and returns the equivalent weight in pounds.
It raises a ValueError for invalid inputs like negative numbers.
"""

import unittest
Expand All @@ -16,14 +22,15 @@ def kg_to_lbs(kg):
Returns:
float: Equivalent weight in pounds.
>>> kg_to_lbs(75):
165.347
Examples:
>>> kg_to_lbs(75)
165.3465
>>> kg_to_lbs(34):
74.957
>>> kg_to_lbs(34)
74.95708
>>> kg_to_lbs(10):
22.046
>>> kg_to_lbs(10)
22.0462
Raises:
ValueError: If the input is not a positive number.
Expand All @@ -34,20 +41,33 @@ def kg_to_lbs(kg):


class TestKgToLbs(unittest.TestCase):
"""Unit tests for the kg_to_lbs function.
The tests verify the following:
- Correct conversion of positive weights.
- Conversion of zero to zero pounds.
- Handling of negative input values by raising a ValueError.
- Accuracy of conversion for large values.
"""

def test_positive_conversion(self):
"""Test conversion for positive weights."""
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):
"""Test conversion for zero weight."""
self.assertEqual(kg_to_lbs(0), 0)

def test_negative_input(self):
"""Test handling of negative weights."""
with self.assertRaises(ValueError):
kg_to_lbs(-1)

def test_large_value(self):
"""Test conversion for large values."""
self.assertAlmostEqual(kg_to_lbs(1000), 2204.62, places=2)


if __name__ == "__main__":
if _name_ == "_main_":

Check failure on line 72 in solutions/kgs_to_lbs.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (F821)

solutions/kgs_to_lbs.py:72:4: F821 Undefined name `_name_`
unittest.main()

0 comments on commit f022028

Please sign in to comment.