broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    pos, cmd = x['pos'], x['cmd']
    if pos == cmd:
        return {'pos': pos, 'result': 'in-position', 'alarm': False}
    if x['route_locked']:
        return {'pos': pos, 'result': 'route-locked', 'alarm': pos == 'X'}
    if x['occupied']:
        return {'pos': pos, 'result': 'track-locked', 'alarm': pos == 'X'}
    det = x['detected_ms']
    if det is None or det >= x['limit_ms']:
        return {'pos': 'X', 'result': 'no-detection', 'alarm': True}
    return {'pos': cmd, 'result': 'moved', 'alarm': False}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('boundary: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('sampled regression 59', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 33', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 3999}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 1', {'pos': 'X', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 4500}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 4', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 6000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 7', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'in-position', 'alarm': False})], [('regression: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('boundary: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 43', {'pos': 'X', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4500}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: immediate detection', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 12', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 15', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 3999}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 18', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('boundary: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('sampled regression 41', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 48', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 3001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: already reverse while route locked', {'pos': 'R', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('sampled regression 23', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 26', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 1500}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 29', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'R', 'result': 'in-position', 'alarm': False})], [('regression: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('boundary: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('sampled regression 68', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('boundary: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('boundary: normal point locked by a route', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 34', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 37', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 40', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 7000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('boundary: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('sampled regression 23', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 33', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 3999}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: failed throw from normal', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 9000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 45', {'pos': 'X', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2999}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 48', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 3001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 51', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 0}, {'pos': 'R', 'result': 'moved', 'alarm': False})]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    pos, cmd = x['pos'], x['cmd']
    if pos == cmd:
        return {'pos': pos, 'result': 'in-position', 'alarm': False}
    if x['route_locked']:
        return {'pos': pos, 'result': 'route-locked', 'alarm': pos == 'X'}
    if x['occupied']:
        return {'pos': pos, 'result': 'track-locked', 'alarm': pos == 'X'}
    det = x['detected_ms']
    if det is None or det // 1000 > x['limit_ms'] // 1000:
        return {'pos': 'X', 'result': 'no-detection', 'alarm': True}
    return {'pos': cmd, 'result': 'moved', 'alarm': False}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('boundary: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('sampled regression 59', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 33', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 3999}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 1', {'pos': 'X', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 4500}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 4', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 6000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 7', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'in-position', 'alarm': False})], [('regression: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('boundary: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 43', {'pos': 'X', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4500}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: immediate detection', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 12', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 15', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 3999}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 18', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('boundary: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('sampled regression 41', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 48', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 3001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: already reverse while route locked', {'pos': 'R', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('sampled regression 23', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 26', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 1500}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 29', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'R', 'result': 'in-position', 'alarm': False})], [('regression: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('boundary: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('sampled regression 68', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('boundary: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('boundary: normal point locked by a route', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 34', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 37', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 40', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 7000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('boundary: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('sampled regression 23', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 33', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 3999}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: failed throw from normal', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 9000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 45', {'pos': 'X', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2999}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 48', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 3001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 51', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 0}, {'pos': 'R', 'result': 'moved', 'alarm': False})]]
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)

prompt:
A point detected exactly at the deadline is declared failed.

A point command is answered as in-position when already detected in the commanded lie (even if locked or occupied). Otherwise route locking refuses (route-locked), then track locking refuses (track-locked); the alarm flag on refusals is raised only when the point has lost detection (X). A throw that fails to regain detection within limit_ms (inclusive; None means never) leaves the point X with alarm; otherwise it lies in the commanded position. detected_ms of 0 means detection was immediate.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    pos, cmd = x['pos'], x['cmd']
    if pos == cmd:
        return {'pos': pos, 'result': 'in-position', 'alarm': False}
    if x['route_locked']:
        return {'pos': pos, 'result': 'route-locked', 'alarm': pos == 'X'}
    if x['occupied']:
        return {'pos': pos, 'result': 'track-locked', 'alarm': pos == 'X'}
    det = x['detected_ms']
    if det is not None and det > x['limit_ms']:
        return {'pos': 'X', 'result': 'no-detection', 'alarm': True}
    return {'pos': cmd, 'result': 'moved', 'alarm': False}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: immediate detection', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 34', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('boundary: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('boundary: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 1', {'pos': 'X', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 4500}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 4', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 6000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 7', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'in-position', 'alarm': False})], [('regression: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: immediate detection', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('sampled regression 24', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 79', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('boundary: already reverse while route locked', {'pos': 'R', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 12', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 15', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 3999}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 18', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: immediate detection', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('sampled regression 71', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 60', {'pos': 'X', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 0}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('boundary: already reverse while route locked', {'pos': 'R', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 23', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 26', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 1500}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 29', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'R', 'result': 'in-position', 'alarm': False})], [('regression: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: immediate detection', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 36', {'pos': 'X', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('boundary: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('boundary: normal point locked by a route', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 34', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 37', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 40', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 7000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: immediate detection', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('sampled regression 24', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: failed throw from normal', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 9000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 45', {'pos': 'X', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2999}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 48', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 3001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 51', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 0}, {'pos': 'R', 'result': 'moved', 'alarm': False})]]
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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    pos, cmd = x['pos'], x['cmd']
    if pos == cmd:
        return {'pos': pos, 'result': 'in-position', 'alarm': False}
    if x['route_locked']:
        return {'pos': pos, 'result': 'route-locked', 'alarm': pos == 'X'}
    if x['occupied']:
        return {'pos': pos, 'result': 'track-locked', 'alarm': pos == 'X'}
    det = x['detected_ms']
    if not det or det > x['limit_ms']:
        return {'pos': 'X', 'result': 'no-detection', 'alarm': True}
    return {'pos': cmd, 'result': 'moved', 'alarm': False}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: immediate detection', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 34', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('boundary: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('boundary: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 1', {'pos': 'X', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 4500}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 4', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 6000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 7', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'in-position', 'alarm': False})], [('regression: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: immediate detection', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('sampled regression 24', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 79', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('boundary: already reverse while route locked', {'pos': 'R', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 12', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 15', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 3999}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 18', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: immediate detection', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('sampled regression 71', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 60', {'pos': 'X', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 0}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('boundary: already reverse while route locked', {'pos': 'R', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 23', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 26', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 1500}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 29', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'R', 'result': 'in-position', 'alarm': False})], [('regression: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: immediate detection', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 36', {'pos': 'X', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('boundary: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('boundary: normal point locked by a route', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 34', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 37', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 40', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 7000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: immediate detection', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('sampled regression 24', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: failed throw from normal', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 9000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 45', {'pos': 'X', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2999}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 48', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 3001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 51', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 0}, {'pos': 'R', 'result': 'moved', 'alarm': False})]]
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)

prompt:
A point that never regains detection is reported as moved.

A point command is answered as in-position when already detected in the commanded lie (even if locked or occupied). Otherwise route locking refuses (route-locked), then track locking refuses (track-locked); the alarm flag on refusals is raised only when the point has lost detection (X). A throw that fails to regain detection within limit_ms (inclusive; None means never) leaves the point X with alarm; otherwise it lies in the commanded position. detected_ms of 0 means detection was immediate.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    pos, cmd = x['pos'], x['cmd']
    if x['route_locked']:
        return {'pos': pos, 'result': 'route-locked', 'alarm': pos == 'X'}
    if x['occupied']:
        return {'pos': pos, 'result': 'track-locked', 'alarm': pos == 'X'}
    det = x['detected_ms']
    if pos == cmd:
        return {'pos': pos, 'result': 'in-position', 'alarm': False}
    if det is None or det > x['limit_ms']:
        return {'pos': 'X', 'result': 'no-detection', 'alarm': True}
    return {'pos': cmd, 'result': 'moved', 'alarm': False}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: already reverse while route locked', {'pos': 'R', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('regression: already normal under a train', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('sampled regression 26', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 1500}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('sampled regression 20', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': True, 'limit_ms': 6000, 'detected_ms': 1500}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('boundary: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 1', {'pos': 'X', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 4500}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 4', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 6000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 7', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'in-position', 'alarm': False})], [('regression: already normal under a train', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('sampled regression 80', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 6000, 'detected_ms': 0}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('sampled regression 70', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 3000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('boundary: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: immediate detection', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 12', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 15', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 3999}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 18', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: already reverse while route locked', {'pos': 'R', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('regression: already normal under a train', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('sampled regression 58', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 2999}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('sampled regression 26', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 1500}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('boundary: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 23', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 29', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 32', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 3999}, {'pos': 'R', 'result': 'moved', 'alarm': False})], [('regression: already normal under a train', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('sampled regression 20', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': True, 'limit_ms': 6000, 'detected_ms': 1500}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('sampled regression 72', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 3000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('boundary: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('boundary: normal point locked by a route', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 34', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 37', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 40', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 7000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: already reverse while route locked', {'pos': 'R', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('regression: already normal under a train', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('sampled regression 78', {'pos': 'N', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 0}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('sampled regression 28', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('boundary: failed throw from normal', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 9000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 45', {'pos': 'X', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2999}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 48', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 3001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 51', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 0}, {'pos': 'R', 'result': 'moved', 'alarm': False})]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    pos, cmd = x['pos'], x['cmd']
    if pos == cmd and not x['occupied']:
        return {'pos': pos, 'result': 'in-position', 'alarm': False}
    if x['route_locked']:
        return {'pos': pos, 'result': 'route-locked', 'alarm': pos == 'X'}
    if x['occupied']:
        return {'pos': pos, 'result': 'track-locked', 'alarm': pos == 'X'}
    det = x['detected_ms']
    if det is None or det > x['limit_ms']:
        return {'pos': 'X', 'result': 'no-detection', 'alarm': True}
    return {'pos': cmd, 'result': 'moved', 'alarm': False}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: already reverse while route locked', {'pos': 'R', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('regression: already normal under a train', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('sampled regression 26', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 1500}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('sampled regression 20', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': True, 'limit_ms': 6000, 'detected_ms': 1500}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('boundary: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 1', {'pos': 'X', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 4500}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 4', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 6000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 7', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'in-position', 'alarm': False})], [('regression: already normal under a train', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('sampled regression 80', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 6000, 'detected_ms': 0}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('sampled regression 70', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 3000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('boundary: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: immediate detection', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 12', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 15', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 3999}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 18', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: already reverse while route locked', {'pos': 'R', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('regression: already normal under a train', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('sampled regression 58', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 2999}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('sampled regression 26', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 1500}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('boundary: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 23', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 29', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 32', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 3999}, {'pos': 'R', 'result': 'moved', 'alarm': False})], [('regression: already normal under a train', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('sampled regression 20', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': True, 'limit_ms': 6000, 'detected_ms': 1500}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('sampled regression 72', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 3000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('boundary: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('boundary: normal point locked by a route', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 34', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 37', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 40', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 7000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: already reverse while route locked', {'pos': 'R', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('regression: already normal under a train', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('sampled regression 78', {'pos': 'N', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 0}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('sampled regression 28', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('boundary: failed throw from normal', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 9000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 45', {'pos': 'X', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2999}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 48', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 3001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 51', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 0}, {'pos': 'R', 'result': 'moved', 'alarm': False})]]
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)

prompt:
A command matching the current lie is refused because the point is locked.

A point command is answered as in-position when already detected in the commanded lie (even if locked or occupied). Otherwise route locking refuses (route-locked), then track locking refuses (track-locked); the alarm flag on refusals is raised only when the point has lost detection (X). A throw that fails to regain detection within limit_ms (inclusive; None means never) leaves the point X with alarm; otherwise it lies in the commanded position. detected_ms of 0 means detection was immediate.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    pos, cmd = x['pos'], x['cmd']
    if pos == cmd:
        return {'pos': pos, 'result': 'in-position', 'alarm': False}
    if x['route_locked']:
        return {'pos': pos, 'result': 'route-locked', 'alarm': pos == 'X'}
    if x['occupied']:
        return {'pos': pos, 'result': 'track-locked', 'alarm': pos == 'X'}
    det = x['detected_ms']
    if det is None or det > x['limit_ms']:
        return {'pos': pos, 'result': 'no-detection', 'alarm': True}
    return {'pos': cmd, 'result': 'moved', 'alarm': False}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('sampled regression 6', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 7000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('regression: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('boundary: immediate detection', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 1', {'pos': 'X', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 4500}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 4', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 6000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 7', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'in-position', 'alarm': False})], [('regression: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('regression: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 43', {'pos': 'X', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4500}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: immediate detection', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('boundary: already reverse while route locked', {'pos': 'R', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 12', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 15', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 3999}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 18', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: failed throw from normal', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 9000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('sampled regression 48', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 3001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 65', {'pos': 'X', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 4500}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: already reverse while route locked', {'pos': 'R', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('boundary: already normal under a train', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 23', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 26', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 1500}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 29', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'R', 'result': 'in-position', 'alarm': False})], [('regression: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('sampled regression 24', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('regression: failed throw from normal', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 9000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('boundary: normal point locked by a route', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 34', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 37', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 40', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 7000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('sampled regression 47', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 6000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('regression: failed throw from normal', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 9000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('regression: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 45', {'pos': 'X', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2999}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('sampled regression 48', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 3001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 51', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 0}, {'pos': 'R', 'result': 'moved', 'alarm': False})]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    pos, cmd = x['pos'], x['cmd']
    if pos == cmd:
        return {'pos': pos, 'result': 'in-position', 'alarm': False}
    if x['route_locked']:
        return {'pos': pos, 'result': 'route-locked', 'alarm': pos == 'X'}
    if x['occupied']:
        return {'pos': pos, 'result': 'track-locked', 'alarm': pos == 'X'}
    det = x['detected_ms']
    if det is None or det > x['limit_ms']:
        return {'pos': cmd, 'result': 'no-detection', 'alarm': True}
    return {'pos': cmd, 'result': 'moved', 'alarm': False}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('sampled regression 6', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 7000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('regression: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('boundary: immediate detection', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 1', {'pos': 'X', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 4500}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('control 4', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 6000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 7', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'in-position', 'alarm': False})], [('regression: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('regression: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 43', {'pos': 'X', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4500}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: immediate detection', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('boundary: already reverse while route locked', {'pos': 'R', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 12', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 15', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': True, 'limit_ms': 3000, 'detected_ms': 3999}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 18', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: failed throw from normal', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 9000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('sampled regression 48', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 3001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 65', {'pos': 'X', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 4500}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: already reverse while route locked', {'pos': 'R', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('boundary: already normal under a train', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 23', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 6000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('control 26', {'pos': 'N', 'cmd': 'N', 'route_locked': False, 'occupied': True, 'limit_ms': 4000, 'detected_ms': 1500}, {'pos': 'N', 'result': 'in-position', 'alarm': False}), ('control 29', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': None}, {'pos': 'R', 'result': 'in-position', 'alarm': False})], [('regression: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('sampled regression 24', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('regression: failed throw from normal', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 9000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: out of correspondence and locked', {'pos': 'X', 'cmd': 'N', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'X', 'result': 'route-locked', 'alarm': True}), ('boundary: normal point locked by a route', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False}), ('control 34', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 0}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('control 37', {'pos': 'R', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'in-position', 'alarm': False}), ('control 40', {'pos': 'N', 'cmd': 'R', 'route_locked': True, 'occupied': False, 'limit_ms': 6000, 'detected_ms': 7000}, {'pos': 'N', 'result': 'route-locked', 'alarm': False})], [('regression: never detected', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': None}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('sampled regression 47', {'pos': 'R', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 6000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('regression: failed throw from normal', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 9000}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('boundary: detection exactly at the limit', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4000}, {'pos': 'R', 'result': 'moved', 'alarm': False}), ('regression: detection one ms late', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 4001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 45', {'pos': 'X', 'cmd': 'N', 'route_locked': False, 'occupied': False, 'limit_ms': 4000, 'detected_ms': 2999}, {'pos': 'N', 'result': 'moved', 'alarm': False}), ('sampled regression 48', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 3001}, {'pos': 'X', 'result': 'no-detection', 'alarm': True}), ('control 51', {'pos': 'N', 'cmd': 'R', 'route_locked': False, 'occupied': False, 'limit_ms': 3000, 'detected_ms': 0}, {'pos': 'R', 'result': 'moved', 'alarm': False})]]
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)

prompt:
After a failed throw the point is still reported detected in a lie.

A point command is answered as in-position when already detected in the commanded lie (even if locked or occupied). Otherwise route locking refuses (route-locked), then track locking refuses (track-locked); the alarm flag on refusals is raised only when the point has lost detection (X). A throw that fails to regain detection within limit_ms (inclusive; None means never) leaves the point X with alarm; otherwise it lies in the commanded position. detected_ms of 0 means detection was immediate.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T = x['release_s']
    state = 'free'
    until = None
    approach = False
    out = []
    for t, kind in x['events']:
        if state == 'locked' and t > until:
            state = 'free'
        if kind == 'approach_occ':
            approach = True
        elif kind == 'approach_clear':
            approach = False
        elif kind == 'set' and state == 'free':
            state = 'set'
        elif kind == 'cancel' and state == 'set':
            if approach:
                state = 'locked'
                until = t + T
            else:
                state = 'free'
        elif kind == 'pass_signal':
            approach = False
            if state == 'set':
                state = 'in-use'
        elif kind == 'train_clear' and state == 'in-use':
            state = 'free'
        elif kind == 'query':
            out.append('locked-until:%d' % until if state == 'locked' else state)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: query at exactly the release time', {'release_s': 120, 'events': [[0, 'set'], [5, 'approach_occ'], [10, 'cancel'], [130, 'query']]}, ['free']), ('regression: re-set at exactly the release time', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [62, 'set'], [63, 'query']]}, ['set']), ('boundary: second lock after an earlier one', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [70, 'set'], [80, 'cancel'], [81, 'query']]}, ['locked-until:140']), ('boundary: train backs out of the approach', {'release_s': 60, 'events': [[0, 'approach_occ'], [1, 'approach_clear'], [2, 'set'], [3, 'cancel'], [4, 'query']]}, ['free']), ('boundary: cancel under a train', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'pass_signal'], [3, 'cancel'], [4, 'query'], [5, 'train_clear'], [6, 'query']]}, ['in-use', 'free']), ('control 1', {'release_s': 120, 'events': [[120, 'query'], [125, 'set'], [185, 'set'], [215, 'pass_signal'], [275, 'query'], [475, 'query']]}, ['free', 'in-use', 'in-use']), ('control 4', {'release_s': 60, 'events': [[30, 'query'], [60, 'query'], [120, 'query'], [180, 'cancel'], [240, 'query'], [245, 'approach_occ'], [445, 'query']]}, ['free', 'free', 'free', 'free', 'free']), ('control 7', {'release_s': 120, 'events': [[0, 'cancel'], [0, 'query'], [0, 'approach_occ'], [1, 'set'], [11, 'approach_clear'], [41, 'query'], [42, 'approach_occ'], [242, 'query']]}, ['free', 'set', 'set'])], [('regression: re-set at exactly the release time', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [62, 'set'], [63, 'query']]}, ['set']), ('boundary: second lock after an earlier one', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [70, 'set'], [80, 'cancel'], [81, 'query']]}, ['locked-until:140']), ('regression: query at exactly the release time', {'release_s': 120, 'events': [[0, 'set'], [5, 'approach_occ'], [10, 'cancel'], [130, 'query']]}, ['free']), ('boundary: train backs out of the approach', {'release_s': 60, 'events': [[0, 'approach_occ'], [1, 'approach_clear'], [2, 'set'], [3, 'cancel'], [4, 'query']]}, ['free']), ('boundary: cancel under a train', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'pass_signal'], [3, 'cancel'], [4, 'query'], [5, 'train_clear'], [6, 'query']]}, ['in-use', 'free']), ('control 12', {'release_s': 120, 'events': [[1, 'query'], [121, 'approach_clear'], [241, 'set'], [271, 'set'], [391, 'approach_occ'], [451, 'query']]}, ['free', 'set']), ('control 15', {'release_s': 60, 'events': [[5, 'set'], [6, 'query'], [6, 'cancel'], [36, 'set'], [46, 'query'], [106, 'approach_clear'], [226, 'query'], [227, 'query'], [237, 'query'], [267, 'set'], [327, 'set'], [327, 'query']]}, ['set', 'set', 'set', 'set', 'set', 'set']), ('control 18', {'release_s': 60, 'events': [[5, 'approach_occ'], [10, 'approach_clear'], [70, 'approach_clear'], [190, 'query'], [195, 'set'], [195, 'cancel'], [195, 'cancel'], [200, 'query'], [260, 'set'], [265, 'set'], [325, 'query']]}, ['free', 'free', 'set'])], [('regression: query at exactly the release time', {'release_s': 120, 'events': [[0, 'set'], [5, 'approach_occ'], [10, 'cancel'], [130, 'query']]}, ['free']), ('regression: re-set at exactly the release time', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [62, 'set'], [63, 'query']]}, ['set']), ('control 57', {'release_s': 120, 'events': [[0, 'train_clear'], [10, 'set'], [10, 'query'], [15, 'approach_occ'], [15, 'set'], [16, 'train_clear'], [46, 'query'], [56, 'cancel'], [66, 'set'], [126, 'set'], [186, 'set'], [196, 'train_clear'], [196, 'query']]}, ['set', 'set', 'set']), ('boundary: cancel under a train', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'pass_signal'], [3, 'cancel'], [4, 'query'], [5, 'train_clear'], [6, 'query']]}, ['in-use', 'free']), ('boundary: set with a train approaching', {'release_s': 60, 'events': [[0, 'approach_occ'], [1, 'set'], [2, 'query']]}, ['set']), ('control 23', {'release_s': 60, 'events': [[10, 'cancel'], [15, 'set'], [25, 'approach_occ'], [26, 'set'], [36, 'cancel'], [156, 'query']]}, ['free']), ('control 26', {'release_s': 60, 'events': [[1, 'approach_occ'], [6, 'set'], [66, 'set'], [66, 'cancel'], [96, 'query'], [106, 'approach_clear'], [136, 'query'], [141, 'approach_clear'], [151, 'approach_occ'], [211, 'train_clear'], [271, 'query']]}, ['locked-until:126', 'free', 'free']), ('control 29', {'release_s': 60, 'events': [[0, 'set'], [0, 'set'], [30, 'train_clear'], [40, 'set'], [40, 'query'], [100, 'cancel'], [110, 'approach_occ'], [170, 'query']]}, ['set', 'free'])], [('regression: re-set at exactly the release time', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [62, 'set'], [63, 'query']]}, ['set']), ('boundary: second lock after an earlier one', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [70, 'set'], [80, 'cancel'], [81, 'query']]}, ['locked-until:140']), ('regression: query at exactly the release time', {'release_s': 120, 'events': [[0, 'set'], [5, 'approach_occ'], [10, 'cancel'], [130, 'query']]}, ['free']), ('boundary: cancel with empty approach', {'release_s': 60, 'events': [[0, 'set'], [1, 'cancel'], [2, 'query']]}, ['free']), ('boundary: set attempted while locked', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [30, 'set'], [31, 'query']]}, ['locked-until:62']), ('control 34', {'release_s': 120, 'events': [[120, 'set'], [121, 'set'], [121, 'cancel'], [241, 'approach_occ'], [361, 'pass_signal'], [371, 'cancel'], [491, 'approach_occ'], [611, 'query']]}, ['free']), ('control 37', {'release_s': 60, 'events': [[60, 'query'], [61, 'train_clear'], [71, 'set'], [131, 'train_clear'], [131, 'pass_signal'], [136, 'approach_occ'], [196, 'set'], [197, 'cancel'], [202, 'set'], [262, 'train_clear'], [382, 'query'], [382, 'query']]}, ['free', 'free', 'free']), ('control 40', {'release_s': 120, 'events': [[0, 'query'], [30, 'cancel'], [90, 'approach_occ'], [100, 'set'], [130, 'query'], [135, 'approach_clear'], [255, 'train_clear'], [260, 'query'], [265, 'approach_occ'], [270, 'set'], [275, 'train_clear'], [305, 'cancel'], [365, 'query']]}, ['free', 'set', 'set', 'locked-until:425'])], [('regression: query at exactly the release time', {'release_s': 120, 'events': [[0, 'set'], [5, 'approach_occ'], [10, 'cancel'], [130, 'query']]}, ['free']), ('regression: re-set at exactly the release time', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [62, 'set'], [63, 'query']]}, ['set']), ('boundary: train backs out of the approach', {'release_s': 60, 'events': [[0, 'approach_occ'], [1, 'approach_clear'], [2, 'set'], [3, 'cancel'], [4, 'query']]}, ['free']), ('boundary: second lock after an earlier one', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [70, 'set'], [80, 'cancel'], [81, 'query']]}, ['locked-until:140']), ('boundary: cancel under a train', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'pass_signal'], [3, 'cancel'], [4, 'query'], [5, 'train_clear'], [6, 'query']]}, ['in-use', 'free']), ('control 45', {'release_s': 120, 'events': [[0, 'set'], [0, 'cancel'], [0, 'train_clear'], [0, 'approach_occ'], [1, 'approach_clear'], [6, 'approach_clear'], [126, 'query'], [136, 'set'], [141, 'train_clear'], [151, 'cancel'], [152, 'approach_clear'], [152, 'pass_signal'], [212, 'query']]}, ['free', 'free']), ('control 48', {'release_s': 60, 'events': [[120, 'set'], [121, 'train_clear'], [122, 'set'], [242, 'query'], [242, 'query'], [252, 'pass_signal'], [257, 'approach_occ'], [257, 'query']]}, ['set', 'set', 'in-use']), ('control 51', {'release_s': 60, 'events': [[120, 'pass_signal'], [120, 'cancel'], [125, 'approach_clear'], [126, 'cancel'], [136, 'cancel'], [256, 'approach_clear'], [316, 'pass_signal'], [376, 'query'], [377, 'query'], [387, 'cancel'], [387, 'query']]}, ['free', 'free', 'free'])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    T = x['release_s']
    state = 'free'
    until = None
    approach = False
    out = []
    for t, kind in x['events']:
        if kind == 'approach_occ':
            approach = True
        elif kind == 'approach_clear':
            approach = False
        elif kind == 'set' and state == 'free':
            state = 'set'
        elif kind == 'cancel' and state == 'set':
            if approach:
                state = 'locked'
                until = t + T
            else:
                state = 'free'
        elif kind == 'pass_signal':
            approach = False
            if state == 'set':
                state = 'in-use'
        elif kind == 'train_clear' and state == 'in-use':
            state = 'free'
        elif kind == 'query':
            if state == 'locked' and t >= until:
                state = 'free'
            out.append('locked-until:%d' % until if state == 'locked' else state)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: query at exactly the release time', {'release_s': 120, 'events': [[0, 'set'], [5, 'approach_occ'], [10, 'cancel'], [130, 'query']]}, ['free']), ('regression: re-set at exactly the release time', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [62, 'set'], [63, 'query']]}, ['set']), ('boundary: second lock after an earlier one', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [70, 'set'], [80, 'cancel'], [81, 'query']]}, ['locked-until:140']), ('boundary: train backs out of the approach', {'release_s': 60, 'events': [[0, 'approach_occ'], [1, 'approach_clear'], [2, 'set'], [3, 'cancel'], [4, 'query']]}, ['free']), ('boundary: cancel under a train', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'pass_signal'], [3, 'cancel'], [4, 'query'], [5, 'train_clear'], [6, 'query']]}, ['in-use', 'free']), ('control 1', {'release_s': 120, 'events': [[120, 'query'], [125, 'set'], [185, 'set'], [215, 'pass_signal'], [275, 'query'], [475, 'query']]}, ['free', 'in-use', 'in-use']), ('control 4', {'release_s': 60, 'events': [[30, 'query'], [60, 'query'], [120, 'query'], [180, 'cancel'], [240, 'query'], [245, 'approach_occ'], [445, 'query']]}, ['free', 'free', 'free', 'free', 'free']), ('control 7', {'release_s': 120, 'events': [[0, 'cancel'], [0, 'query'], [0, 'approach_occ'], [1, 'set'], [11, 'approach_clear'], [41, 'query'], [42, 'approach_occ'], [242, 'query']]}, ['free', 'set', 'set'])], [('regression: re-set at exactly the release time', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [62, 'set'], [63, 'query']]}, ['set']), ('boundary: second lock after an earlier one', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [70, 'set'], [80, 'cancel'], [81, 'query']]}, ['locked-until:140']), ('regression: query at exactly the release time', {'release_s': 120, 'events': [[0, 'set'], [5, 'approach_occ'], [10, 'cancel'], [130, 'query']]}, ['free']), ('boundary: train backs out of the approach', {'release_s': 60, 'events': [[0, 'approach_occ'], [1, 'approach_clear'], [2, 'set'], [3, 'cancel'], [4, 'query']]}, ['free']), ('boundary: cancel under a train', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'pass_signal'], [3, 'cancel'], [4, 'query'], [5, 'train_clear'], [6, 'query']]}, ['in-use', 'free']), ('control 12', {'release_s': 120, 'events': [[1, 'query'], [121, 'approach_clear'], [241, 'set'], [271, 'set'], [391, 'approach_occ'], [451, 'query']]}, ['free', 'set']), ('control 15', {'release_s': 60, 'events': [[5, 'set'], [6, 'query'], [6, 'cancel'], [36, 'set'], [46, 'query'], [106, 'approach_clear'], [226, 'query'], [227, 'query'], [237, 'query'], [267, 'set'], [327, 'set'], [327, 'query']]}, ['set', 'set', 'set', 'set', 'set', 'set']), ('control 18', {'release_s': 60, 'events': [[5, 'approach_occ'], [10, 'approach_clear'], [70, 'approach_clear'], [190, 'query'], [195, 'set'], [195, 'cancel'], [195, 'cancel'], [200, 'query'], [260, 'set'], [265, 'set'], [325, 'query']]}, ['free', 'free', 'set'])], [('regression: query at exactly the release time', {'release_s': 120, 'events': [[0, 'set'], [5, 'approach_occ'], [10, 'cancel'], [130, 'query']]}, ['free']), ('regression: re-set at exactly the release time', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [62, 'set'], [63, 'query']]}, ['set']), ('control 57', {'release_s': 120, 'events': [[0, 'train_clear'], [10, 'set'], [10, 'query'], [15, 'approach_occ'], [15, 'set'], [16, 'train_clear'], [46, 'query'], [56, 'cancel'], [66, 'set'], [126, 'set'], [186, 'set'], [196, 'train_clear'], [196, 'query']]}, ['set', 'set', 'set']), ('boundary: cancel under a train', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'pass_signal'], [3, 'cancel'], [4, 'query'], [5, 'train_clear'], [6, 'query']]}, ['in-use', 'free']), ('boundary: set with a train approaching', {'release_s': 60, 'events': [[0, 'approach_occ'], [1, 'set'], [2, 'query']]}, ['set']), ('control 23', {'release_s': 60, 'events': [[10, 'cancel'], [15, 'set'], [25, 'approach_occ'], [26, 'set'], [36, 'cancel'], [156, 'query']]}, ['free']), ('control 26', {'release_s': 60, 'events': [[1, 'approach_occ'], [6, 'set'], [66, 'set'], [66, 'cancel'], [96, 'query'], [106, 'approach_clear'], [136, 'query'], [141, 'approach_clear'], [151, 'approach_occ'], [211, 'train_clear'], [271, 'query']]}, ['locked-until:126', 'free', 'free']), ('control 29', {'release_s': 60, 'events': [[0, 'set'], [0, 'set'], [30, 'train_clear'], [40, 'set'], [40, 'query'], [100, 'cancel'], [110, 'approach_occ'], [170, 'query']]}, ['set', 'free'])], [('regression: re-set at exactly the release time', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [62, 'set'], [63, 'query']]}, ['set']), ('boundary: second lock after an earlier one', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [70, 'set'], [80, 'cancel'], [81, 'query']]}, ['locked-until:140']), ('regression: query at exactly the release time', {'release_s': 120, 'events': [[0, 'set'], [5, 'approach_occ'], [10, 'cancel'], [130, 'query']]}, ['free']), ('boundary: cancel with empty approach', {'release_s': 60, 'events': [[0, 'set'], [1, 'cancel'], [2, 'query']]}, ['free']), ('boundary: set attempted while locked', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [30, 'set'], [31, 'query']]}, ['locked-until:62']), ('control 34', {'release_s': 120, 'events': [[120, 'set'], [121, 'set'], [121, 'cancel'], [241, 'approach_occ'], [361, 'pass_signal'], [371, 'cancel'], [491, 'approach_occ'], [611, 'query']]}, ['free']), ('control 37', {'release_s': 60, 'events': [[60, 'query'], [61, 'train_clear'], [71, 'set'], [131, 'train_clear'], [131, 'pass_signal'], [136, 'approach_occ'], [196, 'set'], [197, 'cancel'], [202, 'set'], [262, 'train_clear'], [382, 'query'], [382, 'query']]}, ['free', 'free', 'free']), ('control 40', {'release_s': 120, 'events': [[0, 'query'], [30, 'cancel'], [90, 'approach_occ'], [100, 'set'], [130, 'query'], [135, 'approach_clear'], [255, 'train_clear'], [260, 'query'], [265, 'approach_occ'], [270, 'set'], [275, 'train_clear'], [305, 'cancel'], [365, 'query']]}, ['free', 'set', 'set', 'locked-until:425'])], [('regression: query at exactly the release time', {'release_s': 120, 'events': [[0, 'set'], [5, 'approach_occ'], [10, 'cancel'], [130, 'query']]}, ['free']), ('regression: re-set at exactly the release time', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [62, 'set'], [63, 'query']]}, ['set']), ('boundary: train backs out of the approach', {'release_s': 60, 'events': [[0, 'approach_occ'], [1, 'approach_clear'], [2, 'set'], [3, 'cancel'], [4, 'query']]}, ['free']), ('boundary: second lock after an earlier one', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'cancel'], [70, 'set'], [80, 'cancel'], [81, 'query']]}, ['locked-until:140']), ('boundary: cancel under a train', {'release_s': 60, 'events': [[0, 'set'], [1, 'approach_occ'], [2, 'pass_signal'], [3, 'cancel'], [4, 'query'], [5, 'train_clear'], [6, 'query']]}, ['in-use', 'free']), ('control 45', {'release_s': 120, 'events': [[0, 'set'], [0, 'cancel'], [0, 'train_clear'], [0, 'approach_occ'], [1, 'approach_clear'], [6, 'approach_clear'], [126, 'query'], [136, 'set'], [141, 'train_clear'], [151, 'cancel'], [152, 'approach_clear'], [152, 'pass_signal'], [212, 'query']]}, ['free', 'free']), ('control 48', {'release_s': 60, 'events': [[120, 'set'], [121, 'train_clear'], [122, 'set'], [242, 'query'], [242, 'query'], [252, 'pass_signal'], [257, 'approach_occ'], [257, 'query']]}, ['set', 'set', 'in-use']), ('control 51', {'release_s': 60, 'events': [[120, 'pass_signal'], [120, 'cancel'], [125, 'approach_clear'], [126, 'cancel'], [136, 'cancel'], [256, 'approach_clear'], [316, 'pass_signal'], [376, 'query'], [377, 'query'], [387, 'cancel'], [387, 'query']]}, ['free', 'free', 'free'])]]
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)

prompt:
An approach-locked route stays locked at the instant its timer expires.

A route can be set only when free. pass_signal moves a set route to in-use; train_clear frees an in-use route. Cancelling a set route frees it at once unless a train is in the approach section, in which case it is approach-locked until cancel time + release_s (released when an event time reaches the deadline). approach_occ/approach_clear track the approach section. query appends set, free, in-use or locked-until:<t>.

split: open-access