Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ArwaAbdelkhalik committed Jan 11, 2025
1 parent 7f99f0c commit d856abf
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions solutions/tests/test_kgs_to_lbs.py
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

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (E402)

solutions/tests/test_kgs_to_lbs.py:34:1: E402 Module level import not at top of file

Check failure on line 34 in solutions/tests/test_kgs_to_lbs.py

View workflow job for this annotation

GitHub Actions / py_linting

Ruff (E402)

solutions/tests/test_kgs_to_lbs.py:34:1: E402 Module level import not at top of file


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 d856abf

Please sign in to comment.