FAILURE MAP
← Case archive

FA-58102 / Double-entry ledger accounting / Member archive

FIFO perpetual inventory journal: return layer selection · case 02

Purchase returns remove units from the oldest matching layer.

Member previewVariant 2 · 3 implementations · 7 checks per implementation

Case contract

x = [['buy', qty, unit_cost] | ['sell', qty, unit_price] | ['purchase_return', qty, unit_cost]]. Layers are kept oldest first; a buy at the same cost as the newest layer merges into it. A sale consumes layers oldest first (COGS) and records revenue; a sale exceeding on-hand quantity is rejected whole. A purchase return removes qty from the newest layer at that cost holding at least qty, else it is rejected. Emptied layers are removed. Return {'cogs', 'revenue', 'inventory': sum qty*cost, 'layers', 'rejected': event indexes}.

Why this case matters

Ledger software must keep debits equal to credits and apply normal-balance, period and cutoff rules exactly; small sign or boundary slips silently misstate financial statements.

One recorded failure

Sample boundary fixture

This sample comes from the broken implementation of a controlled reproducer.

Boundary fixtureActualExpectedOutcome
regression: return layer selection{"cogs": 0, "inventory": 2690, "layers": [[7, 100], [5, 150], [10, 100], [2, 120]], "rejected": [], "revenue": 0}{"cogs": 0, "inventory": 2690, "layers": [[9, 100], [5, 150], [8, 100], [2, 120]], "rejected": [], "revenue": 0}Failed

MEMBER ARCHIVE

The complete case is available to members.

This record includes three runnable implementations, regression fixtures, execution results, and source hashes.

Member access is invitation-based. Sign in with your invited account to inspect the sources.

Sign in to the archive ↗