From aca82dd3c363ab294dd7badf210db67e873a74f4 Mon Sep 17 00:00:00 2001 From: Harbinger Date: Wed, 11 Sep 2024 04:46:14 -0500 Subject: [PATCH] fix: bell and minute rollover, add test case (#15) * fix: bell and minute rollover, add test case * improve test coverage * pin test time, make positive rollover test moon and year as well --- EorzeaEnv/eorzea_time.py | 4 +-- test/test_time.py | 68 ++++++++++++++++++++++++++++++++++------ 2 files changed, 60 insertions(+), 12 deletions(-) diff --git a/EorzeaEnv/eorzea_time.py b/EorzeaEnv/eorzea_time.py index 8b805e1..eed9608 100644 --- a/EorzeaEnv/eorzea_time.py +++ b/EorzeaEnv/eorzea_time.py @@ -106,7 +106,7 @@ def bell(self, value): self._bell += 24 self.sun = self.sun - 1 - while self._bell > 24: + while self._bell >= 24: self._bell -= 24 self.sun = self.sun + 1 @@ -121,7 +121,7 @@ def minute(self, value): self._minute += 60 self.bell = self.bell - 1 - while self._minute > 60: + while self._minute >= 60: self._minute -= 60 self.bell = self.bell + 1 diff --git a/test/test_time.py b/test/test_time.py index feed546..9d7816f 100644 --- a/test/test_time.py +++ b/test/test_time.py @@ -60,6 +60,64 @@ def test_time_operator(self): assert t1 != 1 assert not t1 == 1 + def test_positive_rollover(self): + et = EorzeaTime() + et.minute = 59 + et.bell = 23 + et.sun = 32 + et.moon = 12 + et.year = 999 + + et.minute += 1 + + assert et.minute == 0 + assert et.bell == 0 + assert et.sun == 1 + assert et.moon == 1 + assert et.year == 1000 + + et.minute += 121 + + assert et.minute == 1 + assert et.bell == 2 + + et.bell += 49 + + assert et.bell == 3 + assert et.sun == 3 + + def test_negative_rollover(self): + et = EorzeaTime() + et.minute = 0 + et.bell = 0 + et.sun = 1 + et.moon = 2 + et.year = 1000 + + et.minute -= 1 + + assert et.minute == 59 + assert et.bell == 23 + assert et.sun == 32 + assert et.moon == 1 + + et.minute -= 119 + + assert et.minute == 0 + assert et.bell == 22 + + et.bell -= 48 + + assert et.minute == 0 + assert et.bell == 22 + assert et.sun == 30 + assert et.moon == 1 + + et.moon -= 11 + + assert et.moon == 2 + assert et.year == 999 + def test_property(self): ts = 12700000 et = EorzeaTime(ts) @@ -73,16 +131,6 @@ def test_property(self): assert et.moon_phase == 0.50 assert et.moon_name == "Sixth Embral Moon" - et = EorzeaTime() - et.moon += 13 - et.sun += 33 - et.bell += 26 - et.minute += 65 - et.moon -= 13 - et.sun -= 33 - et.bell -= 26 - et.minute -= 65 - def test_repr(self): et = EorzeaTime.now() assert repr(et) == f"EorzeaTime({et.get_unix_time()})"