From e3e889863bd82600c7fb39bc4552ef7055aae8e8 Mon Sep 17 00:00:00 2001 From: Shreyansh Jindal Date: Sun, 25 Oct 2026 17:13:23 +0530 Subject: [PATCH] Build: Litre to gallons converter and vice versa --- .github/PULL_REQUEST_TEMPLATE.md | 3 +++ fixit/cli.py | 1 + fixit/convert.py | 17 +++++++++++++++++ tests/test_convert.py | 9 +++++++++ 4 files changed, 30 insertions(+) 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 5ca0ce0..28165f7 100644 --- a/fixit/convert.py +++ b/fixit/convert.py @@ -37,3 +37,20 @@ def miles_to_km(miles: float) -> float: miles_to_km(1) returns approximately 1.6093. """ 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 \ No newline at end of file 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