FA-64176 / Medication dosing calculations / Open access
Patient-controlled analgesia lockout and hourly limit: lockout time units · case 01
Presses a few minutes apart are all delivered despite a 10-minute lockout.
ROOT CAUSE
The lockout in minutes is compared with elapsed seconds without conversion.
VERIFIED REPAIR
Compare elapsed seconds with lockout_min*60 using a strict less-than.
Unsuccessful approach: Converting units but using <= denies a press made exactly when the lockout ends.
Case contract
Input {presses (ascending seconds), dose_mg, lockout_min, hour_limit_mg}. A press less than 2 s after the previous press (delivered or not) is a switch bounce and ignored entirely. Otherwise it is denied for lockout when less than lockout_min*60 s have passed since the last DELIVERED dose, denied for limit when (deliveries in the preceding 3600 s + 1)*dose exceeds hour_limit_mg, else delivered. Return {delivered, denied_lockout, denied_limit, total_mg}.
Why this case matters
PCA pumps enforce lockout and rolling-hour limits on a stream of button presses; reference points and window edges are distinct defects.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
d = Fraction(str(x['dose_mg']))
lim = Fraction(str(x['hour_limit_mg']))
got, lock, cap, prev = [], 0, 0, None
for p in x['presses']:
bounce = prev is not None and p - prev < 2
prev = p
if bounce:
continue
if got and p - got[-1] < x['lockout_min']:
lock += 1
continue
inwin = sum(1 for g in got if p - g < 3600)
if (inwin + 1) * d > lim:
cap += 1
continue
got.append(p)
return {'delivered': got, 'denied_lockout': lock, 'denied_limit': cap, 'total_mg': float(len(got) * d)}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('press exactly at lockout end',
{'presses': [0, 600], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 10},
{'delivered': [0, 600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('lockout measured in seconds',
{'presses': [100, 400, 701, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
{'delivered': [100, 701, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
('hourly limit reached',
{'presses': [0, 600, 1200, 1800, 2401], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
{'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
('delivery exactly one hour old expires',
{'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
{'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
('window across clock hour',
{'presses': [3000, 3500, 3701, 4001], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
{'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
('switch bounce chain',
{'presses': [0, 1, 2, 3, 4, 701], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [0, 701], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('two second gap is a real press',
{'presses': [1000, 1002, 1710], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [1000, 1710], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
[('press exactly at lockout end',
{'presses': [0, 1200], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 10},
{'delivered': [0, 1200], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('lockout measured in seconds',
{'presses': [100, 400, 702, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
{'delivered': [100, 702, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
('hourly limit reached',
{'presses': [0, 600, 1200, 1800, 2402], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
{'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
('delivery exactly one hour old expires',
{'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
{'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
('window across clock hour',
{'presses': [3000, 3500, 3702, 4002], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
{'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
('switch bounce chain',
{'presses': [0, 1, 2, 3, 4, 702], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [0, 702], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('two second gap is a real press',
{'presses': [1000, 1002, 1720], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [1000, 1720], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
[('press exactly at lockout end',
{'presses': [0, 1800], 'dose_mg': 1, 'lockout_min': 30, 'hour_limit_mg': 10},
{'delivered': [0, 1800], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('lockout measured in seconds',
{'presses': [100, 400, 703, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
{'delivered': [100, 703, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
('hourly limit reached',
{'presses': [0, 600, 1200, 1800, 2403], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
{'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
('delivery exactly one hour old expires',
{'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
{'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
('window across clock hour',
{'presses': [3000, 3500, 3703, 4003], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
{'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
('switch bounce chain',
{'presses': [0, 1, 2, 3, 4, 703], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [0, 703], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('two second gap is a real press',
{'presses': [1000, 1002, 1730], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [1000, 1730], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
[('press exactly at lockout end',
{'presses': [0, 2400], 'dose_mg': 1, 'lockout_min': 40, 'hour_limit_mg': 10},
{'delivered': [0, 2400], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('lockout measured in seconds',
{'presses': [100, 400, 704, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
{'delivered': [100, 704, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
('hourly limit reached',
{'presses': [0, 600, 1200, 1800, 2404], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
{'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
('delivery exactly one hour old expires',
{'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
{'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
('window across clock hour',
{'presses': [3000, 3500, 3704, 4004], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
{'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
('switch bounce chain',
{'presses': [0, 1, 2, 3, 4, 704], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [0, 704], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('two second gap is a real press',
{'presses': [1000, 1002, 1740], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [1000, 1740], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
[('press exactly at lockout end',
{'presses': [0, 3000], 'dose_mg': 1, 'lockout_min': 50, 'hour_limit_mg': 10},
{'delivered': [0, 3000], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('lockout measured in seconds',
{'presses': [100, 400, 705, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
{'delivered': [100, 705, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
('hourly limit reached',
{'presses': [0, 600, 1200, 1800, 2405], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
{'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
('delivery exactly one hour old expires',
{'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
{'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
('window across clock hour',
{'presses': [3000, 3500, 3705, 4005], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
{'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
('switch bounce chain',
{'presses': [0, 1, 2, 3, 4, 705], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [0, 705], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('two second gap is a real press',
{'presses': [1000, 1002, 1750], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [1000, 1750], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| press exactly at lockout end | {'delivered': [0, 600], 'denied_limit': 0, 'denied_lockout': 0, 'total_mg': 2.0} | {'delivered': [0, 600], 'denied_limit': 0, 'denied_lockout': 0, 'total_mg': 2.0} | Passed |
| lockout measured in seconds | {'delivered': [100, 400, 701, 1300], 'denied_limit': 0, 'denied_lockout': 0, 'total_mg': 2.0} | {'delivered': [100, 701, 1300], 'denied_limit': 0, 'denied_lockout': 1, 'total_mg': 1.5} | Failed |
| hourly limit reached | {'delivered': [0, 600, 1200, 1800], 'denied_limit': 1, 'denied_lockout': 0, 'total_mg': 8.0} | {'delivered': [0, 600, 1200, 1800], 'denied_limit': 1, 'denied_lockout': 0, 'total_mg': 8.0} | Passed |
| delivery exactly one hour old expires | {'delivered': [0, 1200, 2400, 3600], 'denied_limit': 0, 'denied_lockout': 0, 'total_mg': 4.0} | {'delivered': [0, 1200, 2400, 3600], 'denied_limit': 0, 'denied_lockout': 0, 'total_mg': 4.0} | Passed |
| window across clock hour | {'delivered': [3000, 3500], 'denied_limit': 2, 'denied_lockout': 0, 'total_mg': 2.0} | {'delivered': [3000, 3500], 'denied_limit': 1, 'denied_lockout': 1, 'total_mg': 2.0} | Failed |
| switch bounce chain | {'delivered': [0, 701], 'denied_limit': 0, 'denied_lockout': 0, 'total_mg': 2.0} | {'delivered': [0, 701], 'denied_limit': 0, 'denied_lockout': 0, 'total_mg': 2.0} | Passed |
| two second gap is a real press | {'delivered': [1000, 1710], 'denied_limit': 0, 'denied_lockout': 1, 'total_mg': 2.0} | {'delivered': [1000, 1710], 'denied_limit': 0, 'denied_lockout': 1, 'total_mg': 2.0} | Passed |
SHA-256 / 21930eeb6931329565333b9a1153d40cf24a3281195a4c2cb28573a001a7dca4
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
d = Fraction(str(x['dose_mg']))
lim = Fraction(str(x['hour_limit_mg']))
got, lock, cap, prev = [], 0, 0, None
for p in x['presses']:
bounce = prev is not None and p - prev < 2
prev = p
if bounce:
continue
if got and p - got[-1] <= x['lockout_min'] * 60:
lock += 1
continue
inwin = sum(1 for g in got if p - g < 3600)
if (inwin + 1) * d > lim:
cap += 1
continue
got.append(p)
return {'delivered': got, 'denied_lockout': lock, 'denied_limit': cap, 'total_mg': float(len(got) * d)}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('press exactly at lockout end',
{'presses': [0, 600], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 10},
{'delivered': [0, 600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('lockout measured in seconds',
{'presses': [100, 400, 701, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
{'delivered': [100, 701, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
('hourly limit reached',
{'presses': [0, 600, 1200, 1800, 2401], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
{'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
('delivery exactly one hour old expires',
{'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
{'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
('window across clock hour',
{'presses': [3000, 3500, 3701, 4001], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
{'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
('switch bounce chain',
{'presses': [0, 1, 2, 3, 4, 701], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [0, 701], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('two second gap is a real press',
{'presses': [1000, 1002, 1710], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [1000, 1710], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
[('press exactly at lockout end',
{'presses': [0, 1200], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 10},
{'delivered': [0, 1200], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('lockout measured in seconds',
{'presses': [100, 400, 702, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
{'delivered': [100, 702, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
('hourly limit reached',
{'presses': [0, 600, 1200, 1800, 2402], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
{'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
('delivery exactly one hour old expires',
{'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
{'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
('window across clock hour',
{'presses': [3000, 3500, 3702, 4002], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
{'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
('switch bounce chain',
{'presses': [0, 1, 2, 3, 4, 702], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [0, 702], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('two second gap is a real press',
{'presses': [1000, 1002, 1720], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [1000, 1720], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
[('press exactly at lockout end',
{'presses': [0, 1800], 'dose_mg': 1, 'lockout_min': 30, 'hour_limit_mg': 10},
{'delivered': [0, 1800], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('lockout measured in seconds',
{'presses': [100, 400, 703, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
{'delivered': [100, 703, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
('hourly limit reached',
{'presses': [0, 600, 1200, 1800, 2403], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
{'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
('delivery exactly one hour old expires',
{'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
{'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
('window across clock hour',
{'presses': [3000, 3500, 3703, 4003], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
{'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
('switch bounce chain',
{'presses': [0, 1, 2, 3, 4, 703], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [0, 703], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('two second gap is a real press',
{'presses': [1000, 1002, 1730], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [1000, 1730], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
[('press exactly at lockout end',
{'presses': [0, 2400], 'dose_mg': 1, 'lockout_min': 40, 'hour_limit_mg': 10},
{'delivered': [0, 2400], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('lockout measured in seconds',
{'presses': [100, 400, 704, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
{'delivered': [100, 704, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
('hourly limit reached',
{'presses': [0, 600, 1200, 1800, 2404], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
{'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
('delivery exactly one hour old expires',
{'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
{'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
('window across clock hour',
{'presses': [3000, 3500, 3704, 4004], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
{'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
('switch bounce chain',
{'presses': [0, 1, 2, 3, 4, 704], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [0, 704], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('two second gap is a real press',
{'presses': [1000, 1002, 1740], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [1000, 1740], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
[('press exactly at lockout end',
{'presses': [0, 3000], 'dose_mg': 1, 'lockout_min': 50, 'hour_limit_mg': 10},
{'delivered': [0, 3000], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('lockout measured in seconds',
{'presses': [100, 400, 705, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
{'delivered': [100, 705, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
('hourly limit reached',
{'presses': [0, 600, 1200, 1800, 2405], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
{'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
('delivery exactly one hour old expires',
{'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
{'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
('window across clock hour',
{'presses': [3000, 3500, 3705, 4005], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
{'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
('switch bounce chain',
{'presses': [0, 1, 2, 3, 4, 705], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [0, 705], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('two second gap is a real press',
{'presses': [1000, 1002, 1750], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [1000, 1750], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| press exactly at lockout end | {'delivered': [0], 'denied_limit': 0, 'denied_lockout': 1, 'total_mg': 1.0} | {'delivered': [0, 600], 'denied_limit': 0, 'denied_lockout': 0, 'total_mg': 2.0} | Failed |
| lockout measured in seconds | {'delivered': [100, 701, 1300], 'denied_limit': 0, 'denied_lockout': 1, 'total_mg': 1.5} | {'delivered': [100, 701, 1300], 'denied_limit': 0, 'denied_lockout': 1, 'total_mg': 1.5} | Passed |
| hourly limit reached | {'delivered': [0, 1200, 2401], 'denied_limit': 0, 'denied_lockout': 2, 'total_mg': 6.0} | {'delivered': [0, 600, 1200, 1800], 'denied_limit': 1, 'denied_lockout': 0, 'total_mg': 8.0} | Failed |
| delivery exactly one hour old expires | {'delivered': [0, 2400], 'denied_limit': 0, 'denied_lockout': 2, 'total_mg': 2.0} | {'delivered': [0, 1200, 2400, 3600], 'denied_limit': 0, 'denied_lockout': 0, 'total_mg': 4.0} | Failed |
| window across clock hour | {'delivered': [3000, 3500], 'denied_limit': 1, 'denied_lockout': 1, 'total_mg': 2.0} | {'delivered': [3000, 3500], 'denied_limit': 1, 'denied_lockout': 1, 'total_mg': 2.0} | Passed |
| switch bounce chain | {'delivered': [0, 701], 'denied_limit': 0, 'denied_lockout': 0, 'total_mg': 2.0} | {'delivered': [0, 701], 'denied_limit': 0, 'denied_lockout': 0, 'total_mg': 2.0} | Passed |
| two second gap is a real press | {'delivered': [1000, 1710], 'denied_limit': 0, 'denied_lockout': 1, 'total_mg': 2.0} | {'delivered': [1000, 1710], 'denied_limit': 0, 'denied_lockout': 1, 'total_mg': 2.0} | Passed |
SHA-256 / a2c72847a5a80b2453a870e1a96461393d090b17057ede055420a52e4ef35f80
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
d = Fraction(str(x['dose_mg']))
lim = Fraction(str(x['hour_limit_mg']))
got, lock, cap, prev = [], 0, 0, None
for p in x['presses']:
bounce = prev is not None and p - prev < 2
prev = p
if bounce:
continue
if got and p - got[-1] < x['lockout_min'] * 60:
lock += 1
continue
inwin = sum(1 for g in got if p - g < 3600)
if (inwin + 1) * d > lim:
cap += 1
continue
got.append(p)
return {'delivered': got, 'denied_lockout': lock, 'denied_limit': cap, 'total_mg': float(len(got) * d)}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('press exactly at lockout end',
{'presses': [0, 600], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 10},
{'delivered': [0, 600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('lockout measured in seconds',
{'presses': [100, 400, 701, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
{'delivered': [100, 701, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
('hourly limit reached',
{'presses': [0, 600, 1200, 1800, 2401], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
{'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
('delivery exactly one hour old expires',
{'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
{'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
('window across clock hour',
{'presses': [3000, 3500, 3701, 4001], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
{'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
('switch bounce chain',
{'presses': [0, 1, 2, 3, 4, 701], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [0, 701], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('two second gap is a real press',
{'presses': [1000, 1002, 1710], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [1000, 1710], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
[('press exactly at lockout end',
{'presses': [0, 1200], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 10},
{'delivered': [0, 1200], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('lockout measured in seconds',
{'presses': [100, 400, 702, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
{'delivered': [100, 702, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
('hourly limit reached',
{'presses': [0, 600, 1200, 1800, 2402], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
{'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
('delivery exactly one hour old expires',
{'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
{'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
('window across clock hour',
{'presses': [3000, 3500, 3702, 4002], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
{'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
('switch bounce chain',
{'presses': [0, 1, 2, 3, 4, 702], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [0, 702], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('two second gap is a real press',
{'presses': [1000, 1002, 1720], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [1000, 1720], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
[('press exactly at lockout end',
{'presses': [0, 1800], 'dose_mg': 1, 'lockout_min': 30, 'hour_limit_mg': 10},
{'delivered': [0, 1800], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('lockout measured in seconds',
{'presses': [100, 400, 703, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
{'delivered': [100, 703, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
('hourly limit reached',
{'presses': [0, 600, 1200, 1800, 2403], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
{'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
('delivery exactly one hour old expires',
{'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
{'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
('window across clock hour',
{'presses': [3000, 3500, 3703, 4003], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
{'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
('switch bounce chain',
{'presses': [0, 1, 2, 3, 4, 703], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [0, 703], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('two second gap is a real press',
{'presses': [1000, 1002, 1730], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [1000, 1730], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
[('press exactly at lockout end',
{'presses': [0, 2400], 'dose_mg': 1, 'lockout_min': 40, 'hour_limit_mg': 10},
{'delivered': [0, 2400], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('lockout measured in seconds',
{'presses': [100, 400, 704, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
{'delivered': [100, 704, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
('hourly limit reached',
{'presses': [0, 600, 1200, 1800, 2404], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
{'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
('delivery exactly one hour old expires',
{'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
{'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
('window across clock hour',
{'presses': [3000, 3500, 3704, 4004], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
{'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
('switch bounce chain',
{'presses': [0, 1, 2, 3, 4, 704], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [0, 704], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('two second gap is a real press',
{'presses': [1000, 1002, 1740], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [1000, 1740], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})],
[('press exactly at lockout end',
{'presses': [0, 3000], 'dose_mg': 1, 'lockout_min': 50, 'hour_limit_mg': 10},
{'delivered': [0, 3000], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('lockout measured in seconds',
{'presses': [100, 400, 705, 1300], 'dose_mg': '0.5', 'lockout_min': 8, 'hour_limit_mg': 5},
{'delivered': [100, 705, 1300], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 1.5}),
('hourly limit reached',
{'presses': [0, 600, 1200, 1800, 2405], 'dose_mg': 2, 'lockout_min': 10, 'hour_limit_mg': 8},
{'delivered': [0, 600, 1200, 1800], 'denied_lockout': 0, 'denied_limit': 1, 'total_mg': 8.0}),
('delivery exactly one hour old expires',
{'presses': [0, 1200, 2400, 3600], 'dose_mg': 1, 'lockout_min': 20, 'hour_limit_mg': 3},
{'delivered': [0, 1200, 2400, 3600], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 4.0}),
('window across clock hour',
{'presses': [3000, 3500, 3705, 4005], 'dose_mg': 1, 'lockout_min': 5, 'hour_limit_mg': 2},
{'delivered': [3000, 3500], 'denied_lockout': 1, 'denied_limit': 1, 'total_mg': 2.0}),
('switch bounce chain',
{'presses': [0, 1, 2, 3, 4, 705], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [0, 705], 'denied_lockout': 0, 'denied_limit': 0, 'total_mg': 2.0}),
('two second gap is a real press',
{'presses': [1000, 1002, 1750], 'dose_mg': 1, 'lockout_min': 10, 'hour_limit_mg': 5},
{'delivered': [1000, 1750], 'denied_lockout': 1, 'denied_limit': 0, 'total_mg': 2.0})]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| press exactly at lockout end | {'delivered': [0, 600], 'denied_limit': 0, 'denied_lockout': 0, 'total_mg': 2.0} | {'delivered': [0, 600], 'denied_limit': 0, 'denied_lockout': 0, 'total_mg': 2.0} | Passed |
| lockout measured in seconds | {'delivered': [100, 701, 1300], 'denied_limit': 0, 'denied_lockout': 1, 'total_mg': 1.5} | {'delivered': [100, 701, 1300], 'denied_limit': 0, 'denied_lockout': 1, 'total_mg': 1.5} | Passed |
| hourly limit reached | {'delivered': [0, 600, 1200, 1800], 'denied_limit': 1, 'denied_lockout': 0, 'total_mg': 8.0} | {'delivered': [0, 600, 1200, 1800], 'denied_limit': 1, 'denied_lockout': 0, 'total_mg': 8.0} | Passed |
| delivery exactly one hour old expires | {'delivered': [0, 1200, 2400, 3600], 'denied_limit': 0, 'denied_lockout': 0, 'total_mg': 4.0} | {'delivered': [0, 1200, 2400, 3600], 'denied_limit': 0, 'denied_lockout': 0, 'total_mg': 4.0} | Passed |
| window across clock hour | {'delivered': [3000, 3500], 'denied_limit': 1, 'denied_lockout': 1, 'total_mg': 2.0} | {'delivered': [3000, 3500], 'denied_limit': 1, 'denied_lockout': 1, 'total_mg': 2.0} | Passed |
| switch bounce chain | {'delivered': [0, 701], 'denied_limit': 0, 'denied_lockout': 0, 'total_mg': 2.0} | {'delivered': [0, 701], 'denied_limit': 0, 'denied_lockout': 0, 'total_mg': 2.0} | Passed |
| two second gap is a real press | {'delivered': [1000, 1710], 'denied_limit': 0, 'denied_lockout': 1, 'total_mg': 2.0} | {'delivered': [1000, 1710], 'denied_limit': 0, 'denied_lockout': 1, 'total_mg': 2.0} | Passed |
SHA-256 / 797309672df6036f0cae410d57b5124c7aa2019bca20644ec8957dbc6070cd1e
Verification & scope
A deterministic toy software model with explicitly stipulated thresholds and formulas; it is not clinical guidance, not a validated medical calculator, and makes no claim of conformance to any published protocol. Numbered variants vary patient and order inputs. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:47:21.852712+00:00.
Case digest / dbe9fd7fe1aa9bdef3463fa5261efaa38b622a45421111582723a57bc92a6f45