Open the context
Choose the project folder and name the files or behavior involved.
Update a Boolean state using finite lower and upper hysteresis thresholds. Preserve the state strictly between the thresholds and test equality at each boundary, rejecting reversed thresholds, non-finite numbers and non-Boolean states.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
from math import isfinite
def hysteresis(active, sample, low, high):
if type(active) is not bool:
raise ValueError("hysteresis.state")
if any(type(x) not in (int, float) or (type(x) is float and not isfinite(x))
for x in (sample, low, high)) or low >= high:
raise ValueError("hysteresis.thresholds")
if sample >= high:
return True
if sample <= low:
return False
return activeThe example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.