From f022028470b964f68f0ac0cf587f3ef2d3b62a1f Mon Sep 17 00:00:00 2001 From: arwaabdelkhalik Date: Sun, 12 Jan 2025 08:41:39 +0300 Subject: [PATCH] another one --- solutions/kgs_to_lbs.py | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/solutions/kgs_to_lbs.py b/solutions/kgs_to_lbs.py index a002cd652..d58ab0437 100644 --- a/solutions/kgs_to_lbs.py +++ b/solutions/kgs_to_lbs.py @@ -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 @@ -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. @@ -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_": unittest.main()