From ca75913e447f37656ca516b235d27d8cf054e9f0 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Mon, 28 Sep 2020 18:33:22 +0300 Subject: Implement seconds_to_minutes() --- iss/tests/test_utils.py | 15 ++++++++++++++- iss/utils.py | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/iss/tests/test_utils.py b/iss/tests/test_utils.py index 4c67322..ee4971f 100644 --- a/iss/tests/test_utils.py +++ b/iss/tests/test_utils.py @@ -1,4 +1,17 @@ -from ..utils import deg_to_cardinal +from ..utils import deg_to_cardinal, seconds_to_minutes + + +def test_seconds_to_minutes(): + cases = [ + (0, "0:00"), + (1, "0:01"), + (60, "1:00"), + (61, "1:01"), + (1439, "23:59"), + (1440, "24:00"), + ] + for secs, s in cases: + assert seconds_to_minutes(secs) == s def test_deg_to_cardinal(): diff --git a/iss/utils.py b/iss/utils.py index 0bf9d04..326d835 100644 --- a/iss/utils.py +++ b/iss/utils.py @@ -3,6 +3,10 @@ def chunks(l, n): yield l[i : i + n] +def seconds_to_minutes(secs): + return f"{secs // 60}:{secs % 60:02}" + + def deg_to_cardinal(deg): cardinals = [ "N", -- cgit v1.3.1