{"abstract":"Averages that land exactly on half a cent are truncated, drifting unit cost down over many receipts.","category":"Inventory cost layering","checks":8,"contract":"Input {onhand, avg (cents, integer), events}. On receipt the average becomes round-half-up((onhand*avg + qty*cost)/(onhand+qty)) to whole cents; an issue is costed at qty*avg with the current average and never changes it; an issue exceeding on-hand returns \"short\". When on-hand reaches zero the average is kept as the last value (not reset). Return {cogs, onhand, avg}.","evaluation_group":"w2-inventory-cost-layering-moving-average","failed_approach":"Using Python round() applies banker rounding and still rounds some half-cent averages down.","family":"w2-inventory-cost-layering-moving-average-half-cent-rounding","id":"FA-59906","implementations":{"attempt":{"sha256":"7aae3b45fade01d3d1f3ed9636e5cf27c9f3f08492c6f480d74276e1420cf68d","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(x):\n    onhand = x['onhand']\n    avg = x['avg']\n    cogs = []\n    for ev in x['events']:\n        if ev[0] == 'recv':\n            q, c = ev[1], ev[2]\n            total = onhand * avg + q * c\n            units = onhand + q\n            avg = round(total / units)\n            onhand = units\n        else:\n            q = ev[1]\n            if q > onhand:\n                cogs.append('short')\n                continue\n            cogs.append(q * avg)\n            onhand -= q\n    return {'cogs': cogs, 'onhand': onhand, 'avg': avg}\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[['receipt reprices', {'onhand': 10, 'avg': 100, 'events': [['recv', 10, 131], ['issue', 5]]}, {'cogs': [580], 'onhand': 15, 'avg': 116}], ['uneven rounding', {'onhand': 3, 'avg': 10, 'events': [['recv', 4, 12], ['issue', 2], ['issue', 1]]}, {'cogs': [22, 11], 'onhand': 4, 'avg': 11}], ['zero then receipt', {'onhand': 2, 'avg': 50, 'events': [['issue', 2], ['recv', 3, 71], ['issue', 1]]}, {'cogs': [100, 71], 'onhand': 2, 'avg': 71}], ['short issue', {'onhand': 2, 'avg': 50, 'events': [['issue', 4]]}, {'cogs': ['short'], 'onhand': 2, 'avg': 50}], ['many receipts', {'onhand': 0, 'avg': 0, 'events': [['recv', 1, 10], ['recv', 2, 13], ['recv', 1, 20], ['issue', 3]]}, {'cogs': [42], 'onhand': 1, 'avg': 14}], ['half cent', {'onhand': 1, 'avg': 1, 'events': [['recv', 1, 4], ['issue', 1]]}, {'cogs': [3], 'onhand': 1, 'avg': 3}], ['issue all', {'onhand': 4, 'avg': 25, 'events': [['recv', 4, 26], ['issue', 8]]}, {'cogs': [208], 'onhand': 0, 'avg': 26}], ['exact half', {'onhand': 1, 'avg': 2, 'events': [['recv', 1, 3], ['issue', 2]]}, {'cogs': [6], 'onhand': 0, 'avg': 3}]], [['receipt reprices', {'onhand': 10, 'avg': 100, 'events': [['recv', 10, 132], ['issue', 5]]}, {'cogs': [580], 'onhand': 15, 'avg': 116}], ['uneven rounding', {'onhand': 3, 'avg': 10, 'events': [['recv', 4, 13], ['issue', 2], ['issue', 1]]}, {'cogs': [24, 12], 'onhand': 4, 'avg': 12}], ['zero then receipt', {'onhand': 2, 'avg': 50, 'events': [['issue', 2], ['recv', 3, 72], ['issue', 1]]}, {'cogs': [100, 72], 'onhand': 2, 'avg': 72}], ['short issue', {'onhand': 2, 'avg': 50, 'events': [['issue', 5]]}, {'cogs': ['short'], 'onhand': 2, 'avg': 50}], ['many receipts', {'onhand': 0, 'avg': 0, 'events': [['recv', 1, 10], ['recv', 2, 13], ['recv', 2, 20], ['issue', 3]]}, {'cogs': [45], 'onhand': 2, 'avg': 15}], ['half cent', {'onhand': 1, 'avg': 1, 'events': [['recv', 1, 6], ['issue', 1]]}, {'cogs': [4], 'onhand': 1, 'avg': 4}], ['issue all', {'onhand': 4, 'avg': 25, 'events': [['recv', 4, 26], ['issue', 8]]}, {'cogs': [208], 'onhand': 0, 'avg': 26}], ['exact half', {'onhand': 1, 'avg': 4, 'events': [['recv', 1, 5], ['issue', 2]]}, {'cogs': [10], 'onhand': 0, 'avg': 5}]], [['receipt reprices', {'onhand': 10, 'avg': 100, 'events': [['recv', 10, 133], ['issue', 5]]}, {'cogs': [585], 'onhand': 15, 'avg': 117}], ['uneven rounding', {'onhand': 3, 'avg': 10, 'events': [['recv', 4, 14], ['issue', 2], ['issue', 1]]}, {'cogs': [24, 12], 'onhand': 4, 'avg': 12}], ['zero then receipt', {'onhand': 2, 'avg': 50, 'events': [['issue', 2], ['recv', 3, 73], ['issue', 1]]}, {'cogs': [100, 73], 'onhand': 2, 'avg': 73}], ['short issue', {'onhand': 2, 'avg': 50, 'events': [['issue', 6]]}, {'cogs': ['short'], 'onhand': 2, 'avg': 50}], ['many receipts', {'onhand': 0, 'avg': 0, 'events': [['recv', 1, 10], ['recv', 2, 13], ['recv', 3, 20], ['issue', 3]]}, {'cogs': [48], 'onhand': 3, 'avg': 16}], ['half cent', {'onhand': 1, 'avg': 1, 'events': [['recv', 1, 8], ['issue', 1]]}, {'cogs': [5], 'onhand': 1, 'avg': 5}], ['issue all', {'onhand': 4, 'avg': 25, 'events': [['recv', 4, 26], ['issue', 8]]}, {'cogs': [208], 'onhand': 0, 'avg': 26}], ['exact half', {'onhand': 1, 'avg': 6, 'events': [['recv', 1, 7], ['issue', 2]]}, {'cogs': [14], 'onhand': 0, 'avg': 7}]], [['receipt reprices', {'onhand': 10, 'avg': 100, 'events': [['recv', 10, 134], ['issue', 5]]}, {'cogs': [585], 'onhand': 15, 'avg': 117}], ['uneven rounding', {'onhand': 3, 'avg': 10, 'events': [['recv', 4, 15], ['issue', 2], ['issue', 1]]}, {'cogs': [26, 13], 'onhand': 4, 'avg': 13}], ['zero then receipt', {'onhand': 2, 'avg': 50, 'events': [['issue', 2], ['recv', 3, 74], ['issue', 1]]}, {'cogs': [100, 74], 'onhand': 2, 'avg': 74}], ['short issue', {'onhand': 2, 'avg': 50, 'events': [['issue', 7]]}, {'cogs': ['short'], 'onhand': 2, 'avg': 50}], ['many receipts', {'onhand': 0, 'avg': 0, 'events': [['recv', 1, 10], ['recv', 2, 13], ['recv', 4, 20], ['issue', 3]]}, {'cogs': [51], 'onhand': 4, 'avg': 17}], ['half cent', {'onhand': 1, 'avg': 1, 'events': [['recv', 1, 10], ['issue', 1]]}, {'cogs': [6], 'onhand': 1, 'avg': 6}], ['issue all', {'onhand': 4, 'avg': 25, 'events': [['recv', 4, 26], ['issue', 8]]}, {'cogs': [208], 'onhand': 0, 'avg': 26}], ['exact half', {'onhand': 1, 'avg': 8, 'events': [['recv', 1, 9], ['issue', 2]]}, {'cogs': [18], 'onhand': 0, 'avg': 9}]], [['receipt reprices', {'onhand': 10, 'avg': 100, 'events': [['recv', 10, 135], ['issue', 5]]}, {'cogs': [590], 'onhand': 15, 'avg': 118}], ['uneven rounding', {'onhand': 3, 'avg': 10, 'events': [['recv', 4, 16], ['issue', 2], ['issue', 1]]}, {'cogs': [26, 13], 'onhand': 4, 'avg': 13}], ['zero then receipt', {'onhand': 2, 'avg': 50, 'events': [['issue', 2], ['recv', 3, 75], ['issue', 1]]}, {'cogs': [100, 75], 'onhand': 2, 'avg': 75}], ['short issue', {'onhand': 2, 'avg': 50, 'events': [['issue', 8]]}, {'cogs': ['short'], 'onhand': 2, 'avg': 50}], ['many receipts', {'onhand': 0, 'avg': 0, 'events': [['recv', 1, 10], ['recv', 2, 13], ['recv', 5, 20], ['issue', 3]]}, {'cogs': [51], 'onhand': 5, 'avg': 17}], ['half cent', {'onhand': 1, 'avg': 1, 'events': [['recv', 1, 12], ['issue', 1]]}, {'cogs': [7], 'onhand': 1, 'avg': 7}], ['issue all', {'onhand': 4, 'avg': 25, 'events': [['recv', 4, 26], ['issue', 8]]}, {'cogs': [208], 'onhand': 0, 'avg': 26}], ['exact half', {'onhand': 1, 'avg': 10, 'events': [['recv', 1, 11], ['issue', 2]]}, {'cogs': [22], 'onhand': 0, 'avg': 11}]]]\nfor label, args, expected in fixtures[N-1]:\n    check(label, solve(args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"broken":{"sha256":"e685cd47ac62691fb17e58831fa705d0cf63e19d7e529893ff66f42d6d54cc17","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(x):\n    onhand = x['onhand']\n    avg = x['avg']\n    cogs = []\n    for ev in x['events']:\n        if ev[0] == 'recv':\n            q, c = ev[1], ev[2]\n            total = onhand * avg + q * c\n            units = onhand + q\n            avg = total // units\n            onhand = units\n        else:\n            q = ev[1]\n            if q > onhand:\n                cogs.append('short')\n                continue\n            cogs.append(q * avg)\n            onhand -= q\n    return {'cogs': cogs, 'onhand': onhand, 'avg': avg}\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[['receipt reprices', {'onhand': 10, 'avg': 100, 'events': [['recv', 10, 131], ['issue', 5]]}, {'cogs': [580], 'onhand': 15, 'avg': 116}], ['uneven rounding', {'onhand': 3, 'avg': 10, 'events': [['recv', 4, 12], ['issue', 2], ['issue', 1]]}, {'cogs': [22, 11], 'onhand': 4, 'avg': 11}], ['zero then receipt', {'onhand': 2, 'avg': 50, 'events': [['issue', 2], ['recv', 3, 71], ['issue', 1]]}, {'cogs': [100, 71], 'onhand': 2, 'avg': 71}], ['short issue', {'onhand': 2, 'avg': 50, 'events': [['issue', 4]]}, {'cogs': ['short'], 'onhand': 2, 'avg': 50}], ['many receipts', {'onhand': 0, 'avg': 0, 'events': [['recv', 1, 10], ['recv', 2, 13], ['recv', 1, 20], ['issue', 3]]}, {'cogs': [42], 'onhand': 1, 'avg': 14}], ['half cent', {'onhand': 1, 'avg': 1, 'events': [['recv', 1, 4], ['issue', 1]]}, {'cogs': [3], 'onhand': 1, 'avg': 3}], ['issue all', {'onhand': 4, 'avg': 25, 'events': [['recv', 4, 26], ['issue', 8]]}, {'cogs': [208], 'onhand': 0, 'avg': 26}], ['exact half', {'onhand': 1, 'avg': 2, 'events': [['recv', 1, 3], ['issue', 2]]}, {'cogs': [6], 'onhand': 0, 'avg': 3}]], [['receipt reprices', {'onhand': 10, 'avg': 100, 'events': [['recv', 10, 132], ['issue', 5]]}, {'cogs': [580], 'onhand': 15, 'avg': 116}], ['uneven rounding', {'onhand': 3, 'avg': 10, 'events': [['recv', 4, 13], ['issue', 2], ['issue', 1]]}, {'cogs': [24, 12], 'onhand': 4, 'avg': 12}], ['zero then receipt', {'onhand': 2, 'avg': 50, 'events': [['issue', 2], ['recv', 3, 72], ['issue', 1]]}, {'cogs': [100, 72], 'onhand': 2, 'avg': 72}], ['short issue', {'onhand': 2, 'avg': 50, 'events': [['issue', 5]]}, {'cogs': ['short'], 'onhand': 2, 'avg': 50}], ['many receipts', {'onhand': 0, 'avg': 0, 'events': [['recv', 1, 10], ['recv', 2, 13], ['recv', 2, 20], ['issue', 3]]}, {'cogs': [45], 'onhand': 2, 'avg': 15}], ['half cent', {'onhand': 1, 'avg': 1, 'events': [['recv', 1, 6], ['issue', 1]]}, {'cogs': [4], 'onhand': 1, 'avg': 4}], ['issue all', {'onhand': 4, 'avg': 25, 'events': [['recv', 4, 26], ['issue', 8]]}, {'cogs': [208], 'onhand': 0, 'avg': 26}], ['exact half', {'onhand': 1, 'avg': 4, 'events': [['recv', 1, 5], ['issue', 2]]}, {'cogs': [10], 'onhand': 0, 'avg': 5}]], [['receipt reprices', {'onhand': 10, 'avg': 100, 'events': [['recv', 10, 133], ['issue', 5]]}, {'cogs': [585], 'onhand': 15, 'avg': 117}], ['uneven rounding', {'onhand': 3, 'avg': 10, 'events': [['recv', 4, 14], ['issue', 2], ['issue', 1]]}, {'cogs': [24, 12], 'onhand': 4, 'avg': 12}], ['zero then receipt', {'onhand': 2, 'avg': 50, 'events': [['issue', 2], ['recv', 3, 73], ['issue', 1]]}, {'cogs': [100, 73], 'onhand': 2, 'avg': 73}], ['short issue', {'onhand': 2, 'avg': 50, 'events': [['issue', 6]]}, {'cogs': ['short'], 'onhand': 2, 'avg': 50}], ['many receipts', {'onhand': 0, 'avg': 0, 'events': [['recv', 1, 10], ['recv', 2, 13], ['recv', 3, 20], ['issue', 3]]}, {'cogs': [48], 'onhand': 3, 'avg': 16}], ['half cent', {'onhand': 1, 'avg': 1, 'events': [['recv', 1, 8], ['issue', 1]]}, {'cogs': [5], 'onhand': 1, 'avg': 5}], ['issue all', {'onhand': 4, 'avg': 25, 'events': [['recv', 4, 26], ['issue', 8]]}, {'cogs': [208], 'onhand': 0, 'avg': 26}], ['exact half', {'onhand': 1, 'avg': 6, 'events': [['recv', 1, 7], ['issue', 2]]}, {'cogs': [14], 'onhand': 0, 'avg': 7}]], [['receipt reprices', {'onhand': 10, 'avg': 100, 'events': [['recv', 10, 134], ['issue', 5]]}, {'cogs': [585], 'onhand': 15, 'avg': 117}], ['uneven rounding', {'onhand': 3, 'avg': 10, 'events': [['recv', 4, 15], ['issue', 2], ['issue', 1]]}, {'cogs': [26, 13], 'onhand': 4, 'avg': 13}], ['zero then receipt', {'onhand': 2, 'avg': 50, 'events': [['issue', 2], ['recv', 3, 74], ['issue', 1]]}, {'cogs': [100, 74], 'onhand': 2, 'avg': 74}], ['short issue', {'onhand': 2, 'avg': 50, 'events': [['issue', 7]]}, {'cogs': ['short'], 'onhand': 2, 'avg': 50}], ['many receipts', {'onhand': 0, 'avg': 0, 'events': [['recv', 1, 10], ['recv', 2, 13], ['recv', 4, 20], ['issue', 3]]}, {'cogs': [51], 'onhand': 4, 'avg': 17}], ['half cent', {'onhand': 1, 'avg': 1, 'events': [['recv', 1, 10], ['issue', 1]]}, {'cogs': [6], 'onhand': 1, 'avg': 6}], ['issue all', {'onhand': 4, 'avg': 25, 'events': [['recv', 4, 26], ['issue', 8]]}, {'cogs': [208], 'onhand': 0, 'avg': 26}], ['exact half', {'onhand': 1, 'avg': 8, 'events': [['recv', 1, 9], ['issue', 2]]}, {'cogs': [18], 'onhand': 0, 'avg': 9}]], [['receipt reprices', {'onhand': 10, 'avg': 100, 'events': [['recv', 10, 135], ['issue', 5]]}, {'cogs': [590], 'onhand': 15, 'avg': 118}], ['uneven rounding', {'onhand': 3, 'avg': 10, 'events': [['recv', 4, 16], ['issue', 2], ['issue', 1]]}, {'cogs': [26, 13], 'onhand': 4, 'avg': 13}], ['zero then receipt', {'onhand': 2, 'avg': 50, 'events': [['issue', 2], ['recv', 3, 75], ['issue', 1]]}, {'cogs': [100, 75], 'onhand': 2, 'avg': 75}], ['short issue', {'onhand': 2, 'avg': 50, 'events': [['issue', 8]]}, {'cogs': ['short'], 'onhand': 2, 'avg': 50}], ['many receipts', {'onhand': 0, 'avg': 0, 'events': [['recv', 1, 10], ['recv', 2, 13], ['recv', 5, 20], ['issue', 3]]}, {'cogs': [51], 'onhand': 5, 'avg': 17}], ['half cent', {'onhand': 1, 'avg': 1, 'events': [['recv', 1, 12], ['issue', 1]]}, {'cogs': [7], 'onhand': 1, 'avg': 7}], ['issue all', {'onhand': 4, 'avg': 25, 'events': [['recv', 4, 26], ['issue', 8]]}, {'cogs': [208], 'onhand': 0, 'avg': 26}], ['exact half', {'onhand': 1, 'avg': 10, 'events': [['recv', 1, 11], ['issue', 2]]}, {'cogs': [22], 'onhand': 0, 'avg': 11}]]]\nfor label, args, expected in fixtures[N-1]:\n    check(label, solve(args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"fixed":{"sha256":"67e6cb8e5387bd25d5df753d0f7806504655d24ccaf5bc5c2c2deaea7a239147","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\n\nN = 1\nobservations = []\ndef solve(x):\n    onhand = x['onhand']\n    avg = x['avg']\n    cogs = []\n    for ev in x['events']:\n        if ev[0] == 'recv':\n            q, c = ev[1], ev[2]\n            total = onhand * avg + q * c\n            units = onhand + q\n            avg = (2 * total + units) // (2 * units)\n            onhand = units\n        else:\n            q = ev[1]\n            if q > onhand:\n                cogs.append('short')\n                continue\n            cogs.append(q * avg)\n            onhand -= q\n    return {'cogs': cogs, 'onhand': onhand, 'avg': avg}\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[['receipt reprices', {'onhand': 10, 'avg': 100, 'events': [['recv', 10, 131], ['issue', 5]]}, {'cogs': [580], 'onhand': 15, 'avg': 116}], ['uneven rounding', {'onhand': 3, 'avg': 10, 'events': [['recv', 4, 12], ['issue', 2], ['issue', 1]]}, {'cogs': [22, 11], 'onhand': 4, 'avg': 11}], ['zero then receipt', {'onhand': 2, 'avg': 50, 'events': [['issue', 2], ['recv', 3, 71], ['issue', 1]]}, {'cogs': [100, 71], 'onhand': 2, 'avg': 71}], ['short issue', {'onhand': 2, 'avg': 50, 'events': [['issue', 4]]}, {'cogs': ['short'], 'onhand': 2, 'avg': 50}], ['many receipts', {'onhand': 0, 'avg': 0, 'events': [['recv', 1, 10], ['recv', 2, 13], ['recv', 1, 20], ['issue', 3]]}, {'cogs': [42], 'onhand': 1, 'avg': 14}], ['half cent', {'onhand': 1, 'avg': 1, 'events': [['recv', 1, 4], ['issue', 1]]}, {'cogs': [3], 'onhand': 1, 'avg': 3}], ['issue all', {'onhand': 4, 'avg': 25, 'events': [['recv', 4, 26], ['issue', 8]]}, {'cogs': [208], 'onhand': 0, 'avg': 26}], ['exact half', {'onhand': 1, 'avg': 2, 'events': [['recv', 1, 3], ['issue', 2]]}, {'cogs': [6], 'onhand': 0, 'avg': 3}]], [['receipt reprices', {'onhand': 10, 'avg': 100, 'events': [['recv', 10, 132], ['issue', 5]]}, {'cogs': [580], 'onhand': 15, 'avg': 116}], ['uneven rounding', {'onhand': 3, 'avg': 10, 'events': [['recv', 4, 13], ['issue', 2], ['issue', 1]]}, {'cogs': [24, 12], 'onhand': 4, 'avg': 12}], ['zero then receipt', {'onhand': 2, 'avg': 50, 'events': [['issue', 2], ['recv', 3, 72], ['issue', 1]]}, {'cogs': [100, 72], 'onhand': 2, 'avg': 72}], ['short issue', {'onhand': 2, 'avg': 50, 'events': [['issue', 5]]}, {'cogs': ['short'], 'onhand': 2, 'avg': 50}], ['many receipts', {'onhand': 0, 'avg': 0, 'events': [['recv', 1, 10], ['recv', 2, 13], ['recv', 2, 20], ['issue', 3]]}, {'cogs': [45], 'onhand': 2, 'avg': 15}], ['half cent', {'onhand': 1, 'avg': 1, 'events': [['recv', 1, 6], ['issue', 1]]}, {'cogs': [4], 'onhand': 1, 'avg': 4}], ['issue all', {'onhand': 4, 'avg': 25, 'events': [['recv', 4, 26], ['issue', 8]]}, {'cogs': [208], 'onhand': 0, 'avg': 26}], ['exact half', {'onhand': 1, 'avg': 4, 'events': [['recv', 1, 5], ['issue', 2]]}, {'cogs': [10], 'onhand': 0, 'avg': 5}]], [['receipt reprices', {'onhand': 10, 'avg': 100, 'events': [['recv', 10, 133], ['issue', 5]]}, {'cogs': [585], 'onhand': 15, 'avg': 117}], ['uneven rounding', {'onhand': 3, 'avg': 10, 'events': [['recv', 4, 14], ['issue', 2], ['issue', 1]]}, {'cogs': [24, 12], 'onhand': 4, 'avg': 12}], ['zero then receipt', {'onhand': 2, 'avg': 50, 'events': [['issue', 2], ['recv', 3, 73], ['issue', 1]]}, {'cogs': [100, 73], 'onhand': 2, 'avg': 73}], ['short issue', {'onhand': 2, 'avg': 50, 'events': [['issue', 6]]}, {'cogs': ['short'], 'onhand': 2, 'avg': 50}], ['many receipts', {'onhand': 0, 'avg': 0, 'events': [['recv', 1, 10], ['recv', 2, 13], ['recv', 3, 20], ['issue', 3]]}, {'cogs': [48], 'onhand': 3, 'avg': 16}], ['half cent', {'onhand': 1, 'avg': 1, 'events': [['recv', 1, 8], ['issue', 1]]}, {'cogs': [5], 'onhand': 1, 'avg': 5}], ['issue all', {'onhand': 4, 'avg': 25, 'events': [['recv', 4, 26], ['issue', 8]]}, {'cogs': [208], 'onhand': 0, 'avg': 26}], ['exact half', {'onhand': 1, 'avg': 6, 'events': [['recv', 1, 7], ['issue', 2]]}, {'cogs': [14], 'onhand': 0, 'avg': 7}]], [['receipt reprices', {'onhand': 10, 'avg': 100, 'events': [['recv', 10, 134], ['issue', 5]]}, {'cogs': [585], 'onhand': 15, 'avg': 117}], ['uneven rounding', {'onhand': 3, 'avg': 10, 'events': [['recv', 4, 15], ['issue', 2], ['issue', 1]]}, {'cogs': [26, 13], 'onhand': 4, 'avg': 13}], ['zero then receipt', {'onhand': 2, 'avg': 50, 'events': [['issue', 2], ['recv', 3, 74], ['issue', 1]]}, {'cogs': [100, 74], 'onhand': 2, 'avg': 74}], ['short issue', {'onhand': 2, 'avg': 50, 'events': [['issue', 7]]}, {'cogs': ['short'], 'onhand': 2, 'avg': 50}], ['many receipts', {'onhand': 0, 'avg': 0, 'events': [['recv', 1, 10], ['recv', 2, 13], ['recv', 4, 20], ['issue', 3]]}, {'cogs': [51], 'onhand': 4, 'avg': 17}], ['half cent', {'onhand': 1, 'avg': 1, 'events': [['recv', 1, 10], ['issue', 1]]}, {'cogs': [6], 'onhand': 1, 'avg': 6}], ['issue all', {'onhand': 4, 'avg': 25, 'events': [['recv', 4, 26], ['issue', 8]]}, {'cogs': [208], 'onhand': 0, 'avg': 26}], ['exact half', {'onhand': 1, 'avg': 8, 'events': [['recv', 1, 9], ['issue', 2]]}, {'cogs': [18], 'onhand': 0, 'avg': 9}]], [['receipt reprices', {'onhand': 10, 'avg': 100, 'events': [['recv', 10, 135], ['issue', 5]]}, {'cogs': [590], 'onhand': 15, 'avg': 118}], ['uneven rounding', {'onhand': 3, 'avg': 10, 'events': [['recv', 4, 16], ['issue', 2], ['issue', 1]]}, {'cogs': [26, 13], 'onhand': 4, 'avg': 13}], ['zero then receipt', {'onhand': 2, 'avg': 50, 'events': [['issue', 2], ['recv', 3, 75], ['issue', 1]]}, {'cogs': [100, 75], 'onhand': 2, 'avg': 75}], ['short issue', {'onhand': 2, 'avg': 50, 'events': [['issue', 8]]}, {'cogs': ['short'], 'onhand': 2, 'avg': 50}], ['many receipts', {'onhand': 0, 'avg': 0, 'events': [['recv', 1, 10], ['recv', 2, 13], ['recv', 5, 20], ['issue', 3]]}, {'cogs': [51], 'onhand': 5, 'avg': 17}], ['half cent', {'onhand': 1, 'avg': 1, 'events': [['recv', 1, 12], ['issue', 1]]}, {'cogs': [7], 'onhand': 1, 'avg': 7}], ['issue all', {'onhand': 4, 'avg': 25, 'events': [['recv', 4, 26], ['issue', 8]]}, {'cogs': [208], 'onhand': 0, 'avg': 26}], ['exact half', {'onhand': 1, 'avg': 10, 'events': [['recv', 1, 11], ['issue', 2]]}, {'cogs': [22], 'onhand': 0, 'avg': 11}]]]\nfor label, args, expected in fixtures[N-1]:\n    check(label, solve(args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"}},"limitations":"Stipulated bounded teaching model with explicit toy rules; not an accounting-standard implementation. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.","method":"Deterministic executable model with adversarial boundary fixtures.","provenance":{"created_by":"Failure Map","dependencies":"Python standard library","family":"w2-inventory-cost-layering-moving-average-half-cent-rounding","generated_at":"2026-09-29T14:46:40.728930+00:00","license":"CC0-1.0","python":"3.12.14","seed":1,"split":"open-access"},"relevance":"Inventory valuation and cost-of-goods decisions depend on this rule.","repair":"Round half up: (2*total + units) // (2*units).","root_cause":"The average uses floor division without the half-unit offset.","sha256":"06c7ad3670109e4e69935c93f08e268466bc5e8bea0d5f58a56820cde673e46e","title":"Moving average perpetual costing: half-cent rounding · case 01","variant":1,"variant_policy":"Five numbered records share a model and may reuse boundary fixtures.","verification":{"attempt":{"elapsed_ms":39.908,"exit_code":1,"observations":[{"actual":{"avg":116,"cogs":[580],"onhand":15},"check":"receipt reprices","expected":{"avg":116,"cogs":[580],"onhand":15},"passed":true},{"actual":{"avg":11,"cogs":[22,11],"onhand":4},"check":"uneven rounding","expected":{"avg":11,"cogs":[22,11],"onhand":4},"passed":true},{"actual":{"avg":71,"cogs":[100,71],"onhand":2},"check":"zero then receipt","expected":{"avg":71,"cogs":[100,71],"onhand":2},"passed":true},{"actual":{"avg":50,"cogs":["short"],"onhand":2},"check":"short issue","expected":{"avg":50,"cogs":["short"],"onhand":2},"passed":true},{"actual":{"avg":14,"cogs":[42],"onhand":1},"check":"many receipts","expected":{"avg":14,"cogs":[42],"onhand":1},"passed":true},{"actual":{"avg":2,"cogs":[2],"onhand":1},"check":"half cent","expected":{"avg":3,"cogs":[3],"onhand":1},"passed":false},{"actual":{"avg":26,"cogs":[208],"onhand":0},"check":"issue all","expected":{"avg":26,"cogs":[208],"onhand":0},"passed":true},{"actual":{"avg":2,"cogs":[4],"onhand":0},"check":"exact half","expected":{"avg":3,"cogs":[6],"onhand":0},"passed":false}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"receipt reprices\", \"actual\": {\"cogs\": [580], \"onhand\": 15, \"avg\": 116}, \"expected\": {\"cogs\": [580], \"onhand\": 15, \"avg\": 116}, \"passed\": true}, {\"check\": \"uneven rounding\", \"actual\": {\"cogs\": [22, 11], \"onhand\": 4, \"avg\": 11}, \"expected\": {\"cogs\": [22, 11], \"onhand\": 4, \"avg\": 11}, \"passed\": true}, {\"check\": \"zero then receipt\", \"actual\": {\"cogs\": [100, 71], \"onhand\": 2, \"avg\": 71}, \"expected\": {\"cogs\": [100, 71], \"onhand\": 2, \"avg\": 71}, \"passed\": true}, {\"check\": \"short issue\", \"actual\": {\"cogs\": [\"short\"], \"onhand\": 2, \"avg\": 50}, \"expected\": {\"cogs\": [\"short\"], \"onhand\": 2, \"avg\": 50}, \"passed\": true}, {\"check\": \"many receipts\", \"actual\": {\"cogs\": [42], \"onhand\": 1, \"avg\": 14}, \"expected\": {\"cogs\": [42], \"onhand\": 1, \"avg\": 14}, \"passed\": true}, {\"check\": \"half cent\", \"actual\": {\"cogs\": [2], \"onhand\": 1, \"avg\": 2}, \"expected\": {\"cogs\": [3], \"onhand\": 1, \"avg\": 3}, \"passed\": false}, {\"check\": \"issue all\", \"actual\": {\"cogs\": [208], \"onhand\": 0, \"avg\": 26}, \"expected\": {\"cogs\": [208], \"onhand\": 0, \"avg\": 26}, \"passed\": true}, {\"check\": \"exact half\", \"actual\": {\"cogs\": [4], \"onhand\": 0, \"avg\": 2}, \"expected\": {\"cogs\": [6], \"onhand\": 0, \"avg\": 3}, \"passed\": false}], \"passed\": false}\n"},"broken":{"elapsed_ms":38.976,"exit_code":1,"observations":[{"actual":{"avg":115,"cogs":[575],"onhand":15},"check":"receipt reprices","expected":{"avg":116,"cogs":[580],"onhand":15},"passed":false},{"actual":{"avg":11,"cogs":[22,11],"onhand":4},"check":"uneven rounding","expected":{"avg":11,"cogs":[22,11],"onhand":4},"passed":true},{"actual":{"avg":71,"cogs":[100,71],"onhand":2},"check":"zero then receipt","expected":{"avg":71,"cogs":[100,71],"onhand":2},"passed":true},{"actual":{"avg":50,"cogs":["short"],"onhand":2},"check":"short issue","expected":{"avg":50,"cogs":["short"],"onhand":2},"passed":true},{"actual":{"avg":14,"cogs":[42],"onhand":1},"check":"many receipts","expected":{"avg":14,"cogs":[42],"onhand":1},"passed":true},{"actual":{"avg":2,"cogs":[2],"onhand":1},"check":"half cent","expected":{"avg":3,"cogs":[3],"onhand":1},"passed":false},{"actual":{"avg":25,"cogs":[200],"onhand":0},"check":"issue all","expected":{"avg":26,"cogs":[208],"onhand":0},"passed":false},{"actual":{"avg":2,"cogs":[4],"onhand":0},"check":"exact half","expected":{"avg":3,"cogs":[6],"onhand":0},"passed":false}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"receipt reprices\", \"actual\": {\"cogs\": [575], \"onhand\": 15, \"avg\": 115}, \"expected\": {\"cogs\": [580], \"onhand\": 15, \"avg\": 116}, \"passed\": false}, {\"check\": \"uneven rounding\", \"actual\": {\"cogs\": [22, 11], \"onhand\": 4, \"avg\": 11}, \"expected\": {\"cogs\": [22, 11], \"onhand\": 4, \"avg\": 11}, \"passed\": true}, {\"check\": \"zero then receipt\", \"actual\": {\"cogs\": [100, 71], \"onhand\": 2, \"avg\": 71}, \"expected\": {\"cogs\": [100, 71], \"onhand\": 2, \"avg\": 71}, \"passed\": true}, {\"check\": \"short issue\", \"actual\": {\"cogs\": [\"short\"], \"onhand\": 2, \"avg\": 50}, \"expected\": {\"cogs\": [\"short\"], \"onhand\": 2, \"avg\": 50}, \"passed\": true}, {\"check\": \"many receipts\", \"actual\": {\"cogs\": [42], \"onhand\": 1, \"avg\": 14}, \"expected\": {\"cogs\": [42], \"onhand\": 1, \"avg\": 14}, \"passed\": true}, {\"check\": \"half cent\", \"actual\": {\"cogs\": [2], \"onhand\": 1, \"avg\": 2}, \"expected\": {\"cogs\": [3], \"onhand\": 1, \"avg\": 3}, \"passed\": false}, {\"check\": \"issue all\", \"actual\": {\"cogs\": [200], \"onhand\": 0, \"avg\": 25}, \"expected\": {\"cogs\": [208], \"onhand\": 0, \"avg\": 26}, \"passed\": false}, {\"check\": \"exact half\", \"actual\": {\"cogs\": [4], \"onhand\": 0, \"avg\": 2}, \"expected\": {\"cogs\": [6], \"onhand\": 0, \"avg\": 3}, \"passed\": false}], \"passed\": false}\n"},"fixed":{"elapsed_ms":43.282,"exit_code":0,"observations":[{"actual":{"avg":116,"cogs":[580],"onhand":15},"check":"receipt reprices","expected":{"avg":116,"cogs":[580],"onhand":15},"passed":true},{"actual":{"avg":11,"cogs":[22,11],"onhand":4},"check":"uneven rounding","expected":{"avg":11,"cogs":[22,11],"onhand":4},"passed":true},{"actual":{"avg":71,"cogs":[100,71],"onhand":2},"check":"zero then receipt","expected":{"avg":71,"cogs":[100,71],"onhand":2},"passed":true},{"actual":{"avg":50,"cogs":["short"],"onhand":2},"check":"short issue","expected":{"avg":50,"cogs":["short"],"onhand":2},"passed":true},{"actual":{"avg":14,"cogs":[42],"onhand":1},"check":"many receipts","expected":{"avg":14,"cogs":[42],"onhand":1},"passed":true},{"actual":{"avg":3,"cogs":[3],"onhand":1},"check":"half cent","expected":{"avg":3,"cogs":[3],"onhand":1},"passed":true},{"actual":{"avg":26,"cogs":[208],"onhand":0},"check":"issue all","expected":{"avg":26,"cogs":[208],"onhand":0},"passed":true},{"actual":{"avg":3,"cogs":[6],"onhand":0},"check":"exact half","expected":{"avg":3,"cogs":[6],"onhand":0},"passed":true}],"passed":true,"stderr":"","stdout":"{\"observations\": [{\"check\": \"receipt reprices\", \"actual\": {\"cogs\": [580], \"onhand\": 15, \"avg\": 116}, \"expected\": {\"cogs\": [580], \"onhand\": 15, \"avg\": 116}, \"passed\": true}, {\"check\": \"uneven rounding\", \"actual\": {\"cogs\": [22, 11], \"onhand\": 4, \"avg\": 11}, \"expected\": {\"cogs\": [22, 11], \"onhand\": 4, \"avg\": 11}, \"passed\": true}, {\"check\": \"zero then receipt\", \"actual\": {\"cogs\": [100, 71], \"onhand\": 2, \"avg\": 71}, \"expected\": {\"cogs\": [100, 71], \"onhand\": 2, \"avg\": 71}, \"passed\": true}, {\"check\": \"short issue\", \"actual\": {\"cogs\": [\"short\"], \"onhand\": 2, \"avg\": 50}, \"expected\": {\"cogs\": [\"short\"], \"onhand\": 2, \"avg\": 50}, \"passed\": true}, {\"check\": \"many receipts\", \"actual\": {\"cogs\": [42], \"onhand\": 1, \"avg\": 14}, \"expected\": {\"cogs\": [42], \"onhand\": 1, \"avg\": 14}, \"passed\": true}, {\"check\": \"half cent\", \"actual\": {\"cogs\": [3], \"onhand\": 1, \"avg\": 3}, \"expected\": {\"cogs\": [3], \"onhand\": 1, \"avg\": 3}, \"passed\": true}, {\"check\": \"issue all\", \"actual\": {\"cogs\": [208], \"onhand\": 0, \"avg\": 26}, \"expected\": {\"cogs\": [208], \"onhand\": 0, \"avg\": 26}, \"passed\": true}, {\"check\": \"exact half\", \"actual\": {\"cogs\": [6], \"onhand\": 0, \"avg\": 3}, \"expected\": {\"cogs\": [6], \"onhand\": 0, \"avg\": 3}, \"passed\": true}], \"passed\": true}\n"}},"verified":true,"visibility":"public"}