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

N = 1
observations = []
def solve(d):
    rows=d['rows']; blocked=set(d['disabled']); old=set(d['selected'])
    anchor=d['anchor'] if d['anchor'] in rows else d['focus']
    a=rows.index(anchor); b=rows.index(d['target'])
    span=rows[min(a,b):max(a,b)+1]
    eligible=[x for x in span if x in blocked]
    kept=old if d['additive'] else set()
    selected=set(eligible)|kept
    ordered=[x for x in rows if x in selected]
    focus=d['target']
    next_anchor=anchor
    branch=[x for x in d['branch'] if x in rows and x not in blocked]
    covered=bool(branch) and all(x in selected for x in branch)
    return [ordered,focus,next_anchor,covered]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2'], 'c2', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'c2', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': []}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 2: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'c3', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 3: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'c4', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 4: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'c5', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 5: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'c6', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])]}
for label, data, expected in cases[N]:
    check(label, solve(data), 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(d):
    rows=d['rows']; blocked=set(d['disabled']); old=set(d['selected'])
    anchor=d['anchor'] if d['anchor'] in rows else d['focus']
    a=rows.index(anchor); b=rows.index(d['target'])
    span=rows[min(a,b):max(a,b)+1]
    eligible=[x for x in span if x != rows[0]]
    kept=old if d['additive'] else set()
    selected=set(eligible)|kept
    ordered=[x for x in rows if x in selected]
    focus=d['target']
    next_anchor=anchor
    branch=[x for x in d['branch'] if x in rows and x not in blocked]
    covered=bool(branch) and all(x in selected for x in branch)
    return [ordered,focus,next_anchor,covered]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2'], 'c2', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'c2', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': []}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 2: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'c3', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 3: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'c4', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 4: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'c5', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 5: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'c6', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])]}
for label, data, expected in cases[N]:
    check(label, solve(data), 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:
Disabled rows enter a range produces the wrong hierarchical widget state in a regression fixture.

Selectable rows are the ordered visible preorder supplied in rows; disabled rows cannot be selected. A hidden anchor falls back to focus. Preserve outside selections only for additive ranges. Report focus, anchor, ordered selection, and branch coverage.

split: open-access


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

N = 1
observations = []
def solve(d):
    rows=d['rows']; blocked=set(d['disabled']); old=set(d['selected'])
    anchor=d['anchor'] if d['anchor'] in rows else d['focus']
    a=rows.index(anchor); b=rows.index(d['target'])
    span=rows[min(a,b):max(a,b)+1]
    eligible=[x for x in span if x not in blocked]
    kept=old
    selected=set(eligible)|kept
    ordered=[x for x in rows if x in selected]
    focus=d['target']
    next_anchor=anchor
    branch=[x for x in d['branch'] if x in rows and x not in blocked]
    covered=bool(branch) and all(x in selected for x in branch)
    return [ordered,focus,next_anchor,covered]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2'], 'c2', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'c2', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': []}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 2: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'c3', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 3: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'c4', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 4: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'c5', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 5: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'c6', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])]}
for label, data, expected in cases[N]:
    check(label, solve(data), 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(d):
    rows=d['rows']; blocked=set(d['disabled']); old=set(d['selected'])
    anchor=d['anchor'] if d['anchor'] in rows else d['focus']
    a=rows.index(anchor); b=rows.index(d['target'])
    span=rows[min(a,b):max(a,b)+1]
    eligible=[x for x in span if x not in blocked]
    kept=set()
    selected=set(eligible)|kept
    ordered=[x for x in rows if x in selected]
    focus=d['target']
    next_anchor=anchor
    branch=[x for x in d['branch'] if x in rows and x not in blocked]
    covered=bool(branch) and all(x in selected for x in branch)
    return [ordered,focus,next_anchor,covered]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2'], 'c2', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'c2', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': []}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 2: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'c3', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 3: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'c4', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 4: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'c5', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 5: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'c6', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])]}
for label, data, expected in cases[N]:
    check(label, solve(data), 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:
Additive selection replaces unrelated selected branches produces the wrong hierarchical widget state in a regression fixture.

Selectable rows are the ordered visible preorder supplied in rows; disabled rows cannot be selected. A hidden anchor falls back to focus. Preserve outside selections only for additive ranges. Report focus, anchor, ordered selection, and branch coverage.

split: open-access


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

N = 1
observations = []
def solve(d):
    rows=d['rows']; blocked=set(d['disabled']); old=set(d['selected'])
    anchor=d['anchor'] if d['anchor'] in rows else d['focus']
    a=rows.index(anchor); b=rows.index(d['target'])
    span=rows[min(a,b):max(a,b)+1]
    eligible=[x for x in span if x not in blocked]
    kept=old if d['additive'] else set()
    selected=set(eligible)&kept
    ordered=[x for x in rows if x in selected]
    focus=d['target']
    next_anchor=anchor
    branch=[x for x in d['branch'] if x in rows and x not in blocked]
    covered=bool(branch) and all(x in selected for x in branch)
    return [ordered,focus,next_anchor,covered]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2'], 'c2', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'c2', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': []}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 2: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'c3', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 3: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'c4', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 4: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'c5', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 5: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'c6', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])]}
for label, data, expected in cases[N]:
    check(label, solve(data), 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(d):
    rows=d['rows']; blocked=set(d['disabled']); old=set(d['selected'])
    anchor=d['anchor'] if d['anchor'] in rows else d['focus']
    a=rows.index(anchor); b=rows.index(d['target'])
    span=rows[min(a,b):max(a,b)+1]
    eligible=[x for x in span if x not in blocked]
    kept=old if d['additive'] else set()
    selected=set(eligible)-kept
    ordered=[x for x in rows if x in selected]
    focus=d['target']
    next_anchor=anchor
    branch=[x for x in d['branch'] if x in rows and x not in blocked]
    covered=bool(branch) and all(x in selected for x in branch)
    return [ordered,focus,next_anchor,covered]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2'], 'c2', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'c2', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': []}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 2: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'c3', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 3: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'c4', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 4: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'c5', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 5: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'c6', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])]}
for label, data, expected in cases[N]:
    check(label, solve(data), 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:
Range union toggles previously selected descendants produces the wrong hierarchical widget state in a regression fixture.

Selectable rows are the ordered visible preorder supplied in rows; disabled rows cannot be selected. A hidden anchor falls back to focus. Preserve outside selections only for additive ranges. Report focus, anchor, ordered selection, and branch coverage.

split: open-access


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

N = 1
observations = []
def solve(d):
    rows=d['rows']; blocked=set(d['disabled']); old=set(d['selected'])
    anchor=d['anchor'] if d['anchor'] in rows else d['focus']
    a=rows.index(anchor); b=rows.index(d['target'])
    span=rows[min(a,b):max(a,b)+1]
    eligible=[x for x in span if x not in blocked]
    kept=old if d['additive'] else set()
    selected=set(eligible)|kept
    ordered=sorted(selected)
    focus=d['target']
    next_anchor=anchor
    branch=[x for x in d['branch'] if x in rows and x not in blocked]
    covered=bool(branch) and all(x in selected for x in branch)
    return [ordered,focus,next_anchor,covered]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2'], 'c2', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'c2', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': []}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 2: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'c3', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 3: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'c4', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 4: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'c5', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 5: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'c6', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])]}
for label, data, expected in cases[N]:
    check(label, solve(data), 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(d):
    rows=d['rows']; blocked=set(d['disabled']); old=set(d['selected'])
    anchor=d['anchor'] if d['anchor'] in rows else d['focus']
    a=rows.index(anchor); b=rows.index(d['target'])
    span=rows[min(a,b):max(a,b)+1]
    eligible=[x for x in span if x not in blocked]
    kept=old if d['additive'] else set()
    selected=set(eligible)|kept
    ordered=[x for x in reversed(rows) if x in selected]
    focus=d['target']
    next_anchor=anchor
    branch=[x for x in d['branch'] if x in rows and x not in blocked]
    covered=bool(branch) and all(x in selected for x in branch)
    return [ordered,focus,next_anchor,covered]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = {1: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2'], 'c2', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'a'], 'c2', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': []}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c2', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2'], 'c2', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 2: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'a'], 'c3', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c3', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3'], 'c3', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 3: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'a'], 'c4', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c4', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4'], 'c4', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 4: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'a'], 'c5', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c5', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5'], 'c5', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])], 5: [('forward', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', True]), ('reverse', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'a', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'z', 'a', True]), ('additive', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': True, 'branch': ['z', 'c0']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'c6', 'z', True]), ('hidden anchor', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'hidden', 'focus': 'c0', 'target': 'z', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'z', 'c0', True]), ('empty branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': []}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('partial branch', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c6', 'additive': False, 'branch': ['a', 'z']}, [['z', 'c0', 'c2', 'c3', 'c4', 'c5', 'c6'], 'c6', 'z', False]), ('singleton', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'c0', 'focus': 'c0', 'target': 'c0', 'additive': False, 'branch': ['z', 'c0']}, [['c0'], 'c0', 'c0', False]), ('disabled target', {'rows': ['r', 'z', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'a'], 'disabled': ['c1'], 'selected': ['a'], 'anchor': 'z', 'focus': 'c0', 'target': 'c1', 'additive': False, 'branch': ['z', 'c0']}, [['z', 'c0'], 'c1', 'z', True])]}
for label, data, expected in cases[N]:
    check(label, solve(data), 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:
Selection output loses visible preorder produces the wrong hierarchical widget state in a regression fixture.

Selectable rows are the ordered visible preorder supplied in rows; disabled rows cannot be selected. A hidden anchor falls back to focus. Preserve outside selections only for additive ranges. Report focus, anchor, ordered selection, and branch coverage.

split: open-access