FA-59891 / Inventory cost layering / Open access
Periodic LIFO year-end layering: negative count rejection · case 01
A negative physical count is accepted and produces negative layers instead of an error.
ROOT CAUSE
The validation only checks the upper bound of the ending quantity.
VERIFIED REPAIR
Reject ending quantities below zero as well as above available units.
Unsuccessful approach: Rejecting only counts below -1 still accepts a count of -1.
Case contract
Input {begin:[[qty,unit]] oldest first, purchases:[[qty,unit]] chronological, ending_qty}. Ending inventory keeps the oldest units: if ending_qty covers the base, all base layers stay and one increment layer is priced at the EARLIEST purchases of the year; otherwise the newest base layers are liquidated. ending_qty outside [0, available] returns {"error"}. Return {layers:[[qty,value]], ending_value, cogs}.
Why this case matters
Inventory valuation and cost-of-goods decisions depend on this rule.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
begin = [list(l) for l in x['begin']]
purchases = x['purchases']
end_q = x['ending_qty']
base_q = sum(l[0] for l in begin)
buy_q = sum(p[0] for p in purchases)
avail = base_q + buy_q
if end_q > avail:
return {'error': 'invalid ending quantity'}
layers = []
if end_q >= base_q:
layers = [[q, q * c] for q, c in begin]
inc = end_q - base_q
new_q = 0
new_v = 0
for q, c in purchases:
if inc == 0:
break
take = min(inc, q)
new_q += take
new_v += take * c
inc -= take
if new_q > 0:
layers.append([new_q, new_v])
else:
rem = end_q
for bq, bc in begin:
take = min(rem, bq)
if take > 0:
layers.append([take, take * bc])
rem -= take
begin_value = sum(q * c for q, c in begin)
buy_value = sum(q * c for q, c in purchases)
ending_value = sum(v for q, v in layers)
return {'layers': layers, 'ending_value': ending_value, 'cogs': begin_value + buy_value - ending_value}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['increment layer', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7], [8, 10]], 'ending_qty': 18}, {'layers': [[10, 50], [4, 24], [4, 28]], 'ending_value': 102, 'cogs': 94}], ['liquidation', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7]], 'ending_qty': 10}, {'layers': [[10, 50]], 'ending_value': 50, 'cogs': 66}], ['deep liquidation', {'begin': [[3, 2], [3, 4], [3, 6]], 'purchases': [[2, 8]], 'ending_qty': 1}, {'layers': [[1, 2]], 'ending_value': 2, 'cogs': 50}], ['over available', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': 6}, {'error': 'invalid ending quantity'}], ['negative ending', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': -1}, {'error': 'invalid ending quantity'}], ['count of minus one', {'begin': [[3, 3]], 'purchases': [[3, 4]], 'ending_qty': -1}, {'error': 'invalid ending quantity'}], ['all sold', {'begin': [[5, 3]], 'purchases': [[5, 4]], 'ending_qty': 0}, {'layers': [], 'ending_value': 0, 'cogs': 35}], ['exact base', {'begin': [[4, 10]], 'purchases': [[1, 11], [2, 12]], 'ending_qty': 4}, {'layers': [[4, 40]], 'ending_value': 40, 'cogs': 35}]], [['increment layer', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7], [8, 11]], 'ending_qty': 19}, {'layers': [[10, 50], [4, 24], [5, 35]], 'ending_value': 109, 'cogs': 95}], ['liquidation', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7]], 'ending_qty': 11}, {'layers': [[10, 50], [1, 6]], 'ending_value': 56, 'cogs': 60}], ['deep liquidation', {'begin': [[3, 2], [3, 4], [3, 6]], 'purchases': [[2, 8]], 'ending_qty': 2}, {'layers': [[2, 4]], 'ending_value': 4, 'cogs': 48}], ['over available', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': 7}, {'error': 'invalid ending quantity'}], ['negative ending', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': -2}, {'error': 'invalid ending quantity'}], ['count of minus one', {'begin': [[4, 3]], 'purchases': [[3, 4]], 'ending_qty': -1}, {'error': 'invalid ending quantity'}], ['all sold', {'begin': [[5, 3]], 'purchases': [[5, 4]], 'ending_qty': 0}, {'layers': [], 'ending_value': 0, 'cogs': 35}], ['exact base', {'begin': [[4, 10]], 'purchases': [[2, 11], [2, 12]], 'ending_qty': 4}, {'layers': [[4, 40]], 'ending_value': 40, 'cogs': 46}]], [['increment layer', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7], [8, 12]], 'ending_qty': 17}, {'layers': [[10, 50], [4, 24], [3, 21]], 'ending_value': 95, 'cogs': 117}], ['liquidation', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7]], 'ending_qty': 10}, {'layers': [[10, 50]], 'ending_value': 50, 'cogs': 66}], ['deep liquidation', {'begin': [[3, 2], [3, 4], [3, 6]], 'purchases': [[2, 8]], 'ending_qty': 3}, {'layers': [[3, 6]], 'ending_value': 6, 'cogs': 46}], ['over available', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': 8}, {'error': 'invalid ending quantity'}], ['negative ending', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': -3}, {'error': 'invalid ending quantity'}], ['count of minus one', {'begin': [[5, 3]], 'purchases': [[3, 4]], 'ending_qty': -1}, {'error': 'invalid ending quantity'}], ['all sold', {'begin': [[5, 3]], 'purchases': [[5, 4]], 'ending_qty': 0}, {'layers': [], 'ending_value': 0, 'cogs': 35}], ['exact base', {'begin': [[4, 10]], 'purchases': [[3, 11], [2, 12]], 'ending_qty': 4}, {'layers': [[4, 40]], 'ending_value': 40, 'cogs': 57}]], [['increment layer', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7], [8, 13]], 'ending_qty': 18}, {'layers': [[10, 50], [4, 24], [4, 28]], 'ending_value': 102, 'cogs': 118}], ['liquidation', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7]], 'ending_qty': 11}, {'layers': [[10, 50], [1, 6]], 'ending_value': 56, 'cogs': 60}], ['deep liquidation', {'begin': [[3, 2], [3, 4], [3, 6]], 'purchases': [[2, 8]], 'ending_qty': 4}, {'layers': [[3, 6], [1, 4]], 'ending_value': 10, 'cogs': 42}], ['over available', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': 9}, {'error': 'invalid ending quantity'}], ['negative ending', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': -4}, {'error': 'invalid ending quantity'}], ['count of minus one', {'begin': [[6, 3]], 'purchases': [[3, 4]], 'ending_qty': -1}, {'error': 'invalid ending quantity'}], ['all sold', {'begin': [[5, 3]], 'purchases': [[5, 4]], 'ending_qty': 0}, {'layers': [], 'ending_value': 0, 'cogs': 35}], ['exact base', {'begin': [[4, 10]], 'purchases': [[4, 11], [2, 12]], 'ending_qty': 4}, {'layers': [[4, 40]], 'ending_value': 40, 'cogs': 68}]], [['increment layer', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7], [8, 14]], 'ending_qty': 19}, {'layers': [[10, 50], [4, 24], [5, 35]], 'ending_value': 109, 'cogs': 119}], ['liquidation', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7]], 'ending_qty': 10}, {'layers': [[10, 50]], 'ending_value': 50, 'cogs': 66}], ['deep liquidation', {'begin': [[3, 2], [3, 4], [3, 6]], 'purchases': [[2, 8]], 'ending_qty': 5}, {'layers': [[3, 6], [2, 8]], 'ending_value': 14, 'cogs': 38}], ['over available', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': 10}, {'error': 'invalid ending quantity'}], ['negative ending', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': -5}, {'error': 'invalid ending quantity'}], ['count of minus one', {'begin': [[7, 3]], 'purchases': [[3, 4]], 'ending_qty': -1}, {'error': 'invalid ending quantity'}], ['all sold', {'begin': [[5, 3]], 'purchases': [[5, 4]], 'ending_qty': 0}, {'layers': [], 'ending_value': 0, 'cogs': 35}], ['exact base', {'begin': [[4, 10]], 'purchases': [[5, 11], [2, 12]], 'ending_qty': 4}, {'layers': [[4, 40]], 'ending_value': 40, 'cogs': 79}]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| increment layer | {'cogs': 94, 'ending_value': 102, 'layers': [[10, 50], [4, 24], [4, 28]]} | {'cogs': 94, 'ending_value': 102, 'layers': [[10, 50], [4, 24], [4, 28]]} | Passed |
| liquidation | {'cogs': 66, 'ending_value': 50, 'layers': [[10, 50]]} | {'cogs': 66, 'ending_value': 50, 'layers': [[10, 50]]} | Passed |
| deep liquidation | {'cogs': 50, 'ending_value': 2, 'layers': [[1, 2]]} | {'cogs': 50, 'ending_value': 2, 'layers': [[1, 2]]} | Passed |
| over available | {'error': 'invalid ending quantity'} | {'error': 'invalid ending quantity'} | Passed |
| negative ending | {'cogs': 18, 'ending_value': 0, 'layers': []} | {'error': 'invalid ending quantity'} | Failed |
| count of minus one | {'cogs': 21, 'ending_value': 0, 'layers': []} | {'error': 'invalid ending quantity'} | Failed |
| all sold | {'cogs': 35, 'ending_value': 0, 'layers': []} | {'cogs': 35, 'ending_value': 0, 'layers': []} | Passed |
| exact base | {'cogs': 35, 'ending_value': 40, 'layers': [[4, 40]]} | {'cogs': 35, 'ending_value': 40, 'layers': [[4, 40]]} | Passed |
SHA-256 / 01905b5aedf76c7f6052ac0ec95f66445c7252be0774b644882f9e8a09722fbb
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
begin = [list(l) for l in x['begin']]
purchases = x['purchases']
end_q = x['ending_qty']
base_q = sum(l[0] for l in begin)
buy_q = sum(p[0] for p in purchases)
avail = base_q + buy_q
if end_q < -1 or end_q > avail:
return {'error': 'invalid ending quantity'}
layers = []
if end_q >= base_q:
layers = [[q, q * c] for q, c in begin]
inc = end_q - base_q
new_q = 0
new_v = 0
for q, c in purchases:
if inc == 0:
break
take = min(inc, q)
new_q += take
new_v += take * c
inc -= take
if new_q > 0:
layers.append([new_q, new_v])
else:
rem = end_q
for bq, bc in begin:
take = min(rem, bq)
if take > 0:
layers.append([take, take * bc])
rem -= take
begin_value = sum(q * c for q, c in begin)
buy_value = sum(q * c for q, c in purchases)
ending_value = sum(v for q, v in layers)
return {'layers': layers, 'ending_value': ending_value, 'cogs': begin_value + buy_value - ending_value}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['increment layer', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7], [8, 10]], 'ending_qty': 18}, {'layers': [[10, 50], [4, 24], [4, 28]], 'ending_value': 102, 'cogs': 94}], ['liquidation', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7]], 'ending_qty': 10}, {'layers': [[10, 50]], 'ending_value': 50, 'cogs': 66}], ['deep liquidation', {'begin': [[3, 2], [3, 4], [3, 6]], 'purchases': [[2, 8]], 'ending_qty': 1}, {'layers': [[1, 2]], 'ending_value': 2, 'cogs': 50}], ['over available', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': 6}, {'error': 'invalid ending quantity'}], ['negative ending', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': -1}, {'error': 'invalid ending quantity'}], ['count of minus one', {'begin': [[3, 3]], 'purchases': [[3, 4]], 'ending_qty': -1}, {'error': 'invalid ending quantity'}], ['all sold', {'begin': [[5, 3]], 'purchases': [[5, 4]], 'ending_qty': 0}, {'layers': [], 'ending_value': 0, 'cogs': 35}], ['exact base', {'begin': [[4, 10]], 'purchases': [[1, 11], [2, 12]], 'ending_qty': 4}, {'layers': [[4, 40]], 'ending_value': 40, 'cogs': 35}]], [['increment layer', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7], [8, 11]], 'ending_qty': 19}, {'layers': [[10, 50], [4, 24], [5, 35]], 'ending_value': 109, 'cogs': 95}], ['liquidation', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7]], 'ending_qty': 11}, {'layers': [[10, 50], [1, 6]], 'ending_value': 56, 'cogs': 60}], ['deep liquidation', {'begin': [[3, 2], [3, 4], [3, 6]], 'purchases': [[2, 8]], 'ending_qty': 2}, {'layers': [[2, 4]], 'ending_value': 4, 'cogs': 48}], ['over available', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': 7}, {'error': 'invalid ending quantity'}], ['negative ending', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': -2}, {'error': 'invalid ending quantity'}], ['count of minus one', {'begin': [[4, 3]], 'purchases': [[3, 4]], 'ending_qty': -1}, {'error': 'invalid ending quantity'}], ['all sold', {'begin': [[5, 3]], 'purchases': [[5, 4]], 'ending_qty': 0}, {'layers': [], 'ending_value': 0, 'cogs': 35}], ['exact base', {'begin': [[4, 10]], 'purchases': [[2, 11], [2, 12]], 'ending_qty': 4}, {'layers': [[4, 40]], 'ending_value': 40, 'cogs': 46}]], [['increment layer', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7], [8, 12]], 'ending_qty': 17}, {'layers': [[10, 50], [4, 24], [3, 21]], 'ending_value': 95, 'cogs': 117}], ['liquidation', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7]], 'ending_qty': 10}, {'layers': [[10, 50]], 'ending_value': 50, 'cogs': 66}], ['deep liquidation', {'begin': [[3, 2], [3, 4], [3, 6]], 'purchases': [[2, 8]], 'ending_qty': 3}, {'layers': [[3, 6]], 'ending_value': 6, 'cogs': 46}], ['over available', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': 8}, {'error': 'invalid ending quantity'}], ['negative ending', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': -3}, {'error': 'invalid ending quantity'}], ['count of minus one', {'begin': [[5, 3]], 'purchases': [[3, 4]], 'ending_qty': -1}, {'error': 'invalid ending quantity'}], ['all sold', {'begin': [[5, 3]], 'purchases': [[5, 4]], 'ending_qty': 0}, {'layers': [], 'ending_value': 0, 'cogs': 35}], ['exact base', {'begin': [[4, 10]], 'purchases': [[3, 11], [2, 12]], 'ending_qty': 4}, {'layers': [[4, 40]], 'ending_value': 40, 'cogs': 57}]], [['increment layer', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7], [8, 13]], 'ending_qty': 18}, {'layers': [[10, 50], [4, 24], [4, 28]], 'ending_value': 102, 'cogs': 118}], ['liquidation', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7]], 'ending_qty': 11}, {'layers': [[10, 50], [1, 6]], 'ending_value': 56, 'cogs': 60}], ['deep liquidation', {'begin': [[3, 2], [3, 4], [3, 6]], 'purchases': [[2, 8]], 'ending_qty': 4}, {'layers': [[3, 6], [1, 4]], 'ending_value': 10, 'cogs': 42}], ['over available', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': 9}, {'error': 'invalid ending quantity'}], ['negative ending', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': -4}, {'error': 'invalid ending quantity'}], ['count of minus one', {'begin': [[6, 3]], 'purchases': [[3, 4]], 'ending_qty': -1}, {'error': 'invalid ending quantity'}], ['all sold', {'begin': [[5, 3]], 'purchases': [[5, 4]], 'ending_qty': 0}, {'layers': [], 'ending_value': 0, 'cogs': 35}], ['exact base', {'begin': [[4, 10]], 'purchases': [[4, 11], [2, 12]], 'ending_qty': 4}, {'layers': [[4, 40]], 'ending_value': 40, 'cogs': 68}]], [['increment layer', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7], [8, 14]], 'ending_qty': 19}, {'layers': [[10, 50], [4, 24], [5, 35]], 'ending_value': 109, 'cogs': 119}], ['liquidation', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7]], 'ending_qty': 10}, {'layers': [[10, 50]], 'ending_value': 50, 'cogs': 66}], ['deep liquidation', {'begin': [[3, 2], [3, 4], [3, 6]], 'purchases': [[2, 8]], 'ending_qty': 5}, {'layers': [[3, 6], [2, 8]], 'ending_value': 14, 'cogs': 38}], ['over available', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': 10}, {'error': 'invalid ending quantity'}], ['negative ending', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': -5}, {'error': 'invalid ending quantity'}], ['count of minus one', {'begin': [[7, 3]], 'purchases': [[3, 4]], 'ending_qty': -1}, {'error': 'invalid ending quantity'}], ['all sold', {'begin': [[5, 3]], 'purchases': [[5, 4]], 'ending_qty': 0}, {'layers': [], 'ending_value': 0, 'cogs': 35}], ['exact base', {'begin': [[4, 10]], 'purchases': [[5, 11], [2, 12]], 'ending_qty': 4}, {'layers': [[4, 40]], 'ending_value': 40, 'cogs': 79}]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| increment layer | {'cogs': 94, 'ending_value': 102, 'layers': [[10, 50], [4, 24], [4, 28]]} | {'cogs': 94, 'ending_value': 102, 'layers': [[10, 50], [4, 24], [4, 28]]} | Passed |
| liquidation | {'cogs': 66, 'ending_value': 50, 'layers': [[10, 50]]} | {'cogs': 66, 'ending_value': 50, 'layers': [[10, 50]]} | Passed |
| deep liquidation | {'cogs': 50, 'ending_value': 2, 'layers': [[1, 2]]} | {'cogs': 50, 'ending_value': 2, 'layers': [[1, 2]]} | Passed |
| over available | {'error': 'invalid ending quantity'} | {'error': 'invalid ending quantity'} | Passed |
| negative ending | {'cogs': 18, 'ending_value': 0, 'layers': []} | {'error': 'invalid ending quantity'} | Failed |
| count of minus one | {'cogs': 21, 'ending_value': 0, 'layers': []} | {'error': 'invalid ending quantity'} | Failed |
| all sold | {'cogs': 35, 'ending_value': 0, 'layers': []} | {'cogs': 35, 'ending_value': 0, 'layers': []} | Passed |
| exact base | {'cogs': 35, 'ending_value': 40, 'layers': [[4, 40]]} | {'cogs': 35, 'ending_value': 40, 'layers': [[4, 40]]} | Passed |
SHA-256 / 5c28c6bb5b9fdf182454e4fc61815fddf158d1ae9b1e5b5ab5a5e19faa0e76bf
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
begin = [list(l) for l in x['begin']]
purchases = x['purchases']
end_q = x['ending_qty']
base_q = sum(l[0] for l in begin)
buy_q = sum(p[0] for p in purchases)
avail = base_q + buy_q
if end_q < 0 or end_q > avail:
return {'error': 'invalid ending quantity'}
layers = []
if end_q >= base_q:
layers = [[q, q * c] for q, c in begin]
inc = end_q - base_q
new_q = 0
new_v = 0
for q, c in purchases:
if inc == 0:
break
take = min(inc, q)
new_q += take
new_v += take * c
inc -= take
if new_q > 0:
layers.append([new_q, new_v])
else:
rem = end_q
for bq, bc in begin:
take = min(rem, bq)
if take > 0:
layers.append([take, take * bc])
rem -= take
begin_value = sum(q * c for q, c in begin)
buy_value = sum(q * c for q, c in purchases)
ending_value = sum(v for q, v in layers)
return {'layers': layers, 'ending_value': ending_value, 'cogs': begin_value + buy_value - ending_value}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['increment layer', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7], [8, 10]], 'ending_qty': 18}, {'layers': [[10, 50], [4, 24], [4, 28]], 'ending_value': 102, 'cogs': 94}], ['liquidation', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7]], 'ending_qty': 10}, {'layers': [[10, 50]], 'ending_value': 50, 'cogs': 66}], ['deep liquidation', {'begin': [[3, 2], [3, 4], [3, 6]], 'purchases': [[2, 8]], 'ending_qty': 1}, {'layers': [[1, 2]], 'ending_value': 2, 'cogs': 50}], ['over available', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': 6}, {'error': 'invalid ending quantity'}], ['negative ending', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': -1}, {'error': 'invalid ending quantity'}], ['count of minus one', {'begin': [[3, 3]], 'purchases': [[3, 4]], 'ending_qty': -1}, {'error': 'invalid ending quantity'}], ['all sold', {'begin': [[5, 3]], 'purchases': [[5, 4]], 'ending_qty': 0}, {'layers': [], 'ending_value': 0, 'cogs': 35}], ['exact base', {'begin': [[4, 10]], 'purchases': [[1, 11], [2, 12]], 'ending_qty': 4}, {'layers': [[4, 40]], 'ending_value': 40, 'cogs': 35}]], [['increment layer', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7], [8, 11]], 'ending_qty': 19}, {'layers': [[10, 50], [4, 24], [5, 35]], 'ending_value': 109, 'cogs': 95}], ['liquidation', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7]], 'ending_qty': 11}, {'layers': [[10, 50], [1, 6]], 'ending_value': 56, 'cogs': 60}], ['deep liquidation', {'begin': [[3, 2], [3, 4], [3, 6]], 'purchases': [[2, 8]], 'ending_qty': 2}, {'layers': [[2, 4]], 'ending_value': 4, 'cogs': 48}], ['over available', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': 7}, {'error': 'invalid ending quantity'}], ['negative ending', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': -2}, {'error': 'invalid ending quantity'}], ['count of minus one', {'begin': [[4, 3]], 'purchases': [[3, 4]], 'ending_qty': -1}, {'error': 'invalid ending quantity'}], ['all sold', {'begin': [[5, 3]], 'purchases': [[5, 4]], 'ending_qty': 0}, {'layers': [], 'ending_value': 0, 'cogs': 35}], ['exact base', {'begin': [[4, 10]], 'purchases': [[2, 11], [2, 12]], 'ending_qty': 4}, {'layers': [[4, 40]], 'ending_value': 40, 'cogs': 46}]], [['increment layer', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7], [8, 12]], 'ending_qty': 17}, {'layers': [[10, 50], [4, 24], [3, 21]], 'ending_value': 95, 'cogs': 117}], ['liquidation', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7]], 'ending_qty': 10}, {'layers': [[10, 50]], 'ending_value': 50, 'cogs': 66}], ['deep liquidation', {'begin': [[3, 2], [3, 4], [3, 6]], 'purchases': [[2, 8]], 'ending_qty': 3}, {'layers': [[3, 6]], 'ending_value': 6, 'cogs': 46}], ['over available', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': 8}, {'error': 'invalid ending quantity'}], ['negative ending', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': -3}, {'error': 'invalid ending quantity'}], ['count of minus one', {'begin': [[5, 3]], 'purchases': [[3, 4]], 'ending_qty': -1}, {'error': 'invalid ending quantity'}], ['all sold', {'begin': [[5, 3]], 'purchases': [[5, 4]], 'ending_qty': 0}, {'layers': [], 'ending_value': 0, 'cogs': 35}], ['exact base', {'begin': [[4, 10]], 'purchases': [[3, 11], [2, 12]], 'ending_qty': 4}, {'layers': [[4, 40]], 'ending_value': 40, 'cogs': 57}]], [['increment layer', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7], [8, 13]], 'ending_qty': 18}, {'layers': [[10, 50], [4, 24], [4, 28]], 'ending_value': 102, 'cogs': 118}], ['liquidation', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7]], 'ending_qty': 11}, {'layers': [[10, 50], [1, 6]], 'ending_value': 56, 'cogs': 60}], ['deep liquidation', {'begin': [[3, 2], [3, 4], [3, 6]], 'purchases': [[2, 8]], 'ending_qty': 4}, {'layers': [[3, 6], [1, 4]], 'ending_value': 10, 'cogs': 42}], ['over available', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': 9}, {'error': 'invalid ending quantity'}], ['negative ending', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': -4}, {'error': 'invalid ending quantity'}], ['count of minus one', {'begin': [[6, 3]], 'purchases': [[3, 4]], 'ending_qty': -1}, {'error': 'invalid ending quantity'}], ['all sold', {'begin': [[5, 3]], 'purchases': [[5, 4]], 'ending_qty': 0}, {'layers': [], 'ending_value': 0, 'cogs': 35}], ['exact base', {'begin': [[4, 10]], 'purchases': [[4, 11], [2, 12]], 'ending_qty': 4}, {'layers': [[4, 40]], 'ending_value': 40, 'cogs': 68}]], [['increment layer', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7], [8, 14]], 'ending_qty': 19}, {'layers': [[10, 50], [4, 24], [5, 35]], 'ending_value': 109, 'cogs': 119}], ['liquidation', {'begin': [[10, 5], [4, 6]], 'purchases': [[6, 7]], 'ending_qty': 10}, {'layers': [[10, 50]], 'ending_value': 50, 'cogs': 66}], ['deep liquidation', {'begin': [[3, 2], [3, 4], [3, 6]], 'purchases': [[2, 8]], 'ending_qty': 5}, {'layers': [[3, 6], [2, 8]], 'ending_value': 14, 'cogs': 38}], ['over available', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': 10}, {'error': 'invalid ending quantity'}], ['negative ending', {'begin': [[2, 3]], 'purchases': [[3, 4]], 'ending_qty': -5}, {'error': 'invalid ending quantity'}], ['count of minus one', {'begin': [[7, 3]], 'purchases': [[3, 4]], 'ending_qty': -1}, {'error': 'invalid ending quantity'}], ['all sold', {'begin': [[5, 3]], 'purchases': [[5, 4]], 'ending_qty': 0}, {'layers': [], 'ending_value': 0, 'cogs': 35}], ['exact base', {'begin': [[4, 10]], 'purchases': [[5, 11], [2, 12]], 'ending_qty': 4}, {'layers': [[4, 40]], 'ending_value': 40, 'cogs': 79}]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| increment layer | {'cogs': 94, 'ending_value': 102, 'layers': [[10, 50], [4, 24], [4, 28]]} | {'cogs': 94, 'ending_value': 102, 'layers': [[10, 50], [4, 24], [4, 28]]} | Passed |
| liquidation | {'cogs': 66, 'ending_value': 50, 'layers': [[10, 50]]} | {'cogs': 66, 'ending_value': 50, 'layers': [[10, 50]]} | Passed |
| deep liquidation | {'cogs': 50, 'ending_value': 2, 'layers': [[1, 2]]} | {'cogs': 50, 'ending_value': 2, 'layers': [[1, 2]]} | Passed |
| over available | {'error': 'invalid ending quantity'} | {'error': 'invalid ending quantity'} | Passed |
| negative ending | {'error': 'invalid ending quantity'} | {'error': 'invalid ending quantity'} | Passed |
| count of minus one | {'error': 'invalid ending quantity'} | {'error': 'invalid ending quantity'} | Passed |
| all sold | {'cogs': 35, 'ending_value': 0, 'layers': []} | {'cogs': 35, 'ending_value': 0, 'layers': []} | Passed |
| exact base | {'cogs': 35, 'ending_value': 40, 'layers': [[4, 40]]} | {'cogs': 35, 'ending_value': 40, 'layers': [[4, 40]]} | Passed |
SHA-256 / 953c6075f67fa22ecf38b9c8df39830879a6138b4ac3c2f1f900c8918d8a2ff7
Verification & scope
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.
Observations recorded using Python 3.12.14 at 2026-09-29T14:46:40.478213+00:00.
Case digest / 4629bc8a7ba68ef52ef664de5b89775bd4e3d62d18142c3a5205f32592860483