Skip to content

Commit

Permalink
try
Browse files Browse the repository at this point in the history
  • Loading branch information
ArwaAbdelkhalik committed Jan 12, 2025
1 parent 890366d commit 22538d5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions solutions/kgs_to_lbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""

import unittest


def kg_to_lbs(kg):
"""Converts a given weight from kilograms (kg) to pounds (lbs).
Expand All @@ -29,3 +31,23 @@ def kg_to_lbs(kg):
if kg < 0:
raise ValueError("Weight cannot be negative.")
return kg * 2.20462


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()

0 comments on commit 22538d5

Please sign in to comment.