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

N = 1
observations = []
def solve(tuples, measures, hidden, totals, separator):
    seen=[]
    for t in tuples:
        if t not in seen: seen.append(t)
    cols=[]
    for t in seen:
        for m in measures:
            key=(tuple(t),m['id'])
            if key in hidden: continue
            cols.append({'key':key,'path':list(t),'label':separator.join(str(x) if x is not None else '(missing)' for x in t)+separator+m['label'],'measure':m['label'],'total':False})
    if totals:
        for m in measures:
            key=(('TOTAL',),m['id'])
            if key not in hidden: cols.append({'key':key,'path':[],'label':'Total'+separator+m['label'],'measure':m['id'],'total':True})
    return cols
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('duplicate paths measures', solve([('east',1),('west',2),('east',1)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 1), 'sum'), 'path': ['east', 1], 'label': 'east / 1 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 1), 'cnt'), 'path': ['east', 1], 'label': 'east / 1 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 2:
    check('duplicate paths measures', solve([('east',2),('west',2),('east',2)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 2), 'sum'), 'path': ['east', 2], 'label': 'east / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 2), 'cnt'), 'path': ['east', 2], 'label': 'east / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 3:
    check('duplicate paths measures', solve([('east',3),('west',2),('east',3)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 3), 'sum'), 'path': ['east', 3], 'label': 'east / 3 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 3), 'cnt'), 'path': ['east', 3], 'label': 'east / 3 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 4:
    check('duplicate paths measures', solve([('east',4),('west',2),('east',4)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 4), 'sum'), 'path': ['east', 4], 'label': 'east / 4 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 4), 'cnt'), 'path': ['east', 4], 'label': 'east / 4 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 5:
    check('duplicate paths measures', solve([('east',5),('west',2),('east',5)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 5), 'sum'), 'path': ['east', 5], 'label': 'east / 5 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 5), 'cnt'), 'path': ['east', 5], 'label': 'east / 5 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

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(tuples, measures, hidden, totals, separator):
    seen=[]
    for t in tuples:
        if t not in seen: seen.append(t)
    cols=[]
    for t in seen:
        for m in measures:
            key=(tuple(t),m['id'])
            if key in hidden: continue
            cols.append({'key':key,'path':list(t),'label':separator.join(str(x) if x is not None else '(missing)' for x in t)+separator+m['label'],'measure':None,'total':False})
    if totals:
        for m in measures:
            key=(('TOTAL',),m['id'])
            if key not in hidden: cols.append({'key':key,'path':[],'label':'Total'+separator+m['label'],'measure':m['id'],'total':True})
    return cols
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('duplicate paths measures', solve([('east',1),('west',2),('east',1)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 1), 'sum'), 'path': ['east', 1], 'label': 'east / 1 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 1), 'cnt'), 'path': ['east', 1], 'label': 'east / 1 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 2:
    check('duplicate paths measures', solve([('east',2),('west',2),('east',2)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 2), 'sum'), 'path': ['east', 2], 'label': 'east / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 2), 'cnt'), 'path': ['east', 2], 'label': 'east / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 3:
    check('duplicate paths measures', solve([('east',3),('west',2),('east',3)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 3), 'sum'), 'path': ['east', 3], 'label': 'east / 3 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 3), 'cnt'), 'path': ['east', 3], 'label': 'east / 3 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 4:
    check('duplicate paths measures', solve([('east',4),('west',2),('east',4)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 4), 'sum'), 'path': ['east', 4], 'label': 'east / 4 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 4), 'cnt'), 'path': ['east', 4], 'label': 'east / 4 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 5:
    check('duplicate paths measures', solve([('east',5),('west',2),('east',5)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 5), 'sum'), 'path': ['east', 5], 'label': 'east / 5 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 5), 'cnt'), 'path': ['east', 5], 'label': 'east / 5 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

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:
The table measure id metadata result violates the stipulated pivot table column descriptor generation contract.

Pivot columns use typed dimension tuples plus measure IDs as identity, deduplicate paths in encounter order, keep measure-specific visibility, distinguish missing/empty/zero dimensions in labels, and represent grand totals with empty ancestry and separately hideable measure keys.

split: open-access


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

N = 1
observations = []
def solve(tuples, measures, hidden, totals, separator):
    seen=[]
    for t in tuples:
        if t not in seen: seen.append(t)
    cols=[]
    for t in seen:
        for m in measures:
            key=(tuple(t),m['id'])
            if key in hidden: continue
            cols.append({'key':key,'path':list(t),'label':separator.join(str(x) if x is not None else '(missing)' for x in t)+separator+m['label'],'measure':m['id'],'total':False})
    if True:
        for m in measures:
            key=(('TOTAL',),m['id'])
            if key not in hidden: cols.append({'key':key,'path':[],'label':'Total'+separator+m['label'],'measure':m['id'],'total':True})
    return cols
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('duplicate paths measures', solve([('east',1),('west',2),('east',1)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 1), 'sum'), 'path': ['east', 1], 'label': 'east / 1 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 1), 'cnt'), 'path': ['east', 1], 'label': 'east / 1 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 2:
    check('duplicate paths measures', solve([('east',2),('west',2),('east',2)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 2), 'sum'), 'path': ['east', 2], 'label': 'east / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 2), 'cnt'), 'path': ['east', 2], 'label': 'east / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 3:
    check('duplicate paths measures', solve([('east',3),('west',2),('east',3)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 3), 'sum'), 'path': ['east', 3], 'label': 'east / 3 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 3), 'cnt'), 'path': ['east', 3], 'label': 'east / 3 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 4:
    check('duplicate paths measures', solve([('east',4),('west',2),('east',4)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 4), 'sum'), 'path': ['east', 4], 'label': 'east / 4 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 4), 'cnt'), 'path': ['east', 4], 'label': 'east / 4 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 5:
    check('duplicate paths measures', solve([('east',5),('west',2),('east',5)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 5), 'sum'), 'path': ['east', 5], 'label': 'east / 5 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 5), 'cnt'), 'path': ['east', 5], 'label': 'east / 5 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

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(tuples, measures, hidden, totals, separator):
    seen=[]
    for t in tuples:
        if t not in seen: seen.append(t)
    cols=[]
    for t in seen:
        for m in measures:
            key=(tuple(t),m['id'])
            if key in hidden: continue
            cols.append({'key':key,'path':list(t),'label':separator.join(str(x) if x is not None else '(missing)' for x in t)+separator+m['label'],'measure':m['id'],'total':False})
    if totals and seen:
        for m in measures:
            key=(('TOTAL',),m['id'])
            if key not in hidden: cols.append({'key':key,'path':[],'label':'Total'+separator+m['label'],'measure':m['id'],'total':True})
    return cols
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('duplicate paths measures', solve([('east',1),('west',2),('east',1)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 1), 'sum'), 'path': ['east', 1], 'label': 'east / 1 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 1), 'cnt'), 'path': ['east', 1], 'label': 'east / 1 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 2:
    check('duplicate paths measures', solve([('east',2),('west',2),('east',2)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 2), 'sum'), 'path': ['east', 2], 'label': 'east / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 2), 'cnt'), 'path': ['east', 2], 'label': 'east / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 3:
    check('duplicate paths measures', solve([('east',3),('west',2),('east',3)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 3), 'sum'), 'path': ['east', 3], 'label': 'east / 3 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 3), 'cnt'), 'path': ['east', 3], 'label': 'east / 3 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 4:
    check('duplicate paths measures', solve([('east',4),('west',2),('east',4)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 4), 'sum'), 'path': ['east', 4], 'label': 'east / 4 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 4), 'cnt'), 'path': ['east', 4], 'label': 'east / 4 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 5:
    check('duplicate paths measures', solve([('east',5),('west',2),('east',5)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 5), 'sum'), 'path': ['east', 5], 'label': 'east / 5 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 5), 'cnt'), 'path': ['east', 5], 'label': 'east / 5 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

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:
The table total column policy result violates the stipulated pivot table column descriptor generation contract.

Pivot columns use typed dimension tuples plus measure IDs as identity, deduplicate paths in encounter order, keep measure-specific visibility, distinguish missing/empty/zero dimensions in labels, and represent grand totals with empty ancestry and separately hideable measure keys.

split: open-access


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

N = 1
observations = []
def solve(tuples, measures, hidden, totals, separator):
    seen=[]
    for t in tuples:
        if t not in seen: seen.append(t)
    cols=[]
    for t in seen:
        for m in measures:
            key=(tuple(t),m['id'])
            if key in hidden: continue
            cols.append({'key':key,'path':list(t),'label':separator.join(str(x) if x is not None else '(missing)' for x in t)+separator+m['label'],'measure':m['id'],'total':False})
    if totals:
        for m in measures:
            key=(('TOTAL',),m['id'])
            if True: cols.append({'key':key,'path':[],'label':'Total'+separator+m['label'],'measure':m['id'],'total':True})
    return cols
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('duplicate paths measures', solve([('east',1),('west',2),('east',1)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 1), 'sum'), 'path': ['east', 1], 'label': 'east / 1 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 1), 'cnt'), 'path': ['east', 1], 'label': 'east / 1 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 2:
    check('duplicate paths measures', solve([('east',2),('west',2),('east',2)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 2), 'sum'), 'path': ['east', 2], 'label': 'east / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 2), 'cnt'), 'path': ['east', 2], 'label': 'east / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 3:
    check('duplicate paths measures', solve([('east',3),('west',2),('east',3)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 3), 'sum'), 'path': ['east', 3], 'label': 'east / 3 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 3), 'cnt'), 'path': ['east', 3], 'label': 'east / 3 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 4:
    check('duplicate paths measures', solve([('east',4),('west',2),('east',4)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 4), 'sum'), 'path': ['east', 4], 'label': 'east / 4 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 4), 'cnt'), 'path': ['east', 4], 'label': 'east / 4 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 5:
    check('duplicate paths measures', solve([('east',5),('west',2),('east',5)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 5), 'sum'), 'path': ['east', 5], 'label': 'east / 5 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 5), 'cnt'), 'path': ['east', 5], 'label': 'east / 5 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

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(tuples, measures, hidden, totals, separator):
    seen=[]
    for t in tuples:
        if t not in seen: seen.append(t)
    cols=[]
    for t in seen:
        for m in measures:
            key=(tuple(t),m['id'])
            if key in hidden: continue
            cols.append({'key':key,'path':list(t),'label':separator.join(str(x) if x is not None else '(missing)' for x in t)+separator+m['label'],'measure':m['id'],'total':False})
    if totals:
        for m in measures:
            key=(('TOTAL',),m['id'])
            if all(x[0]!=('TOTAL',) for x in hidden): cols.append({'key':key,'path':[],'label':'Total'+separator+m['label'],'measure':m['id'],'total':True})
    return cols
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
if N == 1:
    check('duplicate paths measures', solve([('east',1),('west',2),('east',1)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 1), 'sum'), 'path': ['east', 1], 'label': 'east / 1 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 1), 'cnt'), 'path': ['east', 1], 'label': 'east / 1 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 2:
    check('duplicate paths measures', solve([('east',2),('west',2),('east',2)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 2), 'sum'), 'path': ['east', 2], 'label': 'east / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 2), 'cnt'), 'path': ['east', 2], 'label': 'east / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 3:
    check('duplicate paths measures', solve([('east',3),('west',2),('east',3)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 3), 'sum'), 'path': ['east', 3], 'label': 'east / 3 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 3), 'cnt'), 'path': ['east', 3], 'label': 'east / 3 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 4:
    check('duplicate paths measures', solve([('east',4),('west',2),('east',4)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 4), 'sum'), 'path': ['east', 4], 'label': 'east / 4 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 4), 'cnt'), 'path': ['east', 4], 'label': 'east / 4 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

if N == 5:
    check('duplicate paths measures', solve([('east',5),('west',2),('east',5)], [{'id':'sum','label':'Sales'},{'id':'cnt','label':'Count'}], [], True, ' / '), [{'key': (('east', 5), 'sum'), 'path': ['east', 5], 'label': 'east / 5 / Sales', 'measure': 'sum', 'total': False}, {'key': (('east', 5), 'cnt'), 'path': ['east', 5], 'label': 'east / 5 / Count', 'measure': 'cnt', 'total': False}, {'key': (('west', 2), 'sum'), 'path': ['west', 2], 'label': 'west / 2 / Sales', 'measure': 'sum', 'total': False}, {'key': (('west', 2), 'cnt'), 'path': ['west', 2], 'label': 'west / 2 / Count', 'measure': 'cnt', 'total': False}, {'key': (('TOTAL',), 'sum'), 'path': [], 'label': 'Total / Sales', 'measure': 'sum', 'total': True}, {'key': (('TOTAL',), 'cnt'), 'path': [], 'label': 'Total / Count', 'measure': 'cnt', 'total': True}])
    check('hidden one measure', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('a',),'x')], False, ':'), [{'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}])
    check('missing and empty dimensions', solve([(None,),('',),(0,),(1,),('1',)], [{'id':'x','label':'X'}], [], False, ':'), [{'key': ((None,), 'x'), 'path': [None], 'label': '(missing):X', 'measure': 'x', 'total': False}, {'key': (('',), 'x'), 'path': [''], 'label': ':X', 'measure': 'x', 'total': False}, {'key': ((0,), 'x'), 'path': [0], 'label': '0:X', 'measure': 'x', 'total': False}, {'key': ((1,), 'x'), 'path': [1], 'label': '1:X', 'measure': 'x', 'total': False}, {'key': (('1',), 'x'), 'path': ['1'], 'label': '1:X', 'measure': 'x', 'total': False}])
    check('hidden one total', solve([('a',)], [{'id':'x','label':'X'},{'id':'y','label':'Y'}], [(('TOTAL',),'x')], True, ':'), [{'key': (('a',), 'x'), 'path': ['a'], 'label': 'a:X', 'measure': 'x', 'total': False}, {'key': (('a',), 'y'), 'path': ['a'], 'label': 'a:Y', 'measure': 'y', 'total': False}, {'key': (('TOTAL',), 'y'), 'path': [], 'label': 'Total:Y', 'measure': 'y', 'total': True}])
    check('totals without tuples', solve([], [{'id':'x','label':'X'}], [], True, ':'), [{'key': (('TOTAL',), 'x'), 'path': [], 'label': 'Total:X', 'measure': 'x', 'total': True}])
    check('no measures', solve([('a',)], [], [], False, ':'), [])

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:
The table total hidden key result violates the stipulated pivot table column descriptor generation contract.

Pivot columns use typed dimension tuples plus measure IDs as identity, deduplicate paths in encounter order, keep measure-specific visibility, distinguish missing/empty/zero dimensions in labels, and represent grand totals with empty ancestry and separately hideable measure keys.

split: open-access