Skip to content

Commit

Permalink
fix: bell and minute rollover, add test case (#15)
Browse files Browse the repository at this point in the history
* fix: bell and minute rollover, add test case

* improve test coverage

* pin test time, make positive rollover test moon and year as well
  • Loading branch information
harbingerftw authored Sep 11, 2024
1 parent 34e623e commit aca82dd
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 12 deletions.
4 changes: 2 additions & 2 deletions EorzeaEnv/eorzea_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
68 changes: 58 additions & 10 deletions test/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()})"
Expand Down

0 comments on commit aca82dd

Please sign in to comment.