diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 75e1d4a..9d50b47 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,5 +1,8 @@ ## What does this PR do? +added gallons to litres conversion and vice versa, +added cli choice for both of them too, +also made the conversion test ## Related issue Closes # diff --git a/fixit/cli.py b/fixit/cli.py index 52d4ffb..c30bcd0 100644 --- a/fixit/cli.py +++ b/fixit/cli.py @@ -14,6 +14,7 @@ "f2c": convert.fahrenheit_to_celsius, "km2mi": convert.km_to_miles, "mi2km": convert.miles_to_km, + "l2gal": convert.litres_to_gallons, } diff --git a/fixit/convert.py b/fixit/convert.py index 54293cd..2d3e9a7 100644 --- a/fixit/convert.py +++ b/fixit/convert.py @@ -40,6 +40,21 @@ def miles_to_km(miles: float) -> float: return miles * KM_PER_MILE +def litres_to_gallons(litre: float)->float: + """Convert litres to US gallons. + + example: + l2gal(1) return approximately 0.2641 + """ + return litre*0.2641 + +def gallons_to_litres(gallons: float)->float: + """Convert US gallons to litres. + + example: + gal2l(1) return approximately 3.7854 + """ + return gallons*3.7854 def kg_to_lbs(kg: float) -> float: """Convert kilograms to pounds. diff --git a/tests/test_convert.py b/tests/test_convert.py index ddd3410..86e082a 100644 --- a/tests/test_convert.py +++ b/tests/test_convert.py @@ -5,6 +5,8 @@ fahrenheit_to_celsius, km_to_miles, miles_to_km, + litres_to_gallons, + gallons_to_litres ) @@ -38,3 +40,10 @@ def test_absolute_zero(): def test_float_km_to_miles(): assert km_to_miles(1.5) == pytest.approx(0.932056788) + + +def test_litres_to_gallons(): + assert litres_to_gallons(8)==pytest.approx(2.113383) + +def test_gallons_to_litres(): + assert gallons_to_litres(4)==pytest.approx(15.1416) \ No newline at end of file