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

N = 1
observations = []
def solve(d):
    try:
        events,gap=d
        out=[]
        for key in sorted(set(k for k,t,i in events)):
            rows=sorted((t,i) for k,t,i in events if k==key)
            start=last=None; ids=[]
            for time,ident in rows:
                if ids and time-last>=gap:
                    out.append([key,start,last,ids]); ids=[]
                if not ids: start=time
                ids.append(ident); last=time
            if ids: out.append([key,start,last,ids])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('bridge chain', solve([[['a', 1, 10], ['a', 3, 11], ['a', 5, 12]], 2]), [['a', 1, 5, [10, 11, 12]]])
    check('arrival order', solve([[['a', 3, 10], ['a', 1, 11]], 2]), [['a', 1, 3, [11, 10]]])
    check('key separation', solve([[['a', 1, 10], ['b', 1, 11]], 2]), [['a', 1, 1, [10]], ['b', 1, 1, [11]]])
    check('separate sessions', solve([[['a', 1, 10], ['a', 6, 11]], 2]), [['a', 1, 1, [10]], ['a', 6, 6, [11]]])
    check('equal timestamp', solve([[['a', 1, 11], ['a', 1, 10]], 0]), [['a', 1, 1, [10, 11]]])
    check('single event', solve([[['a', 1, 10]], 2]), [['a', 1, 1, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 2:
    check('bridge chain', solve([[['a', 2, 10], ['a', 4, 11], ['a', 6, 12]], 2]), [['a', 2, 6, [10, 11, 12]]])
    check('arrival order', solve([[['a', 4, 10], ['a', 2, 11]], 2]), [['a', 2, 4, [11, 10]]])
    check('key separation', solve([[['a', 2, 10], ['b', 2, 11]], 2]), [['a', 2, 2, [10]], ['b', 2, 2, [11]]])
    check('separate sessions', solve([[['a', 2, 10], ['a', 7, 11]], 2]), [['a', 2, 2, [10]], ['a', 7, 7, [11]]])
    check('equal timestamp', solve([[['a', 2, 11], ['a', 2, 10]], 0]), [['a', 2, 2, [10, 11]]])
    check('single event', solve([[['a', 2, 10]], 2]), [['a', 2, 2, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 3:
    check('bridge chain', solve([[['a', 3, 10], ['a', 5, 11], ['a', 7, 12]], 2]), [['a', 3, 7, [10, 11, 12]]])
    check('arrival order', solve([[['a', 5, 10], ['a', 3, 11]], 2]), [['a', 3, 5, [11, 10]]])
    check('key separation', solve([[['a', 3, 10], ['b', 3, 11]], 2]), [['a', 3, 3, [10]], ['b', 3, 3, [11]]])
    check('separate sessions', solve([[['a', 3, 10], ['a', 8, 11]], 2]), [['a', 3, 3, [10]], ['a', 8, 8, [11]]])
    check('equal timestamp', solve([[['a', 3, 11], ['a', 3, 10]], 0]), [['a', 3, 3, [10, 11]]])
    check('single event', solve([[['a', 3, 10]], 2]), [['a', 3, 3, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 4:
    check('bridge chain', solve([[['a', 4, 10], ['a', 6, 11], ['a', 8, 12]], 2]), [['a', 4, 8, [10, 11, 12]]])
    check('arrival order', solve([[['a', 6, 10], ['a', 4, 11]], 2]), [['a', 4, 6, [11, 10]]])
    check('key separation', solve([[['a', 4, 10], ['b', 4, 11]], 2]), [['a', 4, 4, [10]], ['b', 4, 4, [11]]])
    check('separate sessions', solve([[['a', 4, 10], ['a', 9, 11]], 2]), [['a', 4, 4, [10]], ['a', 9, 9, [11]]])
    check('equal timestamp', solve([[['a', 4, 11], ['a', 4, 10]], 0]), [['a', 4, 4, [10, 11]]])
    check('single event', solve([[['a', 4, 10]], 2]), [['a', 4, 4, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 5:
    check('bridge chain', solve([[['a', 5, 10], ['a', 7, 11], ['a', 9, 12]], 2]), [['a', 5, 9, [10, 11, 12]]])
    check('arrival order', solve([[['a', 7, 10], ['a', 5, 11]], 2]), [['a', 5, 7, [11, 10]]])
    check('key separation', solve([[['a', 5, 10], ['b', 5, 11]], 2]), [['a', 5, 5, [10]], ['b', 5, 5, [11]]])
    check('separate sessions', solve([[['a', 5, 10], ['a', 10, 11]], 2]), [['a', 5, 5, [10]], ['a', 10, 10, [11]]])
    check('equal timestamp', solve([[['a', 5, 11], ['a', 5, 10]], 0]), [['a', 5, 5, [10, 11]]])
    check('single event', solve([[['a', 5, 10]], 2]), [['a', 5, 5, [10]]])
    check('empty stream', solve([[], 2]), [])
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):
    try:
        events,gap=d
        out=[]
        for key in sorted(set(k for k,t,i in events)):
            rows=sorted((t,i) for k,t,i in events if k==key)
            start=last=None; ids=[]
            for time,ident in rows:
                if ids and time-last>gap-1:
                    out.append([key,start,last,ids]); ids=[]
                if not ids: start=time
                ids.append(ident); last=time
            if ids: out.append([key,start,last,ids])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('bridge chain', solve([[['a', 1, 10], ['a', 3, 11], ['a', 5, 12]], 2]), [['a', 1, 5, [10, 11, 12]]])
    check('arrival order', solve([[['a', 3, 10], ['a', 1, 11]], 2]), [['a', 1, 3, [11, 10]]])
    check('key separation', solve([[['a', 1, 10], ['b', 1, 11]], 2]), [['a', 1, 1, [10]], ['b', 1, 1, [11]]])
    check('separate sessions', solve([[['a', 1, 10], ['a', 6, 11]], 2]), [['a', 1, 1, [10]], ['a', 6, 6, [11]]])
    check('equal timestamp', solve([[['a', 1, 11], ['a', 1, 10]], 0]), [['a', 1, 1, [10, 11]]])
    check('single event', solve([[['a', 1, 10]], 2]), [['a', 1, 1, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 2:
    check('bridge chain', solve([[['a', 2, 10], ['a', 4, 11], ['a', 6, 12]], 2]), [['a', 2, 6, [10, 11, 12]]])
    check('arrival order', solve([[['a', 4, 10], ['a', 2, 11]], 2]), [['a', 2, 4, [11, 10]]])
    check('key separation', solve([[['a', 2, 10], ['b', 2, 11]], 2]), [['a', 2, 2, [10]], ['b', 2, 2, [11]]])
    check('separate sessions', solve([[['a', 2, 10], ['a', 7, 11]], 2]), [['a', 2, 2, [10]], ['a', 7, 7, [11]]])
    check('equal timestamp', solve([[['a', 2, 11], ['a', 2, 10]], 0]), [['a', 2, 2, [10, 11]]])
    check('single event', solve([[['a', 2, 10]], 2]), [['a', 2, 2, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 3:
    check('bridge chain', solve([[['a', 3, 10], ['a', 5, 11], ['a', 7, 12]], 2]), [['a', 3, 7, [10, 11, 12]]])
    check('arrival order', solve([[['a', 5, 10], ['a', 3, 11]], 2]), [['a', 3, 5, [11, 10]]])
    check('key separation', solve([[['a', 3, 10], ['b', 3, 11]], 2]), [['a', 3, 3, [10]], ['b', 3, 3, [11]]])
    check('separate sessions', solve([[['a', 3, 10], ['a', 8, 11]], 2]), [['a', 3, 3, [10]], ['a', 8, 8, [11]]])
    check('equal timestamp', solve([[['a', 3, 11], ['a', 3, 10]], 0]), [['a', 3, 3, [10, 11]]])
    check('single event', solve([[['a', 3, 10]], 2]), [['a', 3, 3, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 4:
    check('bridge chain', solve([[['a', 4, 10], ['a', 6, 11], ['a', 8, 12]], 2]), [['a', 4, 8, [10, 11, 12]]])
    check('arrival order', solve([[['a', 6, 10], ['a', 4, 11]], 2]), [['a', 4, 6, [11, 10]]])
    check('key separation', solve([[['a', 4, 10], ['b', 4, 11]], 2]), [['a', 4, 4, [10]], ['b', 4, 4, [11]]])
    check('separate sessions', solve([[['a', 4, 10], ['a', 9, 11]], 2]), [['a', 4, 4, [10]], ['a', 9, 9, [11]]])
    check('equal timestamp', solve([[['a', 4, 11], ['a', 4, 10]], 0]), [['a', 4, 4, [10, 11]]])
    check('single event', solve([[['a', 4, 10]], 2]), [['a', 4, 4, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 5:
    check('bridge chain', solve([[['a', 5, 10], ['a', 7, 11], ['a', 9, 12]], 2]), [['a', 5, 9, [10, 11, 12]]])
    check('arrival order', solve([[['a', 7, 10], ['a', 5, 11]], 2]), [['a', 5, 7, [11, 10]]])
    check('key separation', solve([[['a', 5, 10], ['b', 5, 11]], 2]), [['a', 5, 5, [10]], ['b', 5, 5, [11]]])
    check('separate sessions', solve([[['a', 5, 10], ['a', 10, 11]], 2]), [['a', 5, 5, [10]], ['a', 10, 10, [11]]])
    check('equal timestamp', solve([[['a', 5, 11], ['a', 5, 10]], 0]), [['a', 5, 5, [10, 11]]])
    check('single event', solve([[['a', 5, 10]], 2]), [['a', 5, 5, [10]]])
    check('empty stream', solve([[], 2]), [])
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:
Session grouping splits events separated by exactly the allowed gap.

Group [key,time,id] events into sessions independently by key. Sort each key by (time,id); consecutive gaps <=gap belong to one transitive session. Emit [key,first-time,last-time,ordered-ids] ordered by key and session time. An intervening bridge may join otherwise distant endpoints.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        events,gap=d
        out=[]
        for key in sorted(set(k for k,t,i in events)):
            rows=sorted((t,i) for k,t,i in events if True)
            start=last=None; ids=[]
            for time,ident in rows:
                if ids and time-last>gap:
                    out.append([key,start,last,ids]); ids=[]
                if not ids: start=time
                ids.append(ident); last=time
            if ids: out.append([key,start,last,ids])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('bridge chain', solve([[['a', 1, 10], ['a', 3, 11], ['a', 5, 12]], 2]), [['a', 1, 5, [10, 11, 12]]])
    check('arrival order', solve([[['a', 3, 10], ['a', 1, 11]], 2]), [['a', 1, 3, [11, 10]]])
    check('key separation', solve([[['a', 1, 10], ['b', 1, 11]], 2]), [['a', 1, 1, [10]], ['b', 1, 1, [11]]])
    check('separate sessions', solve([[['a', 1, 10], ['a', 6, 11]], 2]), [['a', 1, 1, [10]], ['a', 6, 6, [11]]])
    check('equal timestamp', solve([[['a', 1, 11], ['a', 1, 10]], 0]), [['a', 1, 1, [10, 11]]])
    check('single event', solve([[['a', 1, 10]], 2]), [['a', 1, 1, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 2:
    check('bridge chain', solve([[['a', 2, 10], ['a', 4, 11], ['a', 6, 12]], 2]), [['a', 2, 6, [10, 11, 12]]])
    check('arrival order', solve([[['a', 4, 10], ['a', 2, 11]], 2]), [['a', 2, 4, [11, 10]]])
    check('key separation', solve([[['a', 2, 10], ['b', 2, 11]], 2]), [['a', 2, 2, [10]], ['b', 2, 2, [11]]])
    check('separate sessions', solve([[['a', 2, 10], ['a', 7, 11]], 2]), [['a', 2, 2, [10]], ['a', 7, 7, [11]]])
    check('equal timestamp', solve([[['a', 2, 11], ['a', 2, 10]], 0]), [['a', 2, 2, [10, 11]]])
    check('single event', solve([[['a', 2, 10]], 2]), [['a', 2, 2, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 3:
    check('bridge chain', solve([[['a', 3, 10], ['a', 5, 11], ['a', 7, 12]], 2]), [['a', 3, 7, [10, 11, 12]]])
    check('arrival order', solve([[['a', 5, 10], ['a', 3, 11]], 2]), [['a', 3, 5, [11, 10]]])
    check('key separation', solve([[['a', 3, 10], ['b', 3, 11]], 2]), [['a', 3, 3, [10]], ['b', 3, 3, [11]]])
    check('separate sessions', solve([[['a', 3, 10], ['a', 8, 11]], 2]), [['a', 3, 3, [10]], ['a', 8, 8, [11]]])
    check('equal timestamp', solve([[['a', 3, 11], ['a', 3, 10]], 0]), [['a', 3, 3, [10, 11]]])
    check('single event', solve([[['a', 3, 10]], 2]), [['a', 3, 3, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 4:
    check('bridge chain', solve([[['a', 4, 10], ['a', 6, 11], ['a', 8, 12]], 2]), [['a', 4, 8, [10, 11, 12]]])
    check('arrival order', solve([[['a', 6, 10], ['a', 4, 11]], 2]), [['a', 4, 6, [11, 10]]])
    check('key separation', solve([[['a', 4, 10], ['b', 4, 11]], 2]), [['a', 4, 4, [10]], ['b', 4, 4, [11]]])
    check('separate sessions', solve([[['a', 4, 10], ['a', 9, 11]], 2]), [['a', 4, 4, [10]], ['a', 9, 9, [11]]])
    check('equal timestamp', solve([[['a', 4, 11], ['a', 4, 10]], 0]), [['a', 4, 4, [10, 11]]])
    check('single event', solve([[['a', 4, 10]], 2]), [['a', 4, 4, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 5:
    check('bridge chain', solve([[['a', 5, 10], ['a', 7, 11], ['a', 9, 12]], 2]), [['a', 5, 9, [10, 11, 12]]])
    check('arrival order', solve([[['a', 7, 10], ['a', 5, 11]], 2]), [['a', 5, 7, [11, 10]]])
    check('key separation', solve([[['a', 5, 10], ['b', 5, 11]], 2]), [['a', 5, 5, [10]], ['b', 5, 5, [11]]])
    check('separate sessions', solve([[['a', 5, 10], ['a', 10, 11]], 2]), [['a', 5, 5, [10]], ['a', 10, 10, [11]]])
    check('equal timestamp', solve([[['a', 5, 11], ['a', 5, 10]], 0]), [['a', 5, 5, [10, 11]]])
    check('single event', solve([[['a', 5, 10]], 2]), [['a', 5, 5, [10]]])
    check('empty stream', solve([[], 2]), [])
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):
    try:
        events,gap=d
        out=[]
        for key in sorted(set(k for k,t,i in events)):
            rows=sorted((t,i) for k,t,i in events if k<=key)
            start=last=None; ids=[]
            for time,ident in rows:
                if ids and time-last>gap:
                    out.append([key,start,last,ids]); ids=[]
                if not ids: start=time
                ids.append(ident); last=time
            if ids: out.append([key,start,last,ids])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('bridge chain', solve([[['a', 1, 10], ['a', 3, 11], ['a', 5, 12]], 2]), [['a', 1, 5, [10, 11, 12]]])
    check('arrival order', solve([[['a', 3, 10], ['a', 1, 11]], 2]), [['a', 1, 3, [11, 10]]])
    check('key separation', solve([[['a', 1, 10], ['b', 1, 11]], 2]), [['a', 1, 1, [10]], ['b', 1, 1, [11]]])
    check('separate sessions', solve([[['a', 1, 10], ['a', 6, 11]], 2]), [['a', 1, 1, [10]], ['a', 6, 6, [11]]])
    check('equal timestamp', solve([[['a', 1, 11], ['a', 1, 10]], 0]), [['a', 1, 1, [10, 11]]])
    check('single event', solve([[['a', 1, 10]], 2]), [['a', 1, 1, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 2:
    check('bridge chain', solve([[['a', 2, 10], ['a', 4, 11], ['a', 6, 12]], 2]), [['a', 2, 6, [10, 11, 12]]])
    check('arrival order', solve([[['a', 4, 10], ['a', 2, 11]], 2]), [['a', 2, 4, [11, 10]]])
    check('key separation', solve([[['a', 2, 10], ['b', 2, 11]], 2]), [['a', 2, 2, [10]], ['b', 2, 2, [11]]])
    check('separate sessions', solve([[['a', 2, 10], ['a', 7, 11]], 2]), [['a', 2, 2, [10]], ['a', 7, 7, [11]]])
    check('equal timestamp', solve([[['a', 2, 11], ['a', 2, 10]], 0]), [['a', 2, 2, [10, 11]]])
    check('single event', solve([[['a', 2, 10]], 2]), [['a', 2, 2, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 3:
    check('bridge chain', solve([[['a', 3, 10], ['a', 5, 11], ['a', 7, 12]], 2]), [['a', 3, 7, [10, 11, 12]]])
    check('arrival order', solve([[['a', 5, 10], ['a', 3, 11]], 2]), [['a', 3, 5, [11, 10]]])
    check('key separation', solve([[['a', 3, 10], ['b', 3, 11]], 2]), [['a', 3, 3, [10]], ['b', 3, 3, [11]]])
    check('separate sessions', solve([[['a', 3, 10], ['a', 8, 11]], 2]), [['a', 3, 3, [10]], ['a', 8, 8, [11]]])
    check('equal timestamp', solve([[['a', 3, 11], ['a', 3, 10]], 0]), [['a', 3, 3, [10, 11]]])
    check('single event', solve([[['a', 3, 10]], 2]), [['a', 3, 3, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 4:
    check('bridge chain', solve([[['a', 4, 10], ['a', 6, 11], ['a', 8, 12]], 2]), [['a', 4, 8, [10, 11, 12]]])
    check('arrival order', solve([[['a', 6, 10], ['a', 4, 11]], 2]), [['a', 4, 6, [11, 10]]])
    check('key separation', solve([[['a', 4, 10], ['b', 4, 11]], 2]), [['a', 4, 4, [10]], ['b', 4, 4, [11]]])
    check('separate sessions', solve([[['a', 4, 10], ['a', 9, 11]], 2]), [['a', 4, 4, [10]], ['a', 9, 9, [11]]])
    check('equal timestamp', solve([[['a', 4, 11], ['a', 4, 10]], 0]), [['a', 4, 4, [10, 11]]])
    check('single event', solve([[['a', 4, 10]], 2]), [['a', 4, 4, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 5:
    check('bridge chain', solve([[['a', 5, 10], ['a', 7, 11], ['a', 9, 12]], 2]), [['a', 5, 9, [10, 11, 12]]])
    check('arrival order', solve([[['a', 7, 10], ['a', 5, 11]], 2]), [['a', 5, 7, [11, 10]]])
    check('key separation', solve([[['a', 5, 10], ['b', 5, 11]], 2]), [['a', 5, 5, [10]], ['b', 5, 5, [11]]])
    check('separate sessions', solve([[['a', 5, 10], ['a', 10, 11]], 2]), [['a', 5, 5, [10]], ['a', 10, 10, [11]]])
    check('equal timestamp', solve([[['a', 5, 11], ['a', 5, 10]], 0]), [['a', 5, 5, [10, 11]]])
    check('single event', solve([[['a', 5, 10]], 2]), [['a', 5, 5, [10]]])
    check('empty stream', solve([[], 2]), [])
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:
Session grouping includes events from other keys.

Group [key,time,id] events into sessions independently by key. Sort each key by (time,id); consecutive gaps <=gap belong to one transitive session. Emit [key,first-time,last-time,ordered-ids] ordered by key and session time. An intervening bridge may join otherwise distant endpoints.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        events,gap=d
        out=[]
        for key in sorted(set(k for k,t,i in events)):
            rows=[(t,i) for k,t,i in events if k==key]
            start=last=None; ids=[]
            for time,ident in rows:
                if ids and time-last>gap:
                    out.append([key,start,last,ids]); ids=[]
                if not ids: start=time
                ids.append(ident); last=time
            if ids: out.append([key,start,last,ids])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('bridge chain', solve([[['a', 1, 10], ['a', 3, 11], ['a', 5, 12]], 2]), [['a', 1, 5, [10, 11, 12]]])
    check('arrival order', solve([[['a', 3, 10], ['a', 1, 11]], 2]), [['a', 1, 3, [11, 10]]])
    check('key separation', solve([[['a', 1, 10], ['b', 1, 11]], 2]), [['a', 1, 1, [10]], ['b', 1, 1, [11]]])
    check('separate sessions', solve([[['a', 1, 10], ['a', 6, 11]], 2]), [['a', 1, 1, [10]], ['a', 6, 6, [11]]])
    check('equal timestamp', solve([[['a', 1, 11], ['a', 1, 10]], 0]), [['a', 1, 1, [10, 11]]])
    check('single event', solve([[['a', 1, 10]], 2]), [['a', 1, 1, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 2:
    check('bridge chain', solve([[['a', 2, 10], ['a', 4, 11], ['a', 6, 12]], 2]), [['a', 2, 6, [10, 11, 12]]])
    check('arrival order', solve([[['a', 4, 10], ['a', 2, 11]], 2]), [['a', 2, 4, [11, 10]]])
    check('key separation', solve([[['a', 2, 10], ['b', 2, 11]], 2]), [['a', 2, 2, [10]], ['b', 2, 2, [11]]])
    check('separate sessions', solve([[['a', 2, 10], ['a', 7, 11]], 2]), [['a', 2, 2, [10]], ['a', 7, 7, [11]]])
    check('equal timestamp', solve([[['a', 2, 11], ['a', 2, 10]], 0]), [['a', 2, 2, [10, 11]]])
    check('single event', solve([[['a', 2, 10]], 2]), [['a', 2, 2, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 3:
    check('bridge chain', solve([[['a', 3, 10], ['a', 5, 11], ['a', 7, 12]], 2]), [['a', 3, 7, [10, 11, 12]]])
    check('arrival order', solve([[['a', 5, 10], ['a', 3, 11]], 2]), [['a', 3, 5, [11, 10]]])
    check('key separation', solve([[['a', 3, 10], ['b', 3, 11]], 2]), [['a', 3, 3, [10]], ['b', 3, 3, [11]]])
    check('separate sessions', solve([[['a', 3, 10], ['a', 8, 11]], 2]), [['a', 3, 3, [10]], ['a', 8, 8, [11]]])
    check('equal timestamp', solve([[['a', 3, 11], ['a', 3, 10]], 0]), [['a', 3, 3, [10, 11]]])
    check('single event', solve([[['a', 3, 10]], 2]), [['a', 3, 3, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 4:
    check('bridge chain', solve([[['a', 4, 10], ['a', 6, 11], ['a', 8, 12]], 2]), [['a', 4, 8, [10, 11, 12]]])
    check('arrival order', solve([[['a', 6, 10], ['a', 4, 11]], 2]), [['a', 4, 6, [11, 10]]])
    check('key separation', solve([[['a', 4, 10], ['b', 4, 11]], 2]), [['a', 4, 4, [10]], ['b', 4, 4, [11]]])
    check('separate sessions', solve([[['a', 4, 10], ['a', 9, 11]], 2]), [['a', 4, 4, [10]], ['a', 9, 9, [11]]])
    check('equal timestamp', solve([[['a', 4, 11], ['a', 4, 10]], 0]), [['a', 4, 4, [10, 11]]])
    check('single event', solve([[['a', 4, 10]], 2]), [['a', 4, 4, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 5:
    check('bridge chain', solve([[['a', 5, 10], ['a', 7, 11], ['a', 9, 12]], 2]), [['a', 5, 9, [10, 11, 12]]])
    check('arrival order', solve([[['a', 7, 10], ['a', 5, 11]], 2]), [['a', 5, 7, [11, 10]]])
    check('key separation', solve([[['a', 5, 10], ['b', 5, 11]], 2]), [['a', 5, 5, [10]], ['b', 5, 5, [11]]])
    check('separate sessions', solve([[['a', 5, 10], ['a', 10, 11]], 2]), [['a', 5, 5, [10]], ['a', 10, 10, [11]]])
    check('equal timestamp', solve([[['a', 5, 11], ['a', 5, 10]], 0]), [['a', 5, 5, [10, 11]]])
    check('single event', solve([[['a', 5, 10]], 2]), [['a', 5, 5, [10]]])
    check('empty stream', solve([[], 2]), [])
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):
    try:
        events,gap=d
        out=[]
        for key in sorted(set(k for k,t,i in events)):
            rows=sorted(((t,i) for k,t,i in events if k==key),key=lambda r:r[1])
            start=last=None; ids=[]
            for time,ident in rows:
                if ids and time-last>gap:
                    out.append([key,start,last,ids]); ids=[]
                if not ids: start=time
                ids.append(ident); last=time
            if ids: out.append([key,start,last,ids])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('bridge chain', solve([[['a', 1, 10], ['a', 3, 11], ['a', 5, 12]], 2]), [['a', 1, 5, [10, 11, 12]]])
    check('arrival order', solve([[['a', 3, 10], ['a', 1, 11]], 2]), [['a', 1, 3, [11, 10]]])
    check('key separation', solve([[['a', 1, 10], ['b', 1, 11]], 2]), [['a', 1, 1, [10]], ['b', 1, 1, [11]]])
    check('separate sessions', solve([[['a', 1, 10], ['a', 6, 11]], 2]), [['a', 1, 1, [10]], ['a', 6, 6, [11]]])
    check('equal timestamp', solve([[['a', 1, 11], ['a', 1, 10]], 0]), [['a', 1, 1, [10, 11]]])
    check('single event', solve([[['a', 1, 10]], 2]), [['a', 1, 1, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 2:
    check('bridge chain', solve([[['a', 2, 10], ['a', 4, 11], ['a', 6, 12]], 2]), [['a', 2, 6, [10, 11, 12]]])
    check('arrival order', solve([[['a', 4, 10], ['a', 2, 11]], 2]), [['a', 2, 4, [11, 10]]])
    check('key separation', solve([[['a', 2, 10], ['b', 2, 11]], 2]), [['a', 2, 2, [10]], ['b', 2, 2, [11]]])
    check('separate sessions', solve([[['a', 2, 10], ['a', 7, 11]], 2]), [['a', 2, 2, [10]], ['a', 7, 7, [11]]])
    check('equal timestamp', solve([[['a', 2, 11], ['a', 2, 10]], 0]), [['a', 2, 2, [10, 11]]])
    check('single event', solve([[['a', 2, 10]], 2]), [['a', 2, 2, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 3:
    check('bridge chain', solve([[['a', 3, 10], ['a', 5, 11], ['a', 7, 12]], 2]), [['a', 3, 7, [10, 11, 12]]])
    check('arrival order', solve([[['a', 5, 10], ['a', 3, 11]], 2]), [['a', 3, 5, [11, 10]]])
    check('key separation', solve([[['a', 3, 10], ['b', 3, 11]], 2]), [['a', 3, 3, [10]], ['b', 3, 3, [11]]])
    check('separate sessions', solve([[['a', 3, 10], ['a', 8, 11]], 2]), [['a', 3, 3, [10]], ['a', 8, 8, [11]]])
    check('equal timestamp', solve([[['a', 3, 11], ['a', 3, 10]], 0]), [['a', 3, 3, [10, 11]]])
    check('single event', solve([[['a', 3, 10]], 2]), [['a', 3, 3, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 4:
    check('bridge chain', solve([[['a', 4, 10], ['a', 6, 11], ['a', 8, 12]], 2]), [['a', 4, 8, [10, 11, 12]]])
    check('arrival order', solve([[['a', 6, 10], ['a', 4, 11]], 2]), [['a', 4, 6, [11, 10]]])
    check('key separation', solve([[['a', 4, 10], ['b', 4, 11]], 2]), [['a', 4, 4, [10]], ['b', 4, 4, [11]]])
    check('separate sessions', solve([[['a', 4, 10], ['a', 9, 11]], 2]), [['a', 4, 4, [10]], ['a', 9, 9, [11]]])
    check('equal timestamp', solve([[['a', 4, 11], ['a', 4, 10]], 0]), [['a', 4, 4, [10, 11]]])
    check('single event', solve([[['a', 4, 10]], 2]), [['a', 4, 4, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 5:
    check('bridge chain', solve([[['a', 5, 10], ['a', 7, 11], ['a', 9, 12]], 2]), [['a', 5, 9, [10, 11, 12]]])
    check('arrival order', solve([[['a', 7, 10], ['a', 5, 11]], 2]), [['a', 5, 7, [11, 10]]])
    check('key separation', solve([[['a', 5, 10], ['b', 5, 11]], 2]), [['a', 5, 5, [10]], ['b', 5, 5, [11]]])
    check('separate sessions', solve([[['a', 5, 10], ['a', 10, 11]], 2]), [['a', 5, 5, [10]], ['a', 10, 10, [11]]])
    check('equal timestamp', solve([[['a', 5, 11], ['a', 5, 10]], 0]), [['a', 5, 5, [10, 11]]])
    check('single event', solve([[['a', 5, 10]], 2]), [['a', 5, 5, [10]]])
    check('empty stream', solve([[], 2]), [])
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:
Session grouping consumes source arrival order instead of event-time order.

Group [key,time,id] events into sessions independently by key. Sort each key by (time,id); consecutive gaps <=gap belong to one transitive session. Emit [key,first-time,last-time,ordered-ids] ordered by key and session time. An intervening bridge may join otherwise distant endpoints.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        events,gap=d
        out=[]
        for key in sorted(set(k for k,t,i in events)):
            rows=sorted((t,i) for k,t,i in events if k==key)
            start=last=None; ids=[]
            for time,ident in rows:
                if ids and time-last>gap:
                    out.append([key,start,last,ids]); ids=[]
                start=time
                ids.append(ident); last=time
            if ids: out.append([key,start,last,ids])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('bridge chain', solve([[['a', 1, 10], ['a', 3, 11], ['a', 5, 12]], 2]), [['a', 1, 5, [10, 11, 12]]])
    check('arrival order', solve([[['a', 3, 10], ['a', 1, 11]], 2]), [['a', 1, 3, [11, 10]]])
    check('key separation', solve([[['a', 1, 10], ['b', 1, 11]], 2]), [['a', 1, 1, [10]], ['b', 1, 1, [11]]])
    check('separate sessions', solve([[['a', 1, 10], ['a', 6, 11]], 2]), [['a', 1, 1, [10]], ['a', 6, 6, [11]]])
    check('equal timestamp', solve([[['a', 1, 11], ['a', 1, 10]], 0]), [['a', 1, 1, [10, 11]]])
    check('single event', solve([[['a', 1, 10]], 2]), [['a', 1, 1, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 2:
    check('bridge chain', solve([[['a', 2, 10], ['a', 4, 11], ['a', 6, 12]], 2]), [['a', 2, 6, [10, 11, 12]]])
    check('arrival order', solve([[['a', 4, 10], ['a', 2, 11]], 2]), [['a', 2, 4, [11, 10]]])
    check('key separation', solve([[['a', 2, 10], ['b', 2, 11]], 2]), [['a', 2, 2, [10]], ['b', 2, 2, [11]]])
    check('separate sessions', solve([[['a', 2, 10], ['a', 7, 11]], 2]), [['a', 2, 2, [10]], ['a', 7, 7, [11]]])
    check('equal timestamp', solve([[['a', 2, 11], ['a', 2, 10]], 0]), [['a', 2, 2, [10, 11]]])
    check('single event', solve([[['a', 2, 10]], 2]), [['a', 2, 2, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 3:
    check('bridge chain', solve([[['a', 3, 10], ['a', 5, 11], ['a', 7, 12]], 2]), [['a', 3, 7, [10, 11, 12]]])
    check('arrival order', solve([[['a', 5, 10], ['a', 3, 11]], 2]), [['a', 3, 5, [11, 10]]])
    check('key separation', solve([[['a', 3, 10], ['b', 3, 11]], 2]), [['a', 3, 3, [10]], ['b', 3, 3, [11]]])
    check('separate sessions', solve([[['a', 3, 10], ['a', 8, 11]], 2]), [['a', 3, 3, [10]], ['a', 8, 8, [11]]])
    check('equal timestamp', solve([[['a', 3, 11], ['a', 3, 10]], 0]), [['a', 3, 3, [10, 11]]])
    check('single event', solve([[['a', 3, 10]], 2]), [['a', 3, 3, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 4:
    check('bridge chain', solve([[['a', 4, 10], ['a', 6, 11], ['a', 8, 12]], 2]), [['a', 4, 8, [10, 11, 12]]])
    check('arrival order', solve([[['a', 6, 10], ['a', 4, 11]], 2]), [['a', 4, 6, [11, 10]]])
    check('key separation', solve([[['a', 4, 10], ['b', 4, 11]], 2]), [['a', 4, 4, [10]], ['b', 4, 4, [11]]])
    check('separate sessions', solve([[['a', 4, 10], ['a', 9, 11]], 2]), [['a', 4, 4, [10]], ['a', 9, 9, [11]]])
    check('equal timestamp', solve([[['a', 4, 11], ['a', 4, 10]], 0]), [['a', 4, 4, [10, 11]]])
    check('single event', solve([[['a', 4, 10]], 2]), [['a', 4, 4, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 5:
    check('bridge chain', solve([[['a', 5, 10], ['a', 7, 11], ['a', 9, 12]], 2]), [['a', 5, 9, [10, 11, 12]]])
    check('arrival order', solve([[['a', 7, 10], ['a', 5, 11]], 2]), [['a', 5, 7, [11, 10]]])
    check('key separation', solve([[['a', 5, 10], ['b', 5, 11]], 2]), [['a', 5, 5, [10]], ['b', 5, 5, [11]]])
    check('separate sessions', solve([[['a', 5, 10], ['a', 10, 11]], 2]), [['a', 5, 5, [10]], ['a', 10, 10, [11]]])
    check('equal timestamp', solve([[['a', 5, 11], ['a', 5, 10]], 0]), [['a', 5, 5, [10, 11]]])
    check('single event', solve([[['a', 5, 10]], 2]), [['a', 5, 5, [10]]])
    check('empty stream', solve([[], 2]), [])
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):
    try:
        events,gap=d
        out=[]
        for key in sorted(set(k for k,t,i in events)):
            rows=sorted((t,i) for k,t,i in events if k==key)
            start=last=None; ids=[]
            for time,ident in rows:
                if ids and time-last>gap:
                    out.append([key,start,last,ids]); ids=[]
                if len(ids)<=1: start=time
                ids.append(ident); last=time
            if ids: out.append([key,start,last,ids])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('bridge chain', solve([[['a', 1, 10], ['a', 3, 11], ['a', 5, 12]], 2]), [['a', 1, 5, [10, 11, 12]]])
    check('arrival order', solve([[['a', 3, 10], ['a', 1, 11]], 2]), [['a', 1, 3, [11, 10]]])
    check('key separation', solve([[['a', 1, 10], ['b', 1, 11]], 2]), [['a', 1, 1, [10]], ['b', 1, 1, [11]]])
    check('separate sessions', solve([[['a', 1, 10], ['a', 6, 11]], 2]), [['a', 1, 1, [10]], ['a', 6, 6, [11]]])
    check('equal timestamp', solve([[['a', 1, 11], ['a', 1, 10]], 0]), [['a', 1, 1, [10, 11]]])
    check('single event', solve([[['a', 1, 10]], 2]), [['a', 1, 1, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 2:
    check('bridge chain', solve([[['a', 2, 10], ['a', 4, 11], ['a', 6, 12]], 2]), [['a', 2, 6, [10, 11, 12]]])
    check('arrival order', solve([[['a', 4, 10], ['a', 2, 11]], 2]), [['a', 2, 4, [11, 10]]])
    check('key separation', solve([[['a', 2, 10], ['b', 2, 11]], 2]), [['a', 2, 2, [10]], ['b', 2, 2, [11]]])
    check('separate sessions', solve([[['a', 2, 10], ['a', 7, 11]], 2]), [['a', 2, 2, [10]], ['a', 7, 7, [11]]])
    check('equal timestamp', solve([[['a', 2, 11], ['a', 2, 10]], 0]), [['a', 2, 2, [10, 11]]])
    check('single event', solve([[['a', 2, 10]], 2]), [['a', 2, 2, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 3:
    check('bridge chain', solve([[['a', 3, 10], ['a', 5, 11], ['a', 7, 12]], 2]), [['a', 3, 7, [10, 11, 12]]])
    check('arrival order', solve([[['a', 5, 10], ['a', 3, 11]], 2]), [['a', 3, 5, [11, 10]]])
    check('key separation', solve([[['a', 3, 10], ['b', 3, 11]], 2]), [['a', 3, 3, [10]], ['b', 3, 3, [11]]])
    check('separate sessions', solve([[['a', 3, 10], ['a', 8, 11]], 2]), [['a', 3, 3, [10]], ['a', 8, 8, [11]]])
    check('equal timestamp', solve([[['a', 3, 11], ['a', 3, 10]], 0]), [['a', 3, 3, [10, 11]]])
    check('single event', solve([[['a', 3, 10]], 2]), [['a', 3, 3, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 4:
    check('bridge chain', solve([[['a', 4, 10], ['a', 6, 11], ['a', 8, 12]], 2]), [['a', 4, 8, [10, 11, 12]]])
    check('arrival order', solve([[['a', 6, 10], ['a', 4, 11]], 2]), [['a', 4, 6, [11, 10]]])
    check('key separation', solve([[['a', 4, 10], ['b', 4, 11]], 2]), [['a', 4, 4, [10]], ['b', 4, 4, [11]]])
    check('separate sessions', solve([[['a', 4, 10], ['a', 9, 11]], 2]), [['a', 4, 4, [10]], ['a', 9, 9, [11]]])
    check('equal timestamp', solve([[['a', 4, 11], ['a', 4, 10]], 0]), [['a', 4, 4, [10, 11]]])
    check('single event', solve([[['a', 4, 10]], 2]), [['a', 4, 4, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 5:
    check('bridge chain', solve([[['a', 5, 10], ['a', 7, 11], ['a', 9, 12]], 2]), [['a', 5, 9, [10, 11, 12]]])
    check('arrival order', solve([[['a', 7, 10], ['a', 5, 11]], 2]), [['a', 5, 7, [11, 10]]])
    check('key separation', solve([[['a', 5, 10], ['b', 5, 11]], 2]), [['a', 5, 5, [10]], ['b', 5, 5, [11]]])
    check('separate sessions', solve([[['a', 5, 10], ['a', 10, 11]], 2]), [['a', 5, 5, [10]], ['a', 10, 10, [11]]])
    check('equal timestamp', solve([[['a', 5, 11], ['a', 5, 10]], 0]), [['a', 5, 5, [10, 11]]])
    check('single event', solve([[['a', 5, 10]], 2]), [['a', 5, 5, [10]]])
    check('empty stream', solve([[], 2]), [])
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:
Session grouping overwrites the session start on every event.

Group [key,time,id] events into sessions independently by key. Sort each key by (time,id); consecutive gaps <=gap belong to one transitive session. Emit [key,first-time,last-time,ordered-ids] ordered by key and session time. An intervening bridge may join otherwise distant endpoints.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        events,gap=d
        out=[]
        for key in sorted(set(k for k,t,i in events)):
            rows=sorted((t,i) for k,t,i in events if k==key)
            start=last=None; ids=[]
            for time,ident in rows:
                if ids and time-last>gap:
                    out.append([key,start,last,ids]); ids=[]
                if not ids: start=time
                ids.append(ident); last=time
            if False: out.append([key,start,last,ids])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('bridge chain', solve([[['a', 1, 10], ['a', 3, 11], ['a', 5, 12]], 2]), [['a', 1, 5, [10, 11, 12]]])
    check('arrival order', solve([[['a', 3, 10], ['a', 1, 11]], 2]), [['a', 1, 3, [11, 10]]])
    check('key separation', solve([[['a', 1, 10], ['b', 1, 11]], 2]), [['a', 1, 1, [10]], ['b', 1, 1, [11]]])
    check('separate sessions', solve([[['a', 1, 10], ['a', 6, 11]], 2]), [['a', 1, 1, [10]], ['a', 6, 6, [11]]])
    check('equal timestamp', solve([[['a', 1, 11], ['a', 1, 10]], 0]), [['a', 1, 1, [10, 11]]])
    check('single event', solve([[['a', 1, 10]], 2]), [['a', 1, 1, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 2:
    check('bridge chain', solve([[['a', 2, 10], ['a', 4, 11], ['a', 6, 12]], 2]), [['a', 2, 6, [10, 11, 12]]])
    check('arrival order', solve([[['a', 4, 10], ['a', 2, 11]], 2]), [['a', 2, 4, [11, 10]]])
    check('key separation', solve([[['a', 2, 10], ['b', 2, 11]], 2]), [['a', 2, 2, [10]], ['b', 2, 2, [11]]])
    check('separate sessions', solve([[['a', 2, 10], ['a', 7, 11]], 2]), [['a', 2, 2, [10]], ['a', 7, 7, [11]]])
    check('equal timestamp', solve([[['a', 2, 11], ['a', 2, 10]], 0]), [['a', 2, 2, [10, 11]]])
    check('single event', solve([[['a', 2, 10]], 2]), [['a', 2, 2, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 3:
    check('bridge chain', solve([[['a', 3, 10], ['a', 5, 11], ['a', 7, 12]], 2]), [['a', 3, 7, [10, 11, 12]]])
    check('arrival order', solve([[['a', 5, 10], ['a', 3, 11]], 2]), [['a', 3, 5, [11, 10]]])
    check('key separation', solve([[['a', 3, 10], ['b', 3, 11]], 2]), [['a', 3, 3, [10]], ['b', 3, 3, [11]]])
    check('separate sessions', solve([[['a', 3, 10], ['a', 8, 11]], 2]), [['a', 3, 3, [10]], ['a', 8, 8, [11]]])
    check('equal timestamp', solve([[['a', 3, 11], ['a', 3, 10]], 0]), [['a', 3, 3, [10, 11]]])
    check('single event', solve([[['a', 3, 10]], 2]), [['a', 3, 3, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 4:
    check('bridge chain', solve([[['a', 4, 10], ['a', 6, 11], ['a', 8, 12]], 2]), [['a', 4, 8, [10, 11, 12]]])
    check('arrival order', solve([[['a', 6, 10], ['a', 4, 11]], 2]), [['a', 4, 6, [11, 10]]])
    check('key separation', solve([[['a', 4, 10], ['b', 4, 11]], 2]), [['a', 4, 4, [10]], ['b', 4, 4, [11]]])
    check('separate sessions', solve([[['a', 4, 10], ['a', 9, 11]], 2]), [['a', 4, 4, [10]], ['a', 9, 9, [11]]])
    check('equal timestamp', solve([[['a', 4, 11], ['a', 4, 10]], 0]), [['a', 4, 4, [10, 11]]])
    check('single event', solve([[['a', 4, 10]], 2]), [['a', 4, 4, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 5:
    check('bridge chain', solve([[['a', 5, 10], ['a', 7, 11], ['a', 9, 12]], 2]), [['a', 5, 9, [10, 11, 12]]])
    check('arrival order', solve([[['a', 7, 10], ['a', 5, 11]], 2]), [['a', 5, 7, [11, 10]]])
    check('key separation', solve([[['a', 5, 10], ['b', 5, 11]], 2]), [['a', 5, 5, [10]], ['b', 5, 5, [11]]])
    check('separate sessions', solve([[['a', 5, 10], ['a', 10, 11]], 2]), [['a', 5, 5, [10]], ['a', 10, 10, [11]]])
    check('equal timestamp', solve([[['a', 5, 11], ['a', 5, 10]], 0]), [['a', 5, 5, [10, 11]]])
    check('single event', solve([[['a', 5, 10]], 2]), [['a', 5, 5, [10]]])
    check('empty stream', solve([[], 2]), [])
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):
    try:
        events,gap=d
        out=[]
        for key in sorted(set(k for k,t,i in events)):
            rows=sorted((t,i) for k,t,i in events if k==key)
            start=last=None; ids=[]
            for time,ident in rows:
                if ids and time-last>gap:
                    out.append([key,start,last,ids]); ids=[]
                if not ids: start=time
                ids.append(ident); last=time
            if len(ids)>1: out.append([key,start,last,ids])
        return out
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('bridge chain', solve([[['a', 1, 10], ['a', 3, 11], ['a', 5, 12]], 2]), [['a', 1, 5, [10, 11, 12]]])
    check('arrival order', solve([[['a', 3, 10], ['a', 1, 11]], 2]), [['a', 1, 3, [11, 10]]])
    check('key separation', solve([[['a', 1, 10], ['b', 1, 11]], 2]), [['a', 1, 1, [10]], ['b', 1, 1, [11]]])
    check('separate sessions', solve([[['a', 1, 10], ['a', 6, 11]], 2]), [['a', 1, 1, [10]], ['a', 6, 6, [11]]])
    check('equal timestamp', solve([[['a', 1, 11], ['a', 1, 10]], 0]), [['a', 1, 1, [10, 11]]])
    check('single event', solve([[['a', 1, 10]], 2]), [['a', 1, 1, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 2:
    check('bridge chain', solve([[['a', 2, 10], ['a', 4, 11], ['a', 6, 12]], 2]), [['a', 2, 6, [10, 11, 12]]])
    check('arrival order', solve([[['a', 4, 10], ['a', 2, 11]], 2]), [['a', 2, 4, [11, 10]]])
    check('key separation', solve([[['a', 2, 10], ['b', 2, 11]], 2]), [['a', 2, 2, [10]], ['b', 2, 2, [11]]])
    check('separate sessions', solve([[['a', 2, 10], ['a', 7, 11]], 2]), [['a', 2, 2, [10]], ['a', 7, 7, [11]]])
    check('equal timestamp', solve([[['a', 2, 11], ['a', 2, 10]], 0]), [['a', 2, 2, [10, 11]]])
    check('single event', solve([[['a', 2, 10]], 2]), [['a', 2, 2, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 3:
    check('bridge chain', solve([[['a', 3, 10], ['a', 5, 11], ['a', 7, 12]], 2]), [['a', 3, 7, [10, 11, 12]]])
    check('arrival order', solve([[['a', 5, 10], ['a', 3, 11]], 2]), [['a', 3, 5, [11, 10]]])
    check('key separation', solve([[['a', 3, 10], ['b', 3, 11]], 2]), [['a', 3, 3, [10]], ['b', 3, 3, [11]]])
    check('separate sessions', solve([[['a', 3, 10], ['a', 8, 11]], 2]), [['a', 3, 3, [10]], ['a', 8, 8, [11]]])
    check('equal timestamp', solve([[['a', 3, 11], ['a', 3, 10]], 0]), [['a', 3, 3, [10, 11]]])
    check('single event', solve([[['a', 3, 10]], 2]), [['a', 3, 3, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 4:
    check('bridge chain', solve([[['a', 4, 10], ['a', 6, 11], ['a', 8, 12]], 2]), [['a', 4, 8, [10, 11, 12]]])
    check('arrival order', solve([[['a', 6, 10], ['a', 4, 11]], 2]), [['a', 4, 6, [11, 10]]])
    check('key separation', solve([[['a', 4, 10], ['b', 4, 11]], 2]), [['a', 4, 4, [10]], ['b', 4, 4, [11]]])
    check('separate sessions', solve([[['a', 4, 10], ['a', 9, 11]], 2]), [['a', 4, 4, [10]], ['a', 9, 9, [11]]])
    check('equal timestamp', solve([[['a', 4, 11], ['a', 4, 10]], 0]), [['a', 4, 4, [10, 11]]])
    check('single event', solve([[['a', 4, 10]], 2]), [['a', 4, 4, [10]]])
    check('empty stream', solve([[], 2]), [])
elif N == 5:
    check('bridge chain', solve([[['a', 5, 10], ['a', 7, 11], ['a', 9, 12]], 2]), [['a', 5, 9, [10, 11, 12]]])
    check('arrival order', solve([[['a', 7, 10], ['a', 5, 11]], 2]), [['a', 5, 7, [11, 10]]])
    check('key separation', solve([[['a', 5, 10], ['b', 5, 11]], 2]), [['a', 5, 5, [10]], ['b', 5, 5, [11]]])
    check('separate sessions', solve([[['a', 5, 10], ['a', 10, 11]], 2]), [['a', 5, 5, [10]], ['a', 10, 10, [11]]])
    check('equal timestamp', solve([[['a', 5, 11], ['a', 5, 10]], 0]), [['a', 5, 5, [10, 11]]])
    check('single event', solve([[['a', 5, 10]], 2]), [['a', 5, 5, [10]]])
    check('empty stream', solve([[], 2]), [])
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:
Session grouping loses the final open session for each key.

Group [key,time,id] events into sessions independently by key. Sort each key by (time,id); consecutive gaps <=gap belong to one transitive session. Emit [key,first-time,last-time,ordered-ids] ordered by key and session time. An intervening bridge may join otherwise distant endpoints.

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        watermark=None; pending=[]; emitted=[]; late=[]
        for kind,time,ident in d:
            if kind=='event':
                if watermark is not None and time<=watermark: late.append([time,ident])
                else: pending.append([time,ident])
            else:
                watermark=time if watermark is None else max(watermark,time)
                ready=sorted(e for e in pending if e[0]<watermark)
                emitted.extend(ready)
                pending=[e for e in pending if e[0]>=watermark]
        return [emitted,late,sorted(pending)]
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('frontier equality', solve([['watermark', 1, None], ['event', 1, 10]]), [[], [], [[1, 10]]])
    check('regression', solve([['watermark', 4, None], ['watermark', 1, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('frontier stays pending', solve([['event', 1, 10], ['watermark', 1, None]]), [[], [], [[1, 10]]])
    check('event time ordering', solve([['event', 3, 10], ['event', 1, 11], ['watermark', 4, None]]), [[[1, 11], [3, 10]], [], []])
    check('emit once', solve([['event', 1, 10], ['watermark', 2, None], ['watermark', 3, None]]), [[[1, 10]], [], []])
    check('late row', solve([['watermark', 3, None], ['event', 1, 10]]), [[], [[1, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 2:
    check('frontier equality', solve([['watermark', 2, None], ['event', 2, 10]]), [[], [], [[2, 10]]])
    check('regression', solve([['watermark', 5, None], ['watermark', 2, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('frontier stays pending', solve([['event', 2, 10], ['watermark', 2, None]]), [[], [], [[2, 10]]])
    check('event time ordering', solve([['event', 4, 10], ['event', 2, 11], ['watermark', 5, None]]), [[[2, 11], [4, 10]], [], []])
    check('emit once', solve([['event', 2, 10], ['watermark', 3, None], ['watermark', 4, None]]), [[[2, 10]], [], []])
    check('late row', solve([['watermark', 4, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 3:
    check('frontier equality', solve([['watermark', 3, None], ['event', 3, 10]]), [[], [], [[3, 10]]])
    check('regression', solve([['watermark', 6, None], ['watermark', 3, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('frontier stays pending', solve([['event', 3, 10], ['watermark', 3, None]]), [[], [], [[3, 10]]])
    check('event time ordering', solve([['event', 5, 10], ['event', 3, 11], ['watermark', 6, None]]), [[[3, 11], [5, 10]], [], []])
    check('emit once', solve([['event', 3, 10], ['watermark', 4, None], ['watermark', 5, None]]), [[[3, 10]], [], []])
    check('late row', solve([['watermark', 5, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 4:
    check('frontier equality', solve([['watermark', 4, None], ['event', 4, 10]]), [[], [], [[4, 10]]])
    check('regression', solve([['watermark', 7, None], ['watermark', 4, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('frontier stays pending', solve([['event', 4, 10], ['watermark', 4, None]]), [[], [], [[4, 10]]])
    check('event time ordering', solve([['event', 6, 10], ['event', 4, 11], ['watermark', 7, None]]), [[[4, 11], [6, 10]], [], []])
    check('emit once', solve([['event', 4, 10], ['watermark', 5, None], ['watermark', 6, None]]), [[[4, 10]], [], []])
    check('late row', solve([['watermark', 6, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 5:
    check('frontier equality', solve([['watermark', 5, None], ['event', 5, 10]]), [[], [], [[5, 10]]])
    check('regression', solve([['watermark', 8, None], ['watermark', 5, None], ['event', 6, 10]]), [[], [[6, 10]], []])
    check('frontier stays pending', solve([['event', 5, 10], ['watermark', 5, None]]), [[], [], [[5, 10]]])
    check('event time ordering', solve([['event', 7, 10], ['event', 5, 11], ['watermark', 8, None]]), [[[5, 11], [7, 10]], [], []])
    check('emit once', solve([['event', 5, 10], ['watermark', 6, None], ['watermark', 7, None]]), [[[5, 10]], [], []])
    check('late row', solve([['watermark', 7, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('empty input', solve([]), [[], [], []])
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):
    try:
        watermark=None; pending=[]; emitted=[]; late=[]
        for kind,time,ident in d:
            if kind=='event':
                if watermark is not None and time<watermark+1: late.append([time,ident])
                else: pending.append([time,ident])
            else:
                watermark=time if watermark is None else max(watermark,time)
                ready=sorted(e for e in pending if e[0]<watermark)
                emitted.extend(ready)
                pending=[e for e in pending if e[0]>=watermark]
        return [emitted,late,sorted(pending)]
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('frontier equality', solve([['watermark', 1, None], ['event', 1, 10]]), [[], [], [[1, 10]]])
    check('regression', solve([['watermark', 4, None], ['watermark', 1, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('frontier stays pending', solve([['event', 1, 10], ['watermark', 1, None]]), [[], [], [[1, 10]]])
    check('event time ordering', solve([['event', 3, 10], ['event', 1, 11], ['watermark', 4, None]]), [[[1, 11], [3, 10]], [], []])
    check('emit once', solve([['event', 1, 10], ['watermark', 2, None], ['watermark', 3, None]]), [[[1, 10]], [], []])
    check('late row', solve([['watermark', 3, None], ['event', 1, 10]]), [[], [[1, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 2:
    check('frontier equality', solve([['watermark', 2, None], ['event', 2, 10]]), [[], [], [[2, 10]]])
    check('regression', solve([['watermark', 5, None], ['watermark', 2, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('frontier stays pending', solve([['event', 2, 10], ['watermark', 2, None]]), [[], [], [[2, 10]]])
    check('event time ordering', solve([['event', 4, 10], ['event', 2, 11], ['watermark', 5, None]]), [[[2, 11], [4, 10]], [], []])
    check('emit once', solve([['event', 2, 10], ['watermark', 3, None], ['watermark', 4, None]]), [[[2, 10]], [], []])
    check('late row', solve([['watermark', 4, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 3:
    check('frontier equality', solve([['watermark', 3, None], ['event', 3, 10]]), [[], [], [[3, 10]]])
    check('regression', solve([['watermark', 6, None], ['watermark', 3, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('frontier stays pending', solve([['event', 3, 10], ['watermark', 3, None]]), [[], [], [[3, 10]]])
    check('event time ordering', solve([['event', 5, 10], ['event', 3, 11], ['watermark', 6, None]]), [[[3, 11], [5, 10]], [], []])
    check('emit once', solve([['event', 3, 10], ['watermark', 4, None], ['watermark', 5, None]]), [[[3, 10]], [], []])
    check('late row', solve([['watermark', 5, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 4:
    check('frontier equality', solve([['watermark', 4, None], ['event', 4, 10]]), [[], [], [[4, 10]]])
    check('regression', solve([['watermark', 7, None], ['watermark', 4, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('frontier stays pending', solve([['event', 4, 10], ['watermark', 4, None]]), [[], [], [[4, 10]]])
    check('event time ordering', solve([['event', 6, 10], ['event', 4, 11], ['watermark', 7, None]]), [[[4, 11], [6, 10]], [], []])
    check('emit once', solve([['event', 4, 10], ['watermark', 5, None], ['watermark', 6, None]]), [[[4, 10]], [], []])
    check('late row', solve([['watermark', 6, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 5:
    check('frontier equality', solve([['watermark', 5, None], ['event', 5, 10]]), [[], [], [[5, 10]]])
    check('regression', solve([['watermark', 8, None], ['watermark', 5, None], ['event', 6, 10]]), [[], [[6, 10]], []])
    check('frontier stays pending', solve([['event', 5, 10], ['watermark', 5, None]]), [[], [], [[5, 10]]])
    check('event time ordering', solve([['event', 7, 10], ['event', 5, 11], ['watermark', 8, None]]), [[[5, 11], [7, 10]], [], []])
    check('emit once', solve([['event', 5, 10], ['watermark', 6, None], ['watermark', 7, None]]), [[[5, 10]], [], []])
    check('late row', solve([['watermark', 7, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('empty input', solve([]), [[], [], []])
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:
Watermark buffering rejects an event exactly at the watermark.

Process event actions [event,time,id] and watermark actions [watermark,time,None]. Maintain monotone watermark; events older than it go to late output. On a watermark, release buffered events with time strictly below watermark ordered by (time,id). Return [emitted,late,sorted-pending].

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        watermark=None; pending=[]; emitted=[]; late=[]
        for kind,time,ident in d:
            if kind=='event':
                if watermark is not None and time<watermark: late.append([time,ident])
                else: pending.append([time,ident])
            else:
                watermark=time
                ready=sorted(e for e in pending if e[0]<watermark)
                emitted.extend(ready)
                pending=[e for e in pending if e[0]>=watermark]
        return [emitted,late,sorted(pending)]
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('frontier equality', solve([['watermark', 1, None], ['event', 1, 10]]), [[], [], [[1, 10]]])
    check('regression', solve([['watermark', 4, None], ['watermark', 1, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('frontier stays pending', solve([['event', 1, 10], ['watermark', 1, None]]), [[], [], [[1, 10]]])
    check('event time ordering', solve([['event', 3, 10], ['event', 1, 11], ['watermark', 4, None]]), [[[1, 11], [3, 10]], [], []])
    check('emit once', solve([['event', 1, 10], ['watermark', 2, None], ['watermark', 3, None]]), [[[1, 10]], [], []])
    check('late row', solve([['watermark', 3, None], ['event', 1, 10]]), [[], [[1, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 2:
    check('frontier equality', solve([['watermark', 2, None], ['event', 2, 10]]), [[], [], [[2, 10]]])
    check('regression', solve([['watermark', 5, None], ['watermark', 2, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('frontier stays pending', solve([['event', 2, 10], ['watermark', 2, None]]), [[], [], [[2, 10]]])
    check('event time ordering', solve([['event', 4, 10], ['event', 2, 11], ['watermark', 5, None]]), [[[2, 11], [4, 10]], [], []])
    check('emit once', solve([['event', 2, 10], ['watermark', 3, None], ['watermark', 4, None]]), [[[2, 10]], [], []])
    check('late row', solve([['watermark', 4, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 3:
    check('frontier equality', solve([['watermark', 3, None], ['event', 3, 10]]), [[], [], [[3, 10]]])
    check('regression', solve([['watermark', 6, None], ['watermark', 3, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('frontier stays pending', solve([['event', 3, 10], ['watermark', 3, None]]), [[], [], [[3, 10]]])
    check('event time ordering', solve([['event', 5, 10], ['event', 3, 11], ['watermark', 6, None]]), [[[3, 11], [5, 10]], [], []])
    check('emit once', solve([['event', 3, 10], ['watermark', 4, None], ['watermark', 5, None]]), [[[3, 10]], [], []])
    check('late row', solve([['watermark', 5, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 4:
    check('frontier equality', solve([['watermark', 4, None], ['event', 4, 10]]), [[], [], [[4, 10]]])
    check('regression', solve([['watermark', 7, None], ['watermark', 4, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('frontier stays pending', solve([['event', 4, 10], ['watermark', 4, None]]), [[], [], [[4, 10]]])
    check('event time ordering', solve([['event', 6, 10], ['event', 4, 11], ['watermark', 7, None]]), [[[4, 11], [6, 10]], [], []])
    check('emit once', solve([['event', 4, 10], ['watermark', 5, None], ['watermark', 6, None]]), [[[4, 10]], [], []])
    check('late row', solve([['watermark', 6, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 5:
    check('frontier equality', solve([['watermark', 5, None], ['event', 5, 10]]), [[], [], [[5, 10]]])
    check('regression', solve([['watermark', 8, None], ['watermark', 5, None], ['event', 6, 10]]), [[], [[6, 10]], []])
    check('frontier stays pending', solve([['event', 5, 10], ['watermark', 5, None]]), [[], [], [[5, 10]]])
    check('event time ordering', solve([['event', 7, 10], ['event', 5, 11], ['watermark', 8, None]]), [[[5, 11], [7, 10]], [], []])
    check('emit once', solve([['event', 5, 10], ['watermark', 6, None], ['watermark', 7, None]]), [[[5, 10]], [], []])
    check('late row', solve([['watermark', 7, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('empty input', solve([]), [[], [], []])
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):
    try:
        watermark=None; pending=[]; emitted=[]; late=[]
        for kind,time,ident in d:
            if kind=='event':
                if watermark is not None and time<watermark: late.append([time,ident])
                else: pending.append([time,ident])
            else:
                watermark=time if watermark is None else min(watermark,time)
                ready=sorted(e for e in pending if e[0]<watermark)
                emitted.extend(ready)
                pending=[e for e in pending if e[0]>=watermark]
        return [emitted,late,sorted(pending)]
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('frontier equality', solve([['watermark', 1, None], ['event', 1, 10]]), [[], [], [[1, 10]]])
    check('regression', solve([['watermark', 4, None], ['watermark', 1, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('frontier stays pending', solve([['event', 1, 10], ['watermark', 1, None]]), [[], [], [[1, 10]]])
    check('event time ordering', solve([['event', 3, 10], ['event', 1, 11], ['watermark', 4, None]]), [[[1, 11], [3, 10]], [], []])
    check('emit once', solve([['event', 1, 10], ['watermark', 2, None], ['watermark', 3, None]]), [[[1, 10]], [], []])
    check('late row', solve([['watermark', 3, None], ['event', 1, 10]]), [[], [[1, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 2:
    check('frontier equality', solve([['watermark', 2, None], ['event', 2, 10]]), [[], [], [[2, 10]]])
    check('regression', solve([['watermark', 5, None], ['watermark', 2, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('frontier stays pending', solve([['event', 2, 10], ['watermark', 2, None]]), [[], [], [[2, 10]]])
    check('event time ordering', solve([['event', 4, 10], ['event', 2, 11], ['watermark', 5, None]]), [[[2, 11], [4, 10]], [], []])
    check('emit once', solve([['event', 2, 10], ['watermark', 3, None], ['watermark', 4, None]]), [[[2, 10]], [], []])
    check('late row', solve([['watermark', 4, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 3:
    check('frontier equality', solve([['watermark', 3, None], ['event', 3, 10]]), [[], [], [[3, 10]]])
    check('regression', solve([['watermark', 6, None], ['watermark', 3, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('frontier stays pending', solve([['event', 3, 10], ['watermark', 3, None]]), [[], [], [[3, 10]]])
    check('event time ordering', solve([['event', 5, 10], ['event', 3, 11], ['watermark', 6, None]]), [[[3, 11], [5, 10]], [], []])
    check('emit once', solve([['event', 3, 10], ['watermark', 4, None], ['watermark', 5, None]]), [[[3, 10]], [], []])
    check('late row', solve([['watermark', 5, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 4:
    check('frontier equality', solve([['watermark', 4, None], ['event', 4, 10]]), [[], [], [[4, 10]]])
    check('regression', solve([['watermark', 7, None], ['watermark', 4, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('frontier stays pending', solve([['event', 4, 10], ['watermark', 4, None]]), [[], [], [[4, 10]]])
    check('event time ordering', solve([['event', 6, 10], ['event', 4, 11], ['watermark', 7, None]]), [[[4, 11], [6, 10]], [], []])
    check('emit once', solve([['event', 4, 10], ['watermark', 5, None], ['watermark', 6, None]]), [[[4, 10]], [], []])
    check('late row', solve([['watermark', 6, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 5:
    check('frontier equality', solve([['watermark', 5, None], ['event', 5, 10]]), [[], [], [[5, 10]]])
    check('regression', solve([['watermark', 8, None], ['watermark', 5, None], ['event', 6, 10]]), [[], [[6, 10]], []])
    check('frontier stays pending', solve([['event', 5, 10], ['watermark', 5, None]]), [[], [], [[5, 10]]])
    check('event time ordering', solve([['event', 7, 10], ['event', 5, 11], ['watermark', 8, None]]), [[[5, 11], [7, 10]], [], []])
    check('emit once', solve([['event', 5, 10], ['watermark', 6, None], ['watermark', 7, None]]), [[[5, 10]], [], []])
    check('late row', solve([['watermark', 7, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('empty input', solve([]), [[], [], []])
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 regressing watermark reopens already closed event time.

Process event actions [event,time,id] and watermark actions [watermark,time,None]. Maintain monotone watermark; events older than it go to late output. On a watermark, release buffered events with time strictly below watermark ordered by (time,id). Return [emitted,late,sorted-pending].

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        watermark=None; pending=[]; emitted=[]; late=[]
        for kind,time,ident in d:
            if kind=='event':
                if watermark is not None and time<watermark: late.append([time,ident])
                else: pending.append([time,ident])
            else:
                watermark=time if watermark is None else max(watermark,time)
                ready=sorted(e for e in pending if e[0]<=watermark)
                emitted.extend(ready)
                pending=[e for e in pending if e[0]>=watermark]
        return [emitted,late,sorted(pending)]
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('frontier equality', solve([['watermark', 1, None], ['event', 1, 10]]), [[], [], [[1, 10]]])
    check('regression', solve([['watermark', 4, None], ['watermark', 1, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('frontier stays pending', solve([['event', 1, 10], ['watermark', 1, None]]), [[], [], [[1, 10]]])
    check('event time ordering', solve([['event', 3, 10], ['event', 1, 11], ['watermark', 4, None]]), [[[1, 11], [3, 10]], [], []])
    check('emit once', solve([['event', 1, 10], ['watermark', 2, None], ['watermark', 3, None]]), [[[1, 10]], [], []])
    check('late row', solve([['watermark', 3, None], ['event', 1, 10]]), [[], [[1, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 2:
    check('frontier equality', solve([['watermark', 2, None], ['event', 2, 10]]), [[], [], [[2, 10]]])
    check('regression', solve([['watermark', 5, None], ['watermark', 2, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('frontier stays pending', solve([['event', 2, 10], ['watermark', 2, None]]), [[], [], [[2, 10]]])
    check('event time ordering', solve([['event', 4, 10], ['event', 2, 11], ['watermark', 5, None]]), [[[2, 11], [4, 10]], [], []])
    check('emit once', solve([['event', 2, 10], ['watermark', 3, None], ['watermark', 4, None]]), [[[2, 10]], [], []])
    check('late row', solve([['watermark', 4, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 3:
    check('frontier equality', solve([['watermark', 3, None], ['event', 3, 10]]), [[], [], [[3, 10]]])
    check('regression', solve([['watermark', 6, None], ['watermark', 3, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('frontier stays pending', solve([['event', 3, 10], ['watermark', 3, None]]), [[], [], [[3, 10]]])
    check('event time ordering', solve([['event', 5, 10], ['event', 3, 11], ['watermark', 6, None]]), [[[3, 11], [5, 10]], [], []])
    check('emit once', solve([['event', 3, 10], ['watermark', 4, None], ['watermark', 5, None]]), [[[3, 10]], [], []])
    check('late row', solve([['watermark', 5, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 4:
    check('frontier equality', solve([['watermark', 4, None], ['event', 4, 10]]), [[], [], [[4, 10]]])
    check('regression', solve([['watermark', 7, None], ['watermark', 4, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('frontier stays pending', solve([['event', 4, 10], ['watermark', 4, None]]), [[], [], [[4, 10]]])
    check('event time ordering', solve([['event', 6, 10], ['event', 4, 11], ['watermark', 7, None]]), [[[4, 11], [6, 10]], [], []])
    check('emit once', solve([['event', 4, 10], ['watermark', 5, None], ['watermark', 6, None]]), [[[4, 10]], [], []])
    check('late row', solve([['watermark', 6, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 5:
    check('frontier equality', solve([['watermark', 5, None], ['event', 5, 10]]), [[], [], [[5, 10]]])
    check('regression', solve([['watermark', 8, None], ['watermark', 5, None], ['event', 6, 10]]), [[], [[6, 10]], []])
    check('frontier stays pending', solve([['event', 5, 10], ['watermark', 5, None]]), [[], [], [[5, 10]]])
    check('event time ordering', solve([['event', 7, 10], ['event', 5, 11], ['watermark', 8, None]]), [[[5, 11], [7, 10]], [], []])
    check('emit once', solve([['event', 5, 10], ['watermark', 6, None], ['watermark', 7, None]]), [[[5, 10]], [], []])
    check('late row', solve([['watermark', 7, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('empty input', solve([]), [[], [], []])
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):
    try:
        watermark=None; pending=[]; emitted=[]; late=[]
        for kind,time,ident in d:
            if kind=='event':
                if watermark is not None and time<watermark: late.append([time,ident])
                else: pending.append([time,ident])
            else:
                watermark=time if watermark is None else max(watermark,time)
                ready=sorted(e for e in pending if e[0]<watermark+1)
                emitted.extend(ready)
                pending=[e for e in pending if e[0]>=watermark]
        return [emitted,late,sorted(pending)]
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('frontier equality', solve([['watermark', 1, None], ['event', 1, 10]]), [[], [], [[1, 10]]])
    check('regression', solve([['watermark', 4, None], ['watermark', 1, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('frontier stays pending', solve([['event', 1, 10], ['watermark', 1, None]]), [[], [], [[1, 10]]])
    check('event time ordering', solve([['event', 3, 10], ['event', 1, 11], ['watermark', 4, None]]), [[[1, 11], [3, 10]], [], []])
    check('emit once', solve([['event', 1, 10], ['watermark', 2, None], ['watermark', 3, None]]), [[[1, 10]], [], []])
    check('late row', solve([['watermark', 3, None], ['event', 1, 10]]), [[], [[1, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 2:
    check('frontier equality', solve([['watermark', 2, None], ['event', 2, 10]]), [[], [], [[2, 10]]])
    check('regression', solve([['watermark', 5, None], ['watermark', 2, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('frontier stays pending', solve([['event', 2, 10], ['watermark', 2, None]]), [[], [], [[2, 10]]])
    check('event time ordering', solve([['event', 4, 10], ['event', 2, 11], ['watermark', 5, None]]), [[[2, 11], [4, 10]], [], []])
    check('emit once', solve([['event', 2, 10], ['watermark', 3, None], ['watermark', 4, None]]), [[[2, 10]], [], []])
    check('late row', solve([['watermark', 4, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 3:
    check('frontier equality', solve([['watermark', 3, None], ['event', 3, 10]]), [[], [], [[3, 10]]])
    check('regression', solve([['watermark', 6, None], ['watermark', 3, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('frontier stays pending', solve([['event', 3, 10], ['watermark', 3, None]]), [[], [], [[3, 10]]])
    check('event time ordering', solve([['event', 5, 10], ['event', 3, 11], ['watermark', 6, None]]), [[[3, 11], [5, 10]], [], []])
    check('emit once', solve([['event', 3, 10], ['watermark', 4, None], ['watermark', 5, None]]), [[[3, 10]], [], []])
    check('late row', solve([['watermark', 5, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 4:
    check('frontier equality', solve([['watermark', 4, None], ['event', 4, 10]]), [[], [], [[4, 10]]])
    check('regression', solve([['watermark', 7, None], ['watermark', 4, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('frontier stays pending', solve([['event', 4, 10], ['watermark', 4, None]]), [[], [], [[4, 10]]])
    check('event time ordering', solve([['event', 6, 10], ['event', 4, 11], ['watermark', 7, None]]), [[[4, 11], [6, 10]], [], []])
    check('emit once', solve([['event', 4, 10], ['watermark', 5, None], ['watermark', 6, None]]), [[[4, 10]], [], []])
    check('late row', solve([['watermark', 6, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 5:
    check('frontier equality', solve([['watermark', 5, None], ['event', 5, 10]]), [[], [], [[5, 10]]])
    check('regression', solve([['watermark', 8, None], ['watermark', 5, None], ['event', 6, 10]]), [[], [[6, 10]], []])
    check('frontier stays pending', solve([['event', 5, 10], ['watermark', 5, None]]), [[], [], [[5, 10]]])
    check('event time ordering', solve([['event', 7, 10], ['event', 5, 11], ['watermark', 8, None]]), [[[5, 11], [7, 10]], [], []])
    check('emit once', solve([['event', 5, 10], ['watermark', 6, None], ['watermark', 7, None]]), [[[5, 10]], [], []])
    check('late row', solve([['watermark', 7, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('empty input', solve([]), [[], [], []])
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:
Watermark buffering releases events at the frontier prematurely.

Process event actions [event,time,id] and watermark actions [watermark,time,None]. Maintain monotone watermark; events older than it go to late output. On a watermark, release buffered events with time strictly below watermark ordered by (time,id). Return [emitted,late,sorted-pending].

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        watermark=None; pending=[]; emitted=[]; late=[]
        for kind,time,ident in d:
            if kind=='event':
                if watermark is not None and time<watermark: late.append([time,ident])
                else: pending.append([time,ident])
            else:
                watermark=time if watermark is None else max(watermark,time)
                ready=[e for e in pending if e[0]<watermark]
                emitted.extend(ready)
                pending=[e for e in pending if e[0]>=watermark]
        return [emitted,late,sorted(pending)]
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('frontier equality', solve([['watermark', 1, None], ['event', 1, 10]]), [[], [], [[1, 10]]])
    check('regression', solve([['watermark', 4, None], ['watermark', 1, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('frontier stays pending', solve([['event', 1, 10], ['watermark', 1, None]]), [[], [], [[1, 10]]])
    check('event time ordering', solve([['event', 3, 10], ['event', 1, 11], ['watermark', 4, None]]), [[[1, 11], [3, 10]], [], []])
    check('emit once', solve([['event', 1, 10], ['watermark', 2, None], ['watermark', 3, None]]), [[[1, 10]], [], []])
    check('late row', solve([['watermark', 3, None], ['event', 1, 10]]), [[], [[1, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 2:
    check('frontier equality', solve([['watermark', 2, None], ['event', 2, 10]]), [[], [], [[2, 10]]])
    check('regression', solve([['watermark', 5, None], ['watermark', 2, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('frontier stays pending', solve([['event', 2, 10], ['watermark', 2, None]]), [[], [], [[2, 10]]])
    check('event time ordering', solve([['event', 4, 10], ['event', 2, 11], ['watermark', 5, None]]), [[[2, 11], [4, 10]], [], []])
    check('emit once', solve([['event', 2, 10], ['watermark', 3, None], ['watermark', 4, None]]), [[[2, 10]], [], []])
    check('late row', solve([['watermark', 4, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 3:
    check('frontier equality', solve([['watermark', 3, None], ['event', 3, 10]]), [[], [], [[3, 10]]])
    check('regression', solve([['watermark', 6, None], ['watermark', 3, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('frontier stays pending', solve([['event', 3, 10], ['watermark', 3, None]]), [[], [], [[3, 10]]])
    check('event time ordering', solve([['event', 5, 10], ['event', 3, 11], ['watermark', 6, None]]), [[[3, 11], [5, 10]], [], []])
    check('emit once', solve([['event', 3, 10], ['watermark', 4, None], ['watermark', 5, None]]), [[[3, 10]], [], []])
    check('late row', solve([['watermark', 5, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 4:
    check('frontier equality', solve([['watermark', 4, None], ['event', 4, 10]]), [[], [], [[4, 10]]])
    check('regression', solve([['watermark', 7, None], ['watermark', 4, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('frontier stays pending', solve([['event', 4, 10], ['watermark', 4, None]]), [[], [], [[4, 10]]])
    check('event time ordering', solve([['event', 6, 10], ['event', 4, 11], ['watermark', 7, None]]), [[[4, 11], [6, 10]], [], []])
    check('emit once', solve([['event', 4, 10], ['watermark', 5, None], ['watermark', 6, None]]), [[[4, 10]], [], []])
    check('late row', solve([['watermark', 6, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 5:
    check('frontier equality', solve([['watermark', 5, None], ['event', 5, 10]]), [[], [], [[5, 10]]])
    check('regression', solve([['watermark', 8, None], ['watermark', 5, None], ['event', 6, 10]]), [[], [[6, 10]], []])
    check('frontier stays pending', solve([['event', 5, 10], ['watermark', 5, None]]), [[], [], [[5, 10]]])
    check('event time ordering', solve([['event', 7, 10], ['event', 5, 11], ['watermark', 8, None]]), [[[5, 11], [7, 10]], [], []])
    check('emit once', solve([['event', 5, 10], ['watermark', 6, None], ['watermark', 7, None]]), [[[5, 10]], [], []])
    check('late row', solve([['watermark', 7, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('empty input', solve([]), [[], [], []])
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):
    try:
        watermark=None; pending=[]; emitted=[]; late=[]
        for kind,time,ident in d:
            if kind=='event':
                if watermark is not None and time<watermark: late.append([time,ident])
                else: pending.append([time,ident])
            else:
                watermark=time if watermark is None else max(watermark,time)
                ready=sorted((e for e in pending if e[0]<watermark),key=lambda e:e[1])
                emitted.extend(ready)
                pending=[e for e in pending if e[0]>=watermark]
        return [emitted,late,sorted(pending)]
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('frontier equality', solve([['watermark', 1, None], ['event', 1, 10]]), [[], [], [[1, 10]]])
    check('regression', solve([['watermark', 4, None], ['watermark', 1, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('frontier stays pending', solve([['event', 1, 10], ['watermark', 1, None]]), [[], [], [[1, 10]]])
    check('event time ordering', solve([['event', 3, 10], ['event', 1, 11], ['watermark', 4, None]]), [[[1, 11], [3, 10]], [], []])
    check('emit once', solve([['event', 1, 10], ['watermark', 2, None], ['watermark', 3, None]]), [[[1, 10]], [], []])
    check('late row', solve([['watermark', 3, None], ['event', 1, 10]]), [[], [[1, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 2:
    check('frontier equality', solve([['watermark', 2, None], ['event', 2, 10]]), [[], [], [[2, 10]]])
    check('regression', solve([['watermark', 5, None], ['watermark', 2, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('frontier stays pending', solve([['event', 2, 10], ['watermark', 2, None]]), [[], [], [[2, 10]]])
    check('event time ordering', solve([['event', 4, 10], ['event', 2, 11], ['watermark', 5, None]]), [[[2, 11], [4, 10]], [], []])
    check('emit once', solve([['event', 2, 10], ['watermark', 3, None], ['watermark', 4, None]]), [[[2, 10]], [], []])
    check('late row', solve([['watermark', 4, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 3:
    check('frontier equality', solve([['watermark', 3, None], ['event', 3, 10]]), [[], [], [[3, 10]]])
    check('regression', solve([['watermark', 6, None], ['watermark', 3, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('frontier stays pending', solve([['event', 3, 10], ['watermark', 3, None]]), [[], [], [[3, 10]]])
    check('event time ordering', solve([['event', 5, 10], ['event', 3, 11], ['watermark', 6, None]]), [[[3, 11], [5, 10]], [], []])
    check('emit once', solve([['event', 3, 10], ['watermark', 4, None], ['watermark', 5, None]]), [[[3, 10]], [], []])
    check('late row', solve([['watermark', 5, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 4:
    check('frontier equality', solve([['watermark', 4, None], ['event', 4, 10]]), [[], [], [[4, 10]]])
    check('regression', solve([['watermark', 7, None], ['watermark', 4, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('frontier stays pending', solve([['event', 4, 10], ['watermark', 4, None]]), [[], [], [[4, 10]]])
    check('event time ordering', solve([['event', 6, 10], ['event', 4, 11], ['watermark', 7, None]]), [[[4, 11], [6, 10]], [], []])
    check('emit once', solve([['event', 4, 10], ['watermark', 5, None], ['watermark', 6, None]]), [[[4, 10]], [], []])
    check('late row', solve([['watermark', 6, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 5:
    check('frontier equality', solve([['watermark', 5, None], ['event', 5, 10]]), [[], [], [[5, 10]]])
    check('regression', solve([['watermark', 8, None], ['watermark', 5, None], ['event', 6, 10]]), [[], [[6, 10]], []])
    check('frontier stays pending', solve([['event', 5, 10], ['watermark', 5, None]]), [[], [], [[5, 10]]])
    check('event time ordering', solve([['event', 7, 10], ['event', 5, 11], ['watermark', 8, None]]), [[[5, 11], [7, 10]], [], []])
    check('emit once', solve([['event', 5, 10], ['watermark', 6, None], ['watermark', 7, None]]), [[[5, 10]], [], []])
    check('late row', solve([['watermark', 7, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('empty input', solve([]), [[], [], []])
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:
Watermark release retains arrival order instead of event-time order.

Process event actions [event,time,id] and watermark actions [watermark,time,None]. Maintain monotone watermark; events older than it go to late output. On a watermark, release buffered events with time strictly below watermark ordered by (time,id). Return [emitted,late,sorted-pending].

split: open-access


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

N = 1
observations = []
def solve(d):
    try:
        watermark=None; pending=[]; emitted=[]; late=[]
        for kind,time,ident in d:
            if kind=='event':
                if watermark is not None and time<watermark: late.append([time,ident])
                else: pending.append([time,ident])
            else:
                watermark=time if watermark is None else max(watermark,time)
                ready=sorted(e for e in pending if e[0]<watermark)
                emitted.extend(ready)
                pending=pending
        return [emitted,late,sorted(pending)]
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('frontier equality', solve([['watermark', 1, None], ['event', 1, 10]]), [[], [], [[1, 10]]])
    check('regression', solve([['watermark', 4, None], ['watermark', 1, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('frontier stays pending', solve([['event', 1, 10], ['watermark', 1, None]]), [[], [], [[1, 10]]])
    check('event time ordering', solve([['event', 3, 10], ['event', 1, 11], ['watermark', 4, None]]), [[[1, 11], [3, 10]], [], []])
    check('emit once', solve([['event', 1, 10], ['watermark', 2, None], ['watermark', 3, None]]), [[[1, 10]], [], []])
    check('late row', solve([['watermark', 3, None], ['event', 1, 10]]), [[], [[1, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 2:
    check('frontier equality', solve([['watermark', 2, None], ['event', 2, 10]]), [[], [], [[2, 10]]])
    check('regression', solve([['watermark', 5, None], ['watermark', 2, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('frontier stays pending', solve([['event', 2, 10], ['watermark', 2, None]]), [[], [], [[2, 10]]])
    check('event time ordering', solve([['event', 4, 10], ['event', 2, 11], ['watermark', 5, None]]), [[[2, 11], [4, 10]], [], []])
    check('emit once', solve([['event', 2, 10], ['watermark', 3, None], ['watermark', 4, None]]), [[[2, 10]], [], []])
    check('late row', solve([['watermark', 4, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 3:
    check('frontier equality', solve([['watermark', 3, None], ['event', 3, 10]]), [[], [], [[3, 10]]])
    check('regression', solve([['watermark', 6, None], ['watermark', 3, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('frontier stays pending', solve([['event', 3, 10], ['watermark', 3, None]]), [[], [], [[3, 10]]])
    check('event time ordering', solve([['event', 5, 10], ['event', 3, 11], ['watermark', 6, None]]), [[[3, 11], [5, 10]], [], []])
    check('emit once', solve([['event', 3, 10], ['watermark', 4, None], ['watermark', 5, None]]), [[[3, 10]], [], []])
    check('late row', solve([['watermark', 5, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 4:
    check('frontier equality', solve([['watermark', 4, None], ['event', 4, 10]]), [[], [], [[4, 10]]])
    check('regression', solve([['watermark', 7, None], ['watermark', 4, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('frontier stays pending', solve([['event', 4, 10], ['watermark', 4, None]]), [[], [], [[4, 10]]])
    check('event time ordering', solve([['event', 6, 10], ['event', 4, 11], ['watermark', 7, None]]), [[[4, 11], [6, 10]], [], []])
    check('emit once', solve([['event', 4, 10], ['watermark', 5, None], ['watermark', 6, None]]), [[[4, 10]], [], []])
    check('late row', solve([['watermark', 6, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 5:
    check('frontier equality', solve([['watermark', 5, None], ['event', 5, 10]]), [[], [], [[5, 10]]])
    check('regression', solve([['watermark', 8, None], ['watermark', 5, None], ['event', 6, 10]]), [[], [[6, 10]], []])
    check('frontier stays pending', solve([['event', 5, 10], ['watermark', 5, None]]), [[], [], [[5, 10]]])
    check('event time ordering', solve([['event', 7, 10], ['event', 5, 11], ['watermark', 8, None]]), [[[5, 11], [7, 10]], [], []])
    check('emit once', solve([['event', 5, 10], ['watermark', 6, None], ['watermark', 7, None]]), [[[5, 10]], [], []])
    check('late row', solve([['watermark', 7, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('empty input', solve([]), [[], [], []])
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):
    try:
        watermark=None; pending=[]; emitted=[]; late=[]
        for kind,time,ident in d:
            if kind=='event':
                if watermark is not None and time<watermark: late.append([time,ident])
                else: pending.append([time,ident])
            else:
                watermark=time if watermark is None else max(watermark,time)
                ready=sorted(e for e in pending if e[0]<watermark)
                emitted.extend(ready)
                pending=[e for e in pending if e[0]>watermark]
        return [emitted,late,sorted(pending)]
    except (IndexError, KeyError, ValueError, StopIteration) as exc:
        return {"representation_error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('frontier equality', solve([['watermark', 1, None], ['event', 1, 10]]), [[], [], [[1, 10]]])
    check('regression', solve([['watermark', 4, None], ['watermark', 1, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('frontier stays pending', solve([['event', 1, 10], ['watermark', 1, None]]), [[], [], [[1, 10]]])
    check('event time ordering', solve([['event', 3, 10], ['event', 1, 11], ['watermark', 4, None]]), [[[1, 11], [3, 10]], [], []])
    check('emit once', solve([['event', 1, 10], ['watermark', 2, None], ['watermark', 3, None]]), [[[1, 10]], [], []])
    check('late row', solve([['watermark', 3, None], ['event', 1, 10]]), [[], [[1, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 2:
    check('frontier equality', solve([['watermark', 2, None], ['event', 2, 10]]), [[], [], [[2, 10]]])
    check('regression', solve([['watermark', 5, None], ['watermark', 2, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('frontier stays pending', solve([['event', 2, 10], ['watermark', 2, None]]), [[], [], [[2, 10]]])
    check('event time ordering', solve([['event', 4, 10], ['event', 2, 11], ['watermark', 5, None]]), [[[2, 11], [4, 10]], [], []])
    check('emit once', solve([['event', 2, 10], ['watermark', 3, None], ['watermark', 4, None]]), [[[2, 10]], [], []])
    check('late row', solve([['watermark', 4, None], ['event', 2, 10]]), [[], [[2, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 3:
    check('frontier equality', solve([['watermark', 3, None], ['event', 3, 10]]), [[], [], [[3, 10]]])
    check('regression', solve([['watermark', 6, None], ['watermark', 3, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('frontier stays pending', solve([['event', 3, 10], ['watermark', 3, None]]), [[], [], [[3, 10]]])
    check('event time ordering', solve([['event', 5, 10], ['event', 3, 11], ['watermark', 6, None]]), [[[3, 11], [5, 10]], [], []])
    check('emit once', solve([['event', 3, 10], ['watermark', 4, None], ['watermark', 5, None]]), [[[3, 10]], [], []])
    check('late row', solve([['watermark', 5, None], ['event', 3, 10]]), [[], [[3, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 4:
    check('frontier equality', solve([['watermark', 4, None], ['event', 4, 10]]), [[], [], [[4, 10]]])
    check('regression', solve([['watermark', 7, None], ['watermark', 4, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('frontier stays pending', solve([['event', 4, 10], ['watermark', 4, None]]), [[], [], [[4, 10]]])
    check('event time ordering', solve([['event', 6, 10], ['event', 4, 11], ['watermark', 7, None]]), [[[4, 11], [6, 10]], [], []])
    check('emit once', solve([['event', 4, 10], ['watermark', 5, None], ['watermark', 6, None]]), [[[4, 10]], [], []])
    check('late row', solve([['watermark', 6, None], ['event', 4, 10]]), [[], [[4, 10]], []])
    check('empty input', solve([]), [[], [], []])
elif N == 5:
    check('frontier equality', solve([['watermark', 5, None], ['event', 5, 10]]), [[], [], [[5, 10]]])
    check('regression', solve([['watermark', 8, None], ['watermark', 5, None], ['event', 6, 10]]), [[], [[6, 10]], []])
    check('frontier stays pending', solve([['event', 5, 10], ['watermark', 5, None]]), [[], [], [[5, 10]]])
    check('event time ordering', solve([['event', 7, 10], ['event', 5, 11], ['watermark', 8, None]]), [[[5, 11], [7, 10]], [], []])
    check('emit once', solve([['event', 5, 10], ['watermark', 6, None], ['watermark', 7, None]]), [[[5, 10]], [], []])
    check('late row', solve([['watermark', 7, None], ['event', 5, 10]]), [[], [[5, 10]], []])
    check('empty input', solve([]), [[], [], []])
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:
Watermark release leaves emitted events in the pending buffer.

Process event actions [event,time,id] and watermark actions [watermark,time,None]. Maintain monotone watermark; events older than it go to late output. On a watermark, release buffered events with time strictly below watermark ordered by (time,id). Return [emitted,late,sorted-pending].

split: open-access