Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/hio/base/tyming.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def __init__(self, tyme=0.0, tock=None, **kwa):
"""
super(Tymist,self).__init__(**kwa) # Mixin for Mult-inheritance MRO
self.tyme = float(tyme)
self.tock = float(tock) if tock is not None else self.Tock
# Use setter which applies abs() for consistency with Doer.tock
self.tock = tock if tock is not None else self.Tock

@property
def tyme(self):
Expand Down Expand Up @@ -74,8 +75,9 @@ def tock(self):
def tock(self, tock):
"""
cycle time increment property setter, set ._tock to tock
Uses abs() for consistency with Doer.tock setter (doing.py).
"""
self._tock= float(tock)
self._tock = abs(float(tock))

def tick(self, tock=None):
"""
Expand Down
34 changes: 34 additions & 0 deletions tests/base/test_tyming.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,40 @@ def test_tymist():
"""End Test """


def test_tymist_tock_abs_guard():
"""
Test Tymist.tock setter applies abs() for consistency with Doer.tock.

This guards against negative tock values which would cause tyme to
decrement on tick(), breaking all scheduling invariants:
- Tyme monotonicity violated
- Tymers never expire
- Periodic Doers' retymes never reached
"""
tymist = tyming.Tymist()

# Negative tock should be converted to positive
tymist.tock = -1.0
assert tymist.tock == 1.0, "Tymist.tock setter should apply abs()"

# Verify tyme always increases after tick
tymist.tyme = 0.0
tymist.tick()
assert tymist.tyme == 1.0, "tick() should increase tyme"

# Even with negative input, tyme should still increase
tymist.tock = -0.5
assert tymist.tock == 0.5
tymist.tick()
assert tymist.tyme == 1.5, "tick() should continue to increase tyme"

# Test negative tock in constructor
tymist2 = tyming.Tymist(tock=-0.25)
assert tymist2.tock == 0.25, "Constructor should also apply abs()"

"""End Test """


def test_tymee():
"""
Test Tymee class
Expand Down