mirror of
https://github.com/shouptech/synthale.git
synced 2026-02-03 15:39:45 +00:00
Add temp units conversion
This commit is contained in:
parent
3cd7d59e0d
commit
56c0439968
2 changed files with 53 additions and 3 deletions
|
|
@ -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
|
||||
<https://docs.python.org/3/library/string.html#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
|
||||
<https://docs.python.org/3/library/string.html#format-specification-mini-language>_`
|
||||
for how to write `format_spec`.
|
||||
"""
|
||||
return ('{:' + format_spec + '} °F').format(celsius * 1.8 + 32)
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue