diff --git a/src/synthale/convert.py b/src/synthale/convert.py index 2d468b0..05b8ed7 100644 --- a/src/synthale/convert.py +++ b/src/synthale/convert.py @@ -64,3 +64,23 @@ def pounds(kilograms, format_spec=''): for how to write `format_spec`. """ return ('{:' + format_spec + '} lb').format(kilograms * 2.204623) + + +def celsius(celsius, format_spec=''): + """Return a string with the unit appended. + + See the `Format Specification Mini-Language + _` + for how to write `format_spec`. + """ + return ('{:' + format_spec + '} °C').format(celsius) + + +def fahrenheit(celsius, format_spec=''): + """Convert celsius to fahrenheit and return a string with the unit appended. + + See the `Format Specification Mini-Language + _` + for how to write `format_spec`. + """ + return ('{:' + format_spec + '} °F').format(celsius * 1.8 + 32) diff --git a/tests/test_convert.py b/tests/test_convert.py index f9f64ce..41394bd 100644 --- a/tests/test_convert.py +++ b/tests/test_convert.py @@ -1,13 +1,43 @@ """Contains tests for the synthale.convert module.""" -from synthale.convert import liters, gallons +from synthale import convert def test_liters(): """Test liters function.""" - assert liters(1, '.1f') == '1.0 L' + assert convert.liters(1, '.1f') == '1.0 L' def test_gallons(): """Test gallons function.""" - assert gallons(1, '.1f') == '0.3 gal' + assert convert.gallons(1, '.1f') == '0.3 gal' + + +def test_kilograms(): + """Test kilograms function.""" + assert convert.kilograms(1, '.1f') == '1.0 kg' + + +def test_grams(): + """Test grams function.""" + assert convert.grams(1, '.1f') == '1000.0 g' + + +def test_ounces(): + """Test ounces function.""" + assert convert.ounces(1, '.1f') == '35.3 oz' + + +def test_pounds(): + """Test pounds function.""" + assert convert.pounds(1, '.1f') == '2.2 lb' + + +def test_celsius(): + """Test celsius function.""" + assert convert.celsius(1, '.1f') == '1.0 °C' + + +def test_fahrenheit(): + """Test fahrenheit function.""" + assert convert.fahrenheit(1, '.1f') == '33.8 °F'