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

N = 1
observations = []
def solve(x):
    amt = x['amount']
    b = x['behavior']
    if b == 'none':
        return [0, x['pending'], 0]
    if b == 'always_invoice':
        due = amt
        return [max(0, due), 0, max(0, -due)]
    return [0, x['pending'] + amt, 0]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'behavior': 'always_invoice', 'amount': -4898, 'pending': -2365}, [0, 0, 7263]), ('regression', {'behavior': 'always_invoice', 'amount': 603, 'pending': -721}, [0, 0, 118]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': -1436, 'pending': -1622}, [0, 0, 3058]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': -2445, 'pending': -199}, [0, 0, 2644]), ('normal control', {'behavior': 'none', 'amount': 418, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'none', 'amount': 3140, 'pending': 2478}, [0, 2478, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': -2033, 'pending': -1935}, [0, -3968, 0]), ('normal control', {'behavior': 'none', 'amount': -1187, 'pending': 1574}, [0, 1574, 0])], [('regression', {'behavior': 'always_invoice', 'amount': 603, 'pending': -721}, [0, 0, 118]), ('regression', {'behavior': 'always_invoice', 'amount': 5024, 'pending': 409}, [5433, 0, 0]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': -1436, 'pending': -1622}, [0, 0, 3058]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': -2445, 'pending': -199}, [0, 0, 2644]), ('normal control', {'behavior': 'always_invoice', 'amount': 3806, 'pending': 0}, [3806, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': -2749, 'pending': -1837}, [0, -4586, 0]), ('normal control', {'behavior': 'none', 'amount': -2844, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': 7165, 'pending': -991}, [0, 6174, 0])], [('regression', {'behavior': 'always_invoice', 'amount': -1436, 'pending': -1622}, [0, 0, 3058]), ('regression', {'behavior': 'always_invoice', 'amount': 5024, 'pending': 409}, [5433, 0, 0]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': -751, 'pending': -1872}, [0, 0, 2623]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': -2058, 'pending': -1659}, [0, 0, 3717]), ('normal control', {'behavior': 'always_invoice', 'amount': 883, 'pending': 0}, [883, 0, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 758, 'pending': 0}, [758, 0, 0]), ('normal control', {'behavior': 'none', 'amount': -2370, 'pending': -876}, [0, -876, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 3888, 'pending': 0}, [3888, 0, 0])], [('regression', {'behavior': 'always_invoice', 'amount': -2445, 'pending': -199}, [0, 0, 2644]), ('regression', {'behavior': 'always_invoice', 'amount': -1436, 'pending': -1622}, [0, 0, 3058]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': 5208, 'pending': -1138}, [4070, 0, 0]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': 6787, 'pending': -1826}, [4961, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': 5304, 'pending': -1989}, [0, 3315, 0]), ('normal control', {'behavior': 'none', 'amount': 557, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'none', 'amount': -2879, 'pending': -1049}, [0, -1049, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': 5860, 'pending': -2357}, [0, 3503, 0])], [('regression', {'behavior': 'always_invoice', 'amount': -751, 'pending': -1872}, [0, 0, 2623]), ('regression', {'behavior': 'always_invoice', 'amount': 6428, 'pending': 2242}, [8670, 0, 0]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': 2515, 'pending': -1623}, [892, 0, 0]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': -1535, 'pending': -2189}, [0, 0, 3724]), ('normal control', {'behavior': 'create_prorations', 'amount': -1700, 'pending': 0}, [0, -1700, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': -2824, 'pending': 2220}, [0, -604, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': 3999, 'pending': 3774}, [0, 7773, 0]), ('normal control', {'behavior': 'none', 'amount': -2062, 'pending': 0}, [0, 0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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)

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

N = 1
observations = []
def solve(x):
    amt = x['amount']
    b = x['behavior']
    if b == 'none':
        return [0, x['pending'], 0]
    if b == 'always_invoice':
        due = x['pending'] + amt if x['pending'] > 0 else amt
        return [max(0, due), 0, max(0, -due)]
    return [0, x['pending'] + amt, 0]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'behavior': 'always_invoice', 'amount': -4898, 'pending': -2365}, [0, 0, 7263]), ('regression', {'behavior': 'always_invoice', 'amount': 603, 'pending': -721}, [0, 0, 118]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': -1436, 'pending': -1622}, [0, 0, 3058]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': -2445, 'pending': -199}, [0, 0, 2644]), ('normal control', {'behavior': 'none', 'amount': 418, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'none', 'amount': 3140, 'pending': 2478}, [0, 2478, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': -2033, 'pending': -1935}, [0, -3968, 0]), ('normal control', {'behavior': 'none', 'amount': -1187, 'pending': 1574}, [0, 1574, 0])], [('regression', {'behavior': 'always_invoice', 'amount': 603, 'pending': -721}, [0, 0, 118]), ('regression', {'behavior': 'always_invoice', 'amount': 5024, 'pending': 409}, [5433, 0, 0]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': -1436, 'pending': -1622}, [0, 0, 3058]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': -2445, 'pending': -199}, [0, 0, 2644]), ('normal control', {'behavior': 'always_invoice', 'amount': 3806, 'pending': 0}, [3806, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': -2749, 'pending': -1837}, [0, -4586, 0]), ('normal control', {'behavior': 'none', 'amount': -2844, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': 7165, 'pending': -991}, [0, 6174, 0])], [('regression', {'behavior': 'always_invoice', 'amount': -1436, 'pending': -1622}, [0, 0, 3058]), ('regression', {'behavior': 'always_invoice', 'amount': 5024, 'pending': 409}, [5433, 0, 0]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': -751, 'pending': -1872}, [0, 0, 2623]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': -2058, 'pending': -1659}, [0, 0, 3717]), ('normal control', {'behavior': 'always_invoice', 'amount': 883, 'pending': 0}, [883, 0, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 758, 'pending': 0}, [758, 0, 0]), ('normal control', {'behavior': 'none', 'amount': -2370, 'pending': -876}, [0, -876, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 3888, 'pending': 0}, [3888, 0, 0])], [('regression', {'behavior': 'always_invoice', 'amount': -2445, 'pending': -199}, [0, 0, 2644]), ('regression', {'behavior': 'always_invoice', 'amount': -1436, 'pending': -1622}, [0, 0, 3058]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': 5208, 'pending': -1138}, [4070, 0, 0]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': 6787, 'pending': -1826}, [4961, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': 5304, 'pending': -1989}, [0, 3315, 0]), ('normal control', {'behavior': 'none', 'amount': 557, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'none', 'amount': -2879, 'pending': -1049}, [0, -1049, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': 5860, 'pending': -2357}, [0, 3503, 0])], [('regression', {'behavior': 'always_invoice', 'amount': -751, 'pending': -1872}, [0, 0, 2623]), ('regression', {'behavior': 'always_invoice', 'amount': 6428, 'pending': 2242}, [8670, 0, 0]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': 2515, 'pending': -1623}, [892, 0, 0]), ('partial-repair probe', {'behavior': 'always_invoice', 'amount': -1535, 'pending': -2189}, [0, 0, 3724]), ('normal control', {'behavior': 'create_prorations', 'amount': -1700, 'pending': 0}, [0, -1700, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': -2824, 'pending': 2220}, [0, -604, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': 3999, 'pending': 3774}, [0, 7773, 0]), ('normal control', {'behavior': 'none', 'amount': -2062, 'pending': 0}, [0, 0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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)

prompt:
Pending proration items vanish when a later change is invoiced immediately.

Input {behavior create_prorations|none|always_invoice, amount (net new proration), pending (existing pending items)}. none: nothing is created and pending is untouched. create_prorations: amount joins pending for the next renewal invoice. always_invoice: pending plus amount are invoiced now; a negative total becomes a credit. Return [invoiced_now, pending_after, credited].

split: open-access


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

N = 1
observations = []
def solve(x):
    amt = x['amount']
    b = x['behavior']
    if b == 'none':
        return [0, 0, 0]
    if b == 'always_invoice':
        due = x['pending'] + amt
        return [max(0, due), 0, max(0, -due)]
    return [0, x['pending'] + amt, 0]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'behavior': 'none', 'amount': 3140, 'pending': 2478}, [0, 2478, 0]), ('regression', {'behavior': 'none', 'amount': -1187, 'pending': 1574}, [0, 1574, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': 418, 'pending': 0}, [0, 0, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': -2844, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': -2033, 'pending': -1935}, [0, -3968, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 3806, 'pending': 0}, [3806, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': -2749, 'pending': -1837}, [0, -4586, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': 7165, 'pending': -991}, [0, 6174, 0])], [('regression', {'behavior': 'none', 'amount': -1187, 'pending': 1574}, [0, 1574, 0]), ('regression', {'behavior': 'none', 'amount': -2370, 'pending': -876}, [0, -876, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': -2844, 'pending': 0}, [0, 0, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': 557, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 883, 'pending': 0}, [883, 0, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 758, 'pending': 0}, [758, 0, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 3888, 'pending': 0}, [3888, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': 5304, 'pending': -1989}, [0, 3315, 0])], [('regression', {'behavior': 'none', 'amount': -2370, 'pending': -876}, [0, -876, 0]), ('regression', {'behavior': 'none', 'amount': -2879, 'pending': -1049}, [0, -1049, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': 557, 'pending': 0}, [0, 0, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': -2062, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': 5860, 'pending': -2357}, [0, 3503, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': -4898, 'pending': -2365}, [0, 0, 7263]), ('normal control', {'behavior': 'create_prorations', 'amount': -1700, 'pending': 0}, [0, -1700, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 603, 'pending': -721}, [0, 0, 118])], [('regression', {'behavior': 'none', 'amount': -2879, 'pending': -1049}, [0, -1049, 0]), ('regression', {'behavior': 'none', 'amount': 5845, 'pending': -1589}, [0, -1589, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': -2062, 'pending': 0}, [0, 0, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': -4490, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': -2824, 'pending': 2220}, [0, -604, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 5024, 'pending': 409}, [5433, 0, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': -1436, 'pending': -1622}, [0, 0, 3058]), ('normal control', {'behavior': 'create_prorations', 'amount': 3999, 'pending': 3774}, [0, 7773, 0])], [('regression', {'behavior': 'none', 'amount': 5845, 'pending': -1589}, [0, -1589, 0]), ('regression', {'behavior': 'none', 'amount': 5967, 'pending': -212}, [0, -212, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': -4490, 'pending': 0}, [0, 0, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': -2152, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': 5861, 'pending': 2640}, [0, 8501, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 6428, 'pending': 2242}, [8670, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': 490, 'pending': 0}, [0, 490, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': -4222, 'pending': 288}, [0, -3934, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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)

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(x):
    amt = x['amount']
    b = x['behavior']
    if b == 'none':
        return [0, x['pending'] + amt, 0]
    if b == 'always_invoice':
        due = x['pending'] + amt
        return [max(0, due), 0, max(0, -due)]
    return [0, x['pending'] + amt, 0]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'behavior': 'none', 'amount': 3140, 'pending': 2478}, [0, 2478, 0]), ('regression', {'behavior': 'none', 'amount': -1187, 'pending': 1574}, [0, 1574, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': 418, 'pending': 0}, [0, 0, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': -2844, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': -2033, 'pending': -1935}, [0, -3968, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 3806, 'pending': 0}, [3806, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': -2749, 'pending': -1837}, [0, -4586, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': 7165, 'pending': -991}, [0, 6174, 0])], [('regression', {'behavior': 'none', 'amount': -1187, 'pending': 1574}, [0, 1574, 0]), ('regression', {'behavior': 'none', 'amount': -2370, 'pending': -876}, [0, -876, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': -2844, 'pending': 0}, [0, 0, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': 557, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 883, 'pending': 0}, [883, 0, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 758, 'pending': 0}, [758, 0, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 3888, 'pending': 0}, [3888, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': 5304, 'pending': -1989}, [0, 3315, 0])], [('regression', {'behavior': 'none', 'amount': -2370, 'pending': -876}, [0, -876, 0]), ('regression', {'behavior': 'none', 'amount': -2879, 'pending': -1049}, [0, -1049, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': 557, 'pending': 0}, [0, 0, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': -2062, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': 5860, 'pending': -2357}, [0, 3503, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': -4898, 'pending': -2365}, [0, 0, 7263]), ('normal control', {'behavior': 'create_prorations', 'amount': -1700, 'pending': 0}, [0, -1700, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 603, 'pending': -721}, [0, 0, 118])], [('regression', {'behavior': 'none', 'amount': -2879, 'pending': -1049}, [0, -1049, 0]), ('regression', {'behavior': 'none', 'amount': 5845, 'pending': -1589}, [0, -1589, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': -2062, 'pending': 0}, [0, 0, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': -4490, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': -2824, 'pending': 2220}, [0, -604, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 5024, 'pending': 409}, [5433, 0, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': -1436, 'pending': -1622}, [0, 0, 3058]), ('normal control', {'behavior': 'create_prorations', 'amount': 3999, 'pending': 3774}, [0, 7773, 0])], [('regression', {'behavior': 'none', 'amount': 5845, 'pending': -1589}, [0, -1589, 0]), ('regression', {'behavior': 'none', 'amount': 5967, 'pending': -212}, [0, -212, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': -4490, 'pending': 0}, [0, 0, 0]), ('partial-repair probe', {'behavior': 'none', 'amount': -2152, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': 5861, 'pending': 2640}, [0, 8501, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 6428, 'pending': 2242}, [8670, 0, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': 490, 'pending': 0}, [0, 490, 0]), ('normal control', {'behavior': 'create_prorations', 'amount': -4222, 'pending': 288}, [0, -3934, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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)

prompt:
Changes made without prorations erase previously pending items.

Input {behavior create_prorations|none|always_invoice, amount (net new proration), pending (existing pending items)}. none: nothing is created and pending is untouched. create_prorations: amount joins pending for the next renewal invoice. always_invoice: pending plus amount are invoiced now; a negative total becomes a credit. Return [invoiced_now, pending_after, credited].

split: open-access


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

N = 1
observations = []
def solve(x):
    amt = x['amount']
    b = x['behavior']
    if b == 'none':
        return [0, x['pending'], 0]
    if b == 'always_invoice':
        due = x['pending'] + amt
        return [max(0, due), 0, max(0, -due)]
    return [amt, x['pending'], 0]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'behavior': 'create_prorations', 'amount': -2033, 'pending': -1935}, [0, -3968, 0]), ('regression', {'behavior': 'create_prorations', 'amount': -2749, 'pending': -1837}, [0, -4586, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': 7165, 'pending': -991}, [0, 6174, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': 5304, 'pending': -1989}, [0, 3315, 0]), ('normal control', {'behavior': 'none', 'amount': 418, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'none', 'amount': 3140, 'pending': 2478}, [0, 2478, 0]), ('normal control', {'behavior': 'none', 'amount': -1187, 'pending': 1574}, [0, 1574, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 3806, 'pending': 0}, [3806, 0, 0])], [('regression', {'behavior': 'create_prorations', 'amount': -2749, 'pending': -1837}, [0, -4586, 0]), ('regression', {'behavior': 'create_prorations', 'amount': 7165, 'pending': -991}, [0, 6174, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': 5304, 'pending': -1989}, [0, 3315, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': 5860, 'pending': -2357}, [0, 3503, 0]), ('normal control', {'behavior': 'none', 'amount': -2844, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 883, 'pending': 0}, [883, 0, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 758, 'pending': 0}, [758, 0, 0]), ('normal control', {'behavior': 'none', 'amount': -2370, 'pending': -876}, [0, -876, 0])], [('regression', {'behavior': 'create_prorations', 'amount': 7165, 'pending': -991}, [0, 6174, 0]), ('regression', {'behavior': 'create_prorations', 'amount': 5304, 'pending': -1989}, [0, 3315, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': 5860, 'pending': -2357}, [0, 3503, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': -2824, 'pending': 2220}, [0, -604, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 3888, 'pending': 0}, [3888, 0, 0]), ('normal control', {'behavior': 'none', 'amount': 557, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'none', 'amount': -2879, 'pending': -1049}, [0, -1049, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': -4898, 'pending': -2365}, [0, 0, 7263])], [('regression', {'behavior': 'create_prorations', 'amount': 5304, 'pending': -1989}, [0, 3315, 0]), ('regression', {'behavior': 'create_prorations', 'amount': 5860, 'pending': -2357}, [0, 3503, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': 3999, 'pending': 3774}, [0, 7773, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': 5861, 'pending': 2640}, [0, 8501, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 603, 'pending': -721}, [0, 0, 118]), ('normal control', {'behavior': 'always_invoice', 'amount': 5024, 'pending': 409}, [5433, 0, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': -1436, 'pending': -1622}, [0, 0, 3058]), ('normal control', {'behavior': 'none', 'amount': -2062, 'pending': 0}, [0, 0, 0])], [('regression', {'behavior': 'create_prorations', 'amount': 5860, 'pending': -2357}, [0, 3503, 0]), ('regression', {'behavior': 'create_prorations', 'amount': -1700, 'pending': 0}, [0, -1700, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': -4222, 'pending': 288}, [0, -3934, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': -3788, 'pending': 3777}, [0, -11, 0]), ('normal control', {'behavior': 'none', 'amount': -4490, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 6428, 'pending': 2242}, [8670, 0, 0]), ('normal control', {'behavior': 'none', 'amount': 5845, 'pending': -1589}, [0, -1589, 0]), ('normal control', {'behavior': 'none', 'amount': -2152, 'pending': 0}, [0, 0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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)

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

N = 1
observations = []
def solve(x):
    amt = x['amount']
    b = x['behavior']
    if b == 'none':
        return [0, x['pending'], 0]
    if b == 'always_invoice':
        due = x['pending'] + amt
        return [max(0, due), 0, max(0, -due)]
    return [0, amt, 0]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'behavior': 'create_prorations', 'amount': -2033, 'pending': -1935}, [0, -3968, 0]), ('regression', {'behavior': 'create_prorations', 'amount': -2749, 'pending': -1837}, [0, -4586, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': 7165, 'pending': -991}, [0, 6174, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': 5304, 'pending': -1989}, [0, 3315, 0]), ('normal control', {'behavior': 'none', 'amount': 418, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'none', 'amount': 3140, 'pending': 2478}, [0, 2478, 0]), ('normal control', {'behavior': 'none', 'amount': -1187, 'pending': 1574}, [0, 1574, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 3806, 'pending': 0}, [3806, 0, 0])], [('regression', {'behavior': 'create_prorations', 'amount': -2749, 'pending': -1837}, [0, -4586, 0]), ('regression', {'behavior': 'create_prorations', 'amount': 7165, 'pending': -991}, [0, 6174, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': 5304, 'pending': -1989}, [0, 3315, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': 5860, 'pending': -2357}, [0, 3503, 0]), ('normal control', {'behavior': 'none', 'amount': -2844, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 883, 'pending': 0}, [883, 0, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 758, 'pending': 0}, [758, 0, 0]), ('normal control', {'behavior': 'none', 'amount': -2370, 'pending': -876}, [0, -876, 0])], [('regression', {'behavior': 'create_prorations', 'amount': 7165, 'pending': -991}, [0, 6174, 0]), ('regression', {'behavior': 'create_prorations', 'amount': 5304, 'pending': -1989}, [0, 3315, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': 5860, 'pending': -2357}, [0, 3503, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': -2824, 'pending': 2220}, [0, -604, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 3888, 'pending': 0}, [3888, 0, 0]), ('normal control', {'behavior': 'none', 'amount': 557, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'none', 'amount': -2879, 'pending': -1049}, [0, -1049, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': -4898, 'pending': -2365}, [0, 0, 7263])], [('regression', {'behavior': 'create_prorations', 'amount': 5304, 'pending': -1989}, [0, 3315, 0]), ('regression', {'behavior': 'create_prorations', 'amount': 5860, 'pending': -2357}, [0, 3503, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': 3999, 'pending': 3774}, [0, 7773, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': 5861, 'pending': 2640}, [0, 8501, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 603, 'pending': -721}, [0, 0, 118]), ('normal control', {'behavior': 'always_invoice', 'amount': 5024, 'pending': 409}, [5433, 0, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': -1436, 'pending': -1622}, [0, 0, 3058]), ('normal control', {'behavior': 'none', 'amount': -2062, 'pending': 0}, [0, 0, 0])], [('regression', {'behavior': 'create_prorations', 'amount': 5860, 'pending': -2357}, [0, 3503, 0]), ('regression', {'behavior': 'create_prorations', 'amount': -1700, 'pending': 0}, [0, -1700, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': -4222, 'pending': 288}, [0, -3934, 0]), ('partial-repair probe', {'behavior': 'create_prorations', 'amount': -3788, 'pending': 3777}, [0, -11, 0]), ('normal control', {'behavior': 'none', 'amount': -4490, 'pending': 0}, [0, 0, 0]), ('normal control', {'behavior': 'always_invoice', 'amount': 6428, 'pending': 2242}, [8670, 0, 0]), ('normal control', {'behavior': 'none', 'amount': 5845, 'pending': -1589}, [0, -1589, 0]), ('normal control', {'behavior': 'none', 'amount': -2152, 'pending': 0}, [0, 0, 0])]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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)

prompt:
Default prorations are charged immediately instead of on the next renewal invoice.

Input {behavior create_prorations|none|always_invoice, amount (net new proration), pending (existing pending items)}. none: nothing is created and pending is untouched. create_prorations: amount joins pending for the next renewal invoice. always_invoice: pending plus amount are invoiced now; a negative total becomes a credit. Return [invoiced_now, pending_after, credited].

split: open-access


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

N = 1
observations = []
def solve(x):
    if x['locked'] is not None and x['renewal_day'] < x['lock_until']:
        target = min(x['list_price'], x['locked'])
    else:
        target = x['list_price']
    ceiling = x['last_paid'] * (100 + x['cap_pct']) // 100
    return min(target, ceiling)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'last_paid': 6548, 'list_price': 6483, 'locked': 6448, 'lock_until': 196, 'renewal_day': 196, 'cap_pct': 5}, 6448), ('regression', {'last_paid': 2000, 'list_price': 3042, 'locked': 1900, 'lock_until': 55, 'renewal_day': 55, 'cap_pct': 5}, 1900), ('partial-repair probe', {'last_paid': 2000, 'list_price': 3442, 'locked': 2000, 'lock_until': 83, 'renewal_day': 84, 'cap_pct': 5}, 2100), ('partial-repair probe', {'last_paid': 2000, 'list_price': 4561, 'locked': 1900, 'lock_until': 96, 'renewal_day': 97, 'cap_pct': 20}, 2400), ('normal control', {'last_paid': 1000, 'list_price': 1000, 'locked': 1500, 'lock_until': 328, 'renewal_day': 201, 'cap_pct': 20}, 1000), ('normal control', {'last_paid': 2000, 'list_price': 3312, 'locked': 2500, 'lock_until': 173, 'renewal_day': 173, 'cap_pct': 20}, 2400), ('normal control', {'last_paid': 4900, 'list_price': 4900, 'locked': None, 'lock_until': 83, 'renewal_day': 100, 'cap_pct': 20}, 4900), ('normal control', {'last_paid': 222, 'list_price': 222, 'locked': 222, 'lock_until': 231, 'renewal_day': 231, 'cap_pct': 5}, 222)], [('regression', {'last_paid': 2000, 'list_price': 3042, 'locked': 1900, 'lock_until': 55, 'renewal_day': 55, 'cap_pct': 5}, 1900), ('regression', {'last_paid': 5437, 'list_price': 5507, 'locked': 5337, 'lock_until': 225, 'renewal_day': 225, 'cap_pct': 5}, 5337), ('partial-repair probe', {'last_paid': 4984, 'list_price': 7349, 'locked': 4984, 'lock_until': 94, 'renewal_day': 95, 'cap_pct': 20}, 5980), ('partial-repair probe', {'last_paid': 7649, 'list_price': 7649, 'locked': 7549, 'lock_until': 183, 'renewal_day': 184, 'cap_pct': 10}, 7649), ('normal control', {'last_paid': 4217, 'list_price': 4172, 'locked': 4217, 'lock_until': 1, 'renewal_day': 2, 'cap_pct': 0}, 4172), ('normal control', {'last_paid': 4900, 'list_price': 4441, 'locked': 4900, 'lock_until': 309, 'renewal_day': 310, 'cap_pct': 0}, 4441), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': 2000, 'lock_until': 91, 'renewal_day': 92, 'cap_pct': 5}, 2000), ('normal control', {'last_paid': 4900, 'list_price': 4900, 'locked': 4900, 'lock_until': 26, 'renewal_day': 27, 'cap_pct': 5}, 4900)], [('regression', {'last_paid': 5437, 'list_price': 5507, 'locked': 5337, 'lock_until': 225, 'renewal_day': 225, 'cap_pct': 5}, 5337), ('regression', {'last_paid': 2000, 'list_price': 3888, 'locked': 2000, 'lock_until': 333, 'renewal_day': 333, 'cap_pct': 10}, 2000), ('partial-repair probe', {'last_paid': 2000, 'list_price': 2000, 'locked': 1900, 'lock_until': 374, 'renewal_day': 375, 'cap_pct': 0}, 2000), ('partial-repair probe', {'last_paid': 4900, 'list_price': 5949, 'locked': 4900, 'lock_until': 379, 'renewal_day': 380, 'cap_pct': 10}, 5390), ('normal control', {'last_paid': 4900, 'list_price': 7407, 'locked': None, 'lock_until': 112, 'renewal_day': 113, 'cap_pct': 5}, 5145), ('normal control', {'last_paid': 485, 'list_price': 654, 'locked': None, 'lock_until': 58, 'renewal_day': 58, 'cap_pct': 20}, 582), ('normal control', {'last_paid': 1219, 'list_price': 1057, 'locked': 1119, 'lock_until': 293, 'renewal_day': 294, 'cap_pct': 10}, 1057), ('normal control', {'last_paid': 1000, 'list_price': 1000, 'locked': 1000, 'lock_until': 85, 'renewal_day': 85, 'cap_pct': 20}, 1000)], [('regression', {'last_paid': 2000, 'list_price': 3888, 'locked': 2000, 'lock_until': 333, 'renewal_day': 333, 'cap_pct': 10}, 2000), ('regression', {'last_paid': 1000, 'list_price': 1000, 'locked': 900, 'lock_until': 392, 'renewal_day': 392, 'cap_pct': 5}, 900), ('partial-repair probe', {'last_paid': 7896, 'list_price': 8057, 'locked': 7896, 'lock_until': 71, 'renewal_day': 72, 'cap_pct': 20}, 8057), ('partial-repair probe', {'last_paid': 4900, 'list_price': 5888, 'locked': 5400, 'lock_until': 13, 'renewal_day': 14, 'cap_pct': 20}, 5880), ('normal control', {'last_paid': 2000, 'list_price': 3222, 'locked': 2500, 'lock_until': 57, 'renewal_day': 260, 'cap_pct': 0}, 2000), ('normal control', {'last_paid': 1000, 'list_price': 1000, 'locked': 1500, 'lock_until': 110, 'renewal_day': 262, 'cap_pct': 10}, 1000), ('normal control', {'last_paid': 7522, 'list_price': 7059, 'locked': 8022, 'lock_until': 19, 'renewal_day': 388, 'cap_pct': 20}, 7059), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': None, 'lock_until': 285, 'renewal_day': 285, 'cap_pct': 20}, 2000)], [('regression', {'last_paid': 1000, 'list_price': 1000, 'locked': 900, 'lock_until': 392, 'renewal_day': 392, 'cap_pct': 5}, 900), ('regression', {'last_paid': 3101, 'list_price': 3101, 'locked': 3001, 'lock_until': 113, 'renewal_day': 113, 'cap_pct': 10}, 3001), ('partial-repair probe', {'last_paid': 1000, 'list_price': 1000, 'locked': 900, 'lock_until': 109, 'renewal_day': 110, 'cap_pct': 5}, 1000), ('partial-repair probe', {'last_paid': 8551, 'list_price': 8551, 'locked': 8451, 'lock_until': 130, 'renewal_day': 131, 'cap_pct': 0}, 8551), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': None, 'lock_until': 173, 'renewal_day': 263, 'cap_pct': 5}, 2000), ('normal control', {'last_paid': 4105, 'list_price': 4394, 'locked': 4005, 'lock_until': 133, 'renewal_day': 322, 'cap_pct': 20}, 4394), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': 2500, 'lock_until': 167, 'renewal_day': 167, 'cap_pct': 10}, 2000), ('normal control', {'last_paid': 4900, 'list_price': 5180, 'locked': 4900, 'lock_until': 0, 'renewal_day': 66, 'cap_pct': 20}, 5180)]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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)

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

N = 1
observations = []
def solve(x):
    if x['locked'] is not None and x['renewal_day'] <= x['lock_until'] + 1:
        target = min(x['list_price'], x['locked'])
    else:
        target = x['list_price']
    ceiling = x['last_paid'] * (100 + x['cap_pct']) // 100
    return min(target, ceiling)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'last_paid': 6548, 'list_price': 6483, 'locked': 6448, 'lock_until': 196, 'renewal_day': 196, 'cap_pct': 5}, 6448), ('regression', {'last_paid': 2000, 'list_price': 3042, 'locked': 1900, 'lock_until': 55, 'renewal_day': 55, 'cap_pct': 5}, 1900), ('partial-repair probe', {'last_paid': 2000, 'list_price': 3442, 'locked': 2000, 'lock_until': 83, 'renewal_day': 84, 'cap_pct': 5}, 2100), ('partial-repair probe', {'last_paid': 2000, 'list_price': 4561, 'locked': 1900, 'lock_until': 96, 'renewal_day': 97, 'cap_pct': 20}, 2400), ('normal control', {'last_paid': 1000, 'list_price': 1000, 'locked': 1500, 'lock_until': 328, 'renewal_day': 201, 'cap_pct': 20}, 1000), ('normal control', {'last_paid': 2000, 'list_price': 3312, 'locked': 2500, 'lock_until': 173, 'renewal_day': 173, 'cap_pct': 20}, 2400), ('normal control', {'last_paid': 4900, 'list_price': 4900, 'locked': None, 'lock_until': 83, 'renewal_day': 100, 'cap_pct': 20}, 4900), ('normal control', {'last_paid': 222, 'list_price': 222, 'locked': 222, 'lock_until': 231, 'renewal_day': 231, 'cap_pct': 5}, 222)], [('regression', {'last_paid': 2000, 'list_price': 3042, 'locked': 1900, 'lock_until': 55, 'renewal_day': 55, 'cap_pct': 5}, 1900), ('regression', {'last_paid': 5437, 'list_price': 5507, 'locked': 5337, 'lock_until': 225, 'renewal_day': 225, 'cap_pct': 5}, 5337), ('partial-repair probe', {'last_paid': 4984, 'list_price': 7349, 'locked': 4984, 'lock_until': 94, 'renewal_day': 95, 'cap_pct': 20}, 5980), ('partial-repair probe', {'last_paid': 7649, 'list_price': 7649, 'locked': 7549, 'lock_until': 183, 'renewal_day': 184, 'cap_pct': 10}, 7649), ('normal control', {'last_paid': 4217, 'list_price': 4172, 'locked': 4217, 'lock_until': 1, 'renewal_day': 2, 'cap_pct': 0}, 4172), ('normal control', {'last_paid': 4900, 'list_price': 4441, 'locked': 4900, 'lock_until': 309, 'renewal_day': 310, 'cap_pct': 0}, 4441), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': 2000, 'lock_until': 91, 'renewal_day': 92, 'cap_pct': 5}, 2000), ('normal control', {'last_paid': 4900, 'list_price': 4900, 'locked': 4900, 'lock_until': 26, 'renewal_day': 27, 'cap_pct': 5}, 4900)], [('regression', {'last_paid': 5437, 'list_price': 5507, 'locked': 5337, 'lock_until': 225, 'renewal_day': 225, 'cap_pct': 5}, 5337), ('regression', {'last_paid': 2000, 'list_price': 3888, 'locked': 2000, 'lock_until': 333, 'renewal_day': 333, 'cap_pct': 10}, 2000), ('partial-repair probe', {'last_paid': 2000, 'list_price': 2000, 'locked': 1900, 'lock_until': 374, 'renewal_day': 375, 'cap_pct': 0}, 2000), ('partial-repair probe', {'last_paid': 4900, 'list_price': 5949, 'locked': 4900, 'lock_until': 379, 'renewal_day': 380, 'cap_pct': 10}, 5390), ('normal control', {'last_paid': 4900, 'list_price': 7407, 'locked': None, 'lock_until': 112, 'renewal_day': 113, 'cap_pct': 5}, 5145), ('normal control', {'last_paid': 485, 'list_price': 654, 'locked': None, 'lock_until': 58, 'renewal_day': 58, 'cap_pct': 20}, 582), ('normal control', {'last_paid': 1219, 'list_price': 1057, 'locked': 1119, 'lock_until': 293, 'renewal_day': 294, 'cap_pct': 10}, 1057), ('normal control', {'last_paid': 1000, 'list_price': 1000, 'locked': 1000, 'lock_until': 85, 'renewal_day': 85, 'cap_pct': 20}, 1000)], [('regression', {'last_paid': 2000, 'list_price': 3888, 'locked': 2000, 'lock_until': 333, 'renewal_day': 333, 'cap_pct': 10}, 2000), ('regression', {'last_paid': 1000, 'list_price': 1000, 'locked': 900, 'lock_until': 392, 'renewal_day': 392, 'cap_pct': 5}, 900), ('partial-repair probe', {'last_paid': 7896, 'list_price': 8057, 'locked': 7896, 'lock_until': 71, 'renewal_day': 72, 'cap_pct': 20}, 8057), ('partial-repair probe', {'last_paid': 4900, 'list_price': 5888, 'locked': 5400, 'lock_until': 13, 'renewal_day': 14, 'cap_pct': 20}, 5880), ('normal control', {'last_paid': 2000, 'list_price': 3222, 'locked': 2500, 'lock_until': 57, 'renewal_day': 260, 'cap_pct': 0}, 2000), ('normal control', {'last_paid': 1000, 'list_price': 1000, 'locked': 1500, 'lock_until': 110, 'renewal_day': 262, 'cap_pct': 10}, 1000), ('normal control', {'last_paid': 7522, 'list_price': 7059, 'locked': 8022, 'lock_until': 19, 'renewal_day': 388, 'cap_pct': 20}, 7059), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': None, 'lock_until': 285, 'renewal_day': 285, 'cap_pct': 20}, 2000)], [('regression', {'last_paid': 1000, 'list_price': 1000, 'locked': 900, 'lock_until': 392, 'renewal_day': 392, 'cap_pct': 5}, 900), ('regression', {'last_paid': 3101, 'list_price': 3101, 'locked': 3001, 'lock_until': 113, 'renewal_day': 113, 'cap_pct': 10}, 3001), ('partial-repair probe', {'last_paid': 1000, 'list_price': 1000, 'locked': 900, 'lock_until': 109, 'renewal_day': 110, 'cap_pct': 5}, 1000), ('partial-repair probe', {'last_paid': 8551, 'list_price': 8551, 'locked': 8451, 'lock_until': 130, 'renewal_day': 131, 'cap_pct': 0}, 8551), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': None, 'lock_until': 173, 'renewal_day': 263, 'cap_pct': 5}, 2000), ('normal control', {'last_paid': 4105, 'list_price': 4394, 'locked': 4005, 'lock_until': 133, 'renewal_day': 322, 'cap_pct': 20}, 4394), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': 2500, 'lock_until': 167, 'renewal_day': 167, 'cap_pct': 10}, 2000), ('normal control', {'last_paid': 4900, 'list_price': 5180, 'locked': 4900, 'lock_until': 0, 'renewal_day': 66, 'cap_pct': 20}, 5180)]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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)

prompt:
Renewals on the lock expiry day lose the locked price.

Input {last_paid, list_price, locked|None, lock_until, renewal_day, cap_pct}. While the lock is active (renewal_day <= lock_until) the target is min(list_price, locked); otherwise list_price. The renewal price is min(target, last_paid*(100+cap_pct)//100). Return cents.

split: open-access


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

N = 1
observations = []
def solve(x):
    if x['locked'] is not None and x['renewal_day'] <= x['lock_until']:
        target = x['locked']
    else:
        target = x['list_price']
    ceiling = x['last_paid'] * (100 + x['cap_pct']) // 100
    return min(target, ceiling)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'last_paid': 1000, 'list_price': 1000, 'locked': 1500, 'lock_until': 328, 'renewal_day': 201, 'cap_pct': 20}, 1000), ('regression', {'last_paid': 2000, 'list_price': 2000, 'locked': 2500, 'lock_until': 167, 'renewal_day': 167, 'cap_pct': 10}, 2000), ('partial-repair probe', {'last_paid': 6548, 'list_price': 6483, 'locked': 6448, 'lock_until': 196, 'renewal_day': 196, 'cap_pct': 5}, 6448), ('partial-repair probe', {'last_paid': 4900, 'list_price': 4900, 'locked': 5400, 'lock_until': 345, 'renewal_day': 345, 'cap_pct': 5}, 4900), ('normal control', {'last_paid': 2000, 'list_price': 3312, 'locked': 2500, 'lock_until': 173, 'renewal_day': 173, 'cap_pct': 20}, 2400), ('normal control', {'last_paid': 4900, 'list_price': 4900, 'locked': None, 'lock_until': 83, 'renewal_day': 100, 'cap_pct': 20}, 4900), ('normal control', {'last_paid': 222, 'list_price': 222, 'locked': 222, 'lock_until': 231, 'renewal_day': 231, 'cap_pct': 5}, 222), ('normal control', {'last_paid': 4217, 'list_price': 4172, 'locked': 4217, 'lock_until': 1, 'renewal_day': 2, 'cap_pct': 0}, 4172)], [('regression', {'last_paid': 2000, 'list_price': 2000, 'locked': 2500, 'lock_until': 167, 'renewal_day': 167, 'cap_pct': 10}, 2000), ('regression', {'last_paid': 4900, 'list_price': 4900, 'locked': 5400, 'lock_until': 345, 'renewal_day': 345, 'cap_pct': 5}, 4900), ('partial-repair probe', {'last_paid': 2000, 'list_price': 3042, 'locked': 1900, 'lock_until': 55, 'renewal_day': 55, 'cap_pct': 5}, 1900), ('partial-repair probe', {'last_paid': 2000, 'list_price': 1532, 'locked': 2000, 'lock_until': 313, 'renewal_day': 57, 'cap_pct': 20}, 1532), ('normal control', {'last_paid': 4900, 'list_price': 4441, 'locked': 4900, 'lock_until': 309, 'renewal_day': 310, 'cap_pct': 0}, 4441), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': 2000, 'lock_until': 91, 'renewal_day': 92, 'cap_pct': 5}, 2000), ('normal control', {'last_paid': 4900, 'list_price': 4900, 'locked': 4900, 'lock_until': 26, 'renewal_day': 27, 'cap_pct': 5}, 4900), ('normal control', {'last_paid': 4900, 'list_price': 7407, 'locked': None, 'lock_until': 112, 'renewal_day': 113, 'cap_pct': 5}, 5145)], [('regression', {'last_paid': 4900, 'list_price': 4900, 'locked': 5400, 'lock_until': 345, 'renewal_day': 345, 'cap_pct': 5}, 4900), ('regression', {'last_paid': 2000, 'list_price': 1532, 'locked': 2000, 'lock_until': 313, 'renewal_day': 57, 'cap_pct': 20}, 1532), ('partial-repair probe', {'last_paid': 2000, 'list_price': 3042, 'locked': 1900, 'lock_until': 55, 'renewal_day': 55, 'cap_pct': 5}, 1900), ('partial-repair probe', {'last_paid': 5437, 'list_price': 5507, 'locked': 5337, 'lock_until': 225, 'renewal_day': 225, 'cap_pct': 5}, 5337), ('normal control', {'last_paid': 485, 'list_price': 654, 'locked': None, 'lock_until': 58, 'renewal_day': 58, 'cap_pct': 20}, 582), ('normal control', {'last_paid': 1219, 'list_price': 1057, 'locked': 1119, 'lock_until': 293, 'renewal_day': 294, 'cap_pct': 10}, 1057), ('normal control', {'last_paid': 1000, 'list_price': 1000, 'locked': 1000, 'lock_until': 85, 'renewal_day': 85, 'cap_pct': 20}, 1000), ('normal control', {'last_paid': 2000, 'list_price': 3222, 'locked': 2500, 'lock_until': 57, 'renewal_day': 260, 'cap_pct': 0}, 2000)], [('regression', {'last_paid': 2000, 'list_price': 1532, 'locked': 2000, 'lock_until': 313, 'renewal_day': 57, 'cap_pct': 20}, 1532), ('regression', {'last_paid': 2000, 'list_price': 1999, 'locked': 2500, 'lock_until': 365, 'renewal_day': 365, 'cap_pct': 20}, 1999), ('partial-repair probe', {'last_paid': 5437, 'list_price': 5507, 'locked': 5337, 'lock_until': 225, 'renewal_day': 225, 'cap_pct': 5}, 5337), ('partial-repair probe', {'last_paid': 2000, 'list_price': 3888, 'locked': 2000, 'lock_until': 333, 'renewal_day': 333, 'cap_pct': 10}, 2000), ('normal control', {'last_paid': 1000, 'list_price': 1000, 'locked': 1500, 'lock_until': 110, 'renewal_day': 262, 'cap_pct': 10}, 1000), ('normal control', {'last_paid': 7522, 'list_price': 7059, 'locked': 8022, 'lock_until': 19, 'renewal_day': 388, 'cap_pct': 20}, 7059), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': None, 'lock_until': 285, 'renewal_day': 285, 'cap_pct': 20}, 2000), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': None, 'lock_until': 173, 'renewal_day': 263, 'cap_pct': 5}, 2000)], [('regression', {'last_paid': 2000, 'list_price': 1999, 'locked': 2500, 'lock_until': 365, 'renewal_day': 365, 'cap_pct': 20}, 1999), ('regression', {'last_paid': 4900, 'list_price': 4767, 'locked': 5400, 'lock_until': 335, 'renewal_day': 32, 'cap_pct': 10}, 4767), ('partial-repair probe', {'last_paid': 2000, 'list_price': 3888, 'locked': 2000, 'lock_until': 333, 'renewal_day': 333, 'cap_pct': 10}, 2000), ('partial-repair probe', {'last_paid': 6192, 'list_price': 7798, 'locked': 6092, 'lock_until': 169, 'renewal_day': 157, 'cap_pct': 0}, 6092), ('normal control', {'last_paid': 4105, 'list_price': 4394, 'locked': 4005, 'lock_until': 133, 'renewal_day': 322, 'cap_pct': 20}, 4394), ('normal control', {'last_paid': 4900, 'list_price': 5180, 'locked': 4900, 'lock_until': 0, 'renewal_day': 66, 'cap_pct': 20}, 5180), ('normal control', {'last_paid': 2000, 'list_price': 2438, 'locked': 2500, 'lock_until': 146, 'renewal_day': 147, 'cap_pct': 20}, 2400), ('normal control', {'last_paid': 4900, 'list_price': 4900, 'locked': 5400, 'lock_until': 208, 'renewal_day': 260, 'cap_pct': 5}, 4900)]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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)

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

N = 1
observations = []
def solve(x):
    if x['locked'] is not None and x['renewal_day'] <= x['lock_until']:
        target = max(x['list_price'], x['locked'])
    else:
        target = x['list_price']
    ceiling = x['last_paid'] * (100 + x['cap_pct']) // 100
    return min(target, ceiling)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'last_paid': 1000, 'list_price': 1000, 'locked': 1500, 'lock_until': 328, 'renewal_day': 201, 'cap_pct': 20}, 1000), ('regression', {'last_paid': 2000, 'list_price': 2000, 'locked': 2500, 'lock_until': 167, 'renewal_day': 167, 'cap_pct': 10}, 2000), ('partial-repair probe', {'last_paid': 6548, 'list_price': 6483, 'locked': 6448, 'lock_until': 196, 'renewal_day': 196, 'cap_pct': 5}, 6448), ('partial-repair probe', {'last_paid': 4900, 'list_price': 4900, 'locked': 5400, 'lock_until': 345, 'renewal_day': 345, 'cap_pct': 5}, 4900), ('normal control', {'last_paid': 2000, 'list_price': 3312, 'locked': 2500, 'lock_until': 173, 'renewal_day': 173, 'cap_pct': 20}, 2400), ('normal control', {'last_paid': 4900, 'list_price': 4900, 'locked': None, 'lock_until': 83, 'renewal_day': 100, 'cap_pct': 20}, 4900), ('normal control', {'last_paid': 222, 'list_price': 222, 'locked': 222, 'lock_until': 231, 'renewal_day': 231, 'cap_pct': 5}, 222), ('normal control', {'last_paid': 4217, 'list_price': 4172, 'locked': 4217, 'lock_until': 1, 'renewal_day': 2, 'cap_pct': 0}, 4172)], [('regression', {'last_paid': 2000, 'list_price': 2000, 'locked': 2500, 'lock_until': 167, 'renewal_day': 167, 'cap_pct': 10}, 2000), ('regression', {'last_paid': 4900, 'list_price': 4900, 'locked': 5400, 'lock_until': 345, 'renewal_day': 345, 'cap_pct': 5}, 4900), ('partial-repair probe', {'last_paid': 2000, 'list_price': 3042, 'locked': 1900, 'lock_until': 55, 'renewal_day': 55, 'cap_pct': 5}, 1900), ('partial-repair probe', {'last_paid': 2000, 'list_price': 1532, 'locked': 2000, 'lock_until': 313, 'renewal_day': 57, 'cap_pct': 20}, 1532), ('normal control', {'last_paid': 4900, 'list_price': 4441, 'locked': 4900, 'lock_until': 309, 'renewal_day': 310, 'cap_pct': 0}, 4441), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': 2000, 'lock_until': 91, 'renewal_day': 92, 'cap_pct': 5}, 2000), ('normal control', {'last_paid': 4900, 'list_price': 4900, 'locked': 4900, 'lock_until': 26, 'renewal_day': 27, 'cap_pct': 5}, 4900), ('normal control', {'last_paid': 4900, 'list_price': 7407, 'locked': None, 'lock_until': 112, 'renewal_day': 113, 'cap_pct': 5}, 5145)], [('regression', {'last_paid': 4900, 'list_price': 4900, 'locked': 5400, 'lock_until': 345, 'renewal_day': 345, 'cap_pct': 5}, 4900), ('regression', {'last_paid': 2000, 'list_price': 1532, 'locked': 2000, 'lock_until': 313, 'renewal_day': 57, 'cap_pct': 20}, 1532), ('partial-repair probe', {'last_paid': 2000, 'list_price': 3042, 'locked': 1900, 'lock_until': 55, 'renewal_day': 55, 'cap_pct': 5}, 1900), ('partial-repair probe', {'last_paid': 5437, 'list_price': 5507, 'locked': 5337, 'lock_until': 225, 'renewal_day': 225, 'cap_pct': 5}, 5337), ('normal control', {'last_paid': 485, 'list_price': 654, 'locked': None, 'lock_until': 58, 'renewal_day': 58, 'cap_pct': 20}, 582), ('normal control', {'last_paid': 1219, 'list_price': 1057, 'locked': 1119, 'lock_until': 293, 'renewal_day': 294, 'cap_pct': 10}, 1057), ('normal control', {'last_paid': 1000, 'list_price': 1000, 'locked': 1000, 'lock_until': 85, 'renewal_day': 85, 'cap_pct': 20}, 1000), ('normal control', {'last_paid': 2000, 'list_price': 3222, 'locked': 2500, 'lock_until': 57, 'renewal_day': 260, 'cap_pct': 0}, 2000)], [('regression', {'last_paid': 2000, 'list_price': 1532, 'locked': 2000, 'lock_until': 313, 'renewal_day': 57, 'cap_pct': 20}, 1532), ('regression', {'last_paid': 2000, 'list_price': 1999, 'locked': 2500, 'lock_until': 365, 'renewal_day': 365, 'cap_pct': 20}, 1999), ('partial-repair probe', {'last_paid': 5437, 'list_price': 5507, 'locked': 5337, 'lock_until': 225, 'renewal_day': 225, 'cap_pct': 5}, 5337), ('partial-repair probe', {'last_paid': 2000, 'list_price': 3888, 'locked': 2000, 'lock_until': 333, 'renewal_day': 333, 'cap_pct': 10}, 2000), ('normal control', {'last_paid': 1000, 'list_price': 1000, 'locked': 1500, 'lock_until': 110, 'renewal_day': 262, 'cap_pct': 10}, 1000), ('normal control', {'last_paid': 7522, 'list_price': 7059, 'locked': 8022, 'lock_until': 19, 'renewal_day': 388, 'cap_pct': 20}, 7059), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': None, 'lock_until': 285, 'renewal_day': 285, 'cap_pct': 20}, 2000), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': None, 'lock_until': 173, 'renewal_day': 263, 'cap_pct': 5}, 2000)], [('regression', {'last_paid': 2000, 'list_price': 1999, 'locked': 2500, 'lock_until': 365, 'renewal_day': 365, 'cap_pct': 20}, 1999), ('regression', {'last_paid': 4900, 'list_price': 4767, 'locked': 5400, 'lock_until': 335, 'renewal_day': 32, 'cap_pct': 10}, 4767), ('partial-repair probe', {'last_paid': 2000, 'list_price': 3888, 'locked': 2000, 'lock_until': 333, 'renewal_day': 333, 'cap_pct': 10}, 2000), ('partial-repair probe', {'last_paid': 6192, 'list_price': 7798, 'locked': 6092, 'lock_until': 169, 'renewal_day': 157, 'cap_pct': 0}, 6092), ('normal control', {'last_paid': 4105, 'list_price': 4394, 'locked': 4005, 'lock_until': 133, 'renewal_day': 322, 'cap_pct': 20}, 4394), ('normal control', {'last_paid': 4900, 'list_price': 5180, 'locked': 4900, 'lock_until': 0, 'renewal_day': 66, 'cap_pct': 20}, 5180), ('normal control', {'last_paid': 2000, 'list_price': 2438, 'locked': 2500, 'lock_until': 146, 'renewal_day': 147, 'cap_pct': 20}, 2400), ('normal control', {'last_paid': 4900, 'list_price': 4900, 'locked': 5400, 'lock_until': 208, 'renewal_day': 260, 'cap_pct': 5}, 4900)]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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)

prompt:
When list prices drop below the locked price, locked customers pay more than new customers.

Input {last_paid, list_price, locked|None, lock_until, renewal_day, cap_pct}. While the lock is active (renewal_day <= lock_until) the target is min(list_price, locked); otherwise list_price. The renewal price is min(target, last_paid*(100+cap_pct)//100). Return cents.

split: open-access


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

N = 1
observations = []
def solve(x):
    if x['locked'] is not None and x['renewal_day'] <= x['lock_until']:
        target = min(x['list_price'], x['locked'])
    else:
        target = x['list_price']
    ceiling = x['list_price'] * (100 + x['cap_pct']) // 100
    return min(target, ceiling)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'last_paid': 2000, 'list_price': 3312, 'locked': 2500, 'lock_until': 173, 'renewal_day': 173, 'cap_pct': 20}, 2400), ('regression', {'last_paid': 4900, 'list_price': 7407, 'locked': None, 'lock_until': 112, 'renewal_day': 113, 'cap_pct': 5}, 5145), ('partial-repair probe', {'last_paid': 485, 'list_price': 654, 'locked': None, 'lock_until': 58, 'renewal_day': 58, 'cap_pct': 20}, 582), ('partial-repair probe', {'last_paid': 4105, 'list_price': 4394, 'locked': 4005, 'lock_until': 133, 'renewal_day': 322, 'cap_pct': 20}, 4394), ('normal control', {'last_paid': 1000, 'list_price': 1000, 'locked': 1500, 'lock_until': 328, 'renewal_day': 201, 'cap_pct': 20}, 1000), ('normal control', {'last_paid': 4900, 'list_price': 4900, 'locked': None, 'lock_until': 83, 'renewal_day': 100, 'cap_pct': 20}, 4900), ('normal control', {'last_paid': 222, 'list_price': 222, 'locked': 222, 'lock_until': 231, 'renewal_day': 231, 'cap_pct': 5}, 222), ('normal control', {'last_paid': 4217, 'list_price': 4172, 'locked': 4217, 'lock_until': 1, 'renewal_day': 2, 'cap_pct': 0}, 4172)], [('regression', {'last_paid': 4900, 'list_price': 7407, 'locked': None, 'lock_until': 112, 'renewal_day': 113, 'cap_pct': 5}, 5145), ('regression', {'last_paid': 485, 'list_price': 654, 'locked': None, 'lock_until': 58, 'renewal_day': 58, 'cap_pct': 20}, 582), ('partial-repair probe', {'last_paid': 4105, 'list_price': 4394, 'locked': 4005, 'lock_until': 133, 'renewal_day': 322, 'cap_pct': 20}, 4394), ('partial-repair probe', {'last_paid': 4900, 'list_price': 5180, 'locked': 4900, 'lock_until': 0, 'renewal_day': 66, 'cap_pct': 20}, 5180), ('normal control', {'last_paid': 4900, 'list_price': 4441, 'locked': 4900, 'lock_until': 309, 'renewal_day': 310, 'cap_pct': 0}, 4441), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': 2000, 'lock_until': 91, 'renewal_day': 92, 'cap_pct': 5}, 2000), ('normal control', {'last_paid': 4900, 'list_price': 4900, 'locked': 4900, 'lock_until': 26, 'renewal_day': 27, 'cap_pct': 5}, 4900), ('normal control', {'last_paid': 1219, 'list_price': 1057, 'locked': 1119, 'lock_until': 293, 'renewal_day': 294, 'cap_pct': 10}, 1057)], [('regression', {'last_paid': 485, 'list_price': 654, 'locked': None, 'lock_until': 58, 'renewal_day': 58, 'cap_pct': 20}, 582), ('regression', {'last_paid': 2000, 'list_price': 3222, 'locked': 2500, 'lock_until': 57, 'renewal_day': 260, 'cap_pct': 0}, 2000), ('partial-repair probe', {'last_paid': 4900, 'list_price': 5180, 'locked': 4900, 'lock_until': 0, 'renewal_day': 66, 'cap_pct': 20}, 5180), ('partial-repair probe', {'last_paid': 2000, 'list_price': 2438, 'locked': 2500, 'lock_until': 146, 'renewal_day': 147, 'cap_pct': 20}, 2400), ('normal control', {'last_paid': 1000, 'list_price': 1000, 'locked': 1000, 'lock_until': 85, 'renewal_day': 85, 'cap_pct': 20}, 1000), ('normal control', {'last_paid': 1000, 'list_price': 1000, 'locked': 1500, 'lock_until': 110, 'renewal_day': 262, 'cap_pct': 10}, 1000), ('normal control', {'last_paid': 7522, 'list_price': 7059, 'locked': 8022, 'lock_until': 19, 'renewal_day': 388, 'cap_pct': 20}, 7059), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': None, 'lock_until': 285, 'renewal_day': 285, 'cap_pct': 20}, 2000)], [('regression', {'last_paid': 2000, 'list_price': 2438, 'locked': 2500, 'lock_until': 146, 'renewal_day': 147, 'cap_pct': 20}, 2400), ('regression', {'last_paid': 2000, 'list_price': 3222, 'locked': 2500, 'lock_until': 57, 'renewal_day': 260, 'cap_pct': 0}, 2000), ('partial-repair probe', {'last_paid': 2000, 'list_price': 3442, 'locked': 2000, 'lock_until': 83, 'renewal_day': 84, 'cap_pct': 5}, 2100), ('partial-repair probe', {'last_paid': 2000, 'list_price': 4561, 'locked': 1900, 'lock_until': 96, 'renewal_day': 97, 'cap_pct': 20}, 2400), ('normal control', {'last_paid': 6548, 'list_price': 6483, 'locked': 6448, 'lock_until': 196, 'renewal_day': 196, 'cap_pct': 5}, 6448), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': None, 'lock_until': 173, 'renewal_day': 263, 'cap_pct': 5}, 2000), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': 2500, 'lock_until': 167, 'renewal_day': 167, 'cap_pct': 10}, 2000), ('normal control', {'last_paid': 4900, 'list_price': 4900, 'locked': 5400, 'lock_until': 208, 'renewal_day': 260, 'cap_pct': 5}, 4900)], [('regression', {'last_paid': 2000, 'list_price': 3442, 'locked': 2000, 'lock_until': 83, 'renewal_day': 84, 'cap_pct': 5}, 2100), ('regression', {'last_paid': 2000, 'list_price': 2438, 'locked': 2500, 'lock_until': 146, 'renewal_day': 147, 'cap_pct': 20}, 2400), ('partial-repair probe', {'last_paid': 1000, 'list_price': 1465, 'locked': None, 'lock_until': 310, 'renewal_day': 310, 'cap_pct': 5}, 1050), ('partial-repair probe', {'last_paid': 4984, 'list_price': 7349, 'locked': 4984, 'lock_until': 94, 'renewal_day': 95, 'cap_pct': 20}, 5980), ('normal control', {'last_paid': 4900, 'list_price': 4900, 'locked': 5400, 'lock_until': 345, 'renewal_day': 345, 'cap_pct': 5}, 4900), ('normal control', {'last_paid': 1000, 'list_price': 754, 'locked': 900, 'lock_until': 155, 'renewal_day': 206, 'cap_pct': 10}, 754), ('normal control', {'last_paid': 2000, 'list_price': 3042, 'locked': 1900, 'lock_until': 55, 'renewal_day': 55, 'cap_pct': 5}, 1900), ('normal control', {'last_paid': 2000, 'list_price': 1532, 'locked': 2000, 'lock_until': 313, 'renewal_day': 57, 'cap_pct': 20}, 1532)]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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)

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

N = 1
observations = []
def solve(x):
    if x['locked'] is not None and x['renewal_day'] <= x['lock_until']:
        target = min(x['list_price'], x['locked'])
    else:
        target = x['list_price']
    ceiling = x['last_paid'] + x['cap_pct']
    return min(target, ceiling)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'last_paid': 2000, 'list_price': 3312, 'locked': 2500, 'lock_until': 173, 'renewal_day': 173, 'cap_pct': 20}, 2400), ('regression', {'last_paid': 4900, 'list_price': 7407, 'locked': None, 'lock_until': 112, 'renewal_day': 113, 'cap_pct': 5}, 5145), ('partial-repair probe', {'last_paid': 485, 'list_price': 654, 'locked': None, 'lock_until': 58, 'renewal_day': 58, 'cap_pct': 20}, 582), ('partial-repair probe', {'last_paid': 4105, 'list_price': 4394, 'locked': 4005, 'lock_until': 133, 'renewal_day': 322, 'cap_pct': 20}, 4394), ('normal control', {'last_paid': 1000, 'list_price': 1000, 'locked': 1500, 'lock_until': 328, 'renewal_day': 201, 'cap_pct': 20}, 1000), ('normal control', {'last_paid': 4900, 'list_price': 4900, 'locked': None, 'lock_until': 83, 'renewal_day': 100, 'cap_pct': 20}, 4900), ('normal control', {'last_paid': 222, 'list_price': 222, 'locked': 222, 'lock_until': 231, 'renewal_day': 231, 'cap_pct': 5}, 222), ('normal control', {'last_paid': 4217, 'list_price': 4172, 'locked': 4217, 'lock_until': 1, 'renewal_day': 2, 'cap_pct': 0}, 4172)], [('regression', {'last_paid': 4900, 'list_price': 7407, 'locked': None, 'lock_until': 112, 'renewal_day': 113, 'cap_pct': 5}, 5145), ('regression', {'last_paid': 485, 'list_price': 654, 'locked': None, 'lock_until': 58, 'renewal_day': 58, 'cap_pct': 20}, 582), ('partial-repair probe', {'last_paid': 4105, 'list_price': 4394, 'locked': 4005, 'lock_until': 133, 'renewal_day': 322, 'cap_pct': 20}, 4394), ('partial-repair probe', {'last_paid': 4900, 'list_price': 5180, 'locked': 4900, 'lock_until': 0, 'renewal_day': 66, 'cap_pct': 20}, 5180), ('normal control', {'last_paid': 4900, 'list_price': 4441, 'locked': 4900, 'lock_until': 309, 'renewal_day': 310, 'cap_pct': 0}, 4441), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': 2000, 'lock_until': 91, 'renewal_day': 92, 'cap_pct': 5}, 2000), ('normal control', {'last_paid': 4900, 'list_price': 4900, 'locked': 4900, 'lock_until': 26, 'renewal_day': 27, 'cap_pct': 5}, 4900), ('normal control', {'last_paid': 1219, 'list_price': 1057, 'locked': 1119, 'lock_until': 293, 'renewal_day': 294, 'cap_pct': 10}, 1057)], [('regression', {'last_paid': 485, 'list_price': 654, 'locked': None, 'lock_until': 58, 'renewal_day': 58, 'cap_pct': 20}, 582), ('regression', {'last_paid': 2000, 'list_price': 3222, 'locked': 2500, 'lock_until': 57, 'renewal_day': 260, 'cap_pct': 0}, 2000), ('partial-repair probe', {'last_paid': 4900, 'list_price': 5180, 'locked': 4900, 'lock_until': 0, 'renewal_day': 66, 'cap_pct': 20}, 5180), ('partial-repair probe', {'last_paid': 2000, 'list_price': 2438, 'locked': 2500, 'lock_until': 146, 'renewal_day': 147, 'cap_pct': 20}, 2400), ('normal control', {'last_paid': 1000, 'list_price': 1000, 'locked': 1000, 'lock_until': 85, 'renewal_day': 85, 'cap_pct': 20}, 1000), ('normal control', {'last_paid': 1000, 'list_price': 1000, 'locked': 1500, 'lock_until': 110, 'renewal_day': 262, 'cap_pct': 10}, 1000), ('normal control', {'last_paid': 7522, 'list_price': 7059, 'locked': 8022, 'lock_until': 19, 'renewal_day': 388, 'cap_pct': 20}, 7059), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': None, 'lock_until': 285, 'renewal_day': 285, 'cap_pct': 20}, 2000)], [('regression', {'last_paid': 2000, 'list_price': 2438, 'locked': 2500, 'lock_until': 146, 'renewal_day': 147, 'cap_pct': 20}, 2400), ('regression', {'last_paid': 2000, 'list_price': 3222, 'locked': 2500, 'lock_until': 57, 'renewal_day': 260, 'cap_pct': 0}, 2000), ('partial-repair probe', {'last_paid': 2000, 'list_price': 3442, 'locked': 2000, 'lock_until': 83, 'renewal_day': 84, 'cap_pct': 5}, 2100), ('partial-repair probe', {'last_paid': 2000, 'list_price': 4561, 'locked': 1900, 'lock_until': 96, 'renewal_day': 97, 'cap_pct': 20}, 2400), ('normal control', {'last_paid': 6548, 'list_price': 6483, 'locked': 6448, 'lock_until': 196, 'renewal_day': 196, 'cap_pct': 5}, 6448), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': None, 'lock_until': 173, 'renewal_day': 263, 'cap_pct': 5}, 2000), ('normal control', {'last_paid': 2000, 'list_price': 2000, 'locked': 2500, 'lock_until': 167, 'renewal_day': 167, 'cap_pct': 10}, 2000), ('normal control', {'last_paid': 4900, 'list_price': 4900, 'locked': 5400, 'lock_until': 208, 'renewal_day': 260, 'cap_pct': 5}, 4900)], [('regression', {'last_paid': 2000, 'list_price': 3442, 'locked': 2000, 'lock_until': 83, 'renewal_day': 84, 'cap_pct': 5}, 2100), ('regression', {'last_paid': 2000, 'list_price': 2438, 'locked': 2500, 'lock_until': 146, 'renewal_day': 147, 'cap_pct': 20}, 2400), ('partial-repair probe', {'last_paid': 1000, 'list_price': 1465, 'locked': None, 'lock_until': 310, 'renewal_day': 310, 'cap_pct': 5}, 1050), ('partial-repair probe', {'last_paid': 4984, 'list_price': 7349, 'locked': 4984, 'lock_until': 94, 'renewal_day': 95, 'cap_pct': 20}, 5980), ('normal control', {'last_paid': 4900, 'list_price': 4900, 'locked': 5400, 'lock_until': 345, 'renewal_day': 345, 'cap_pct': 5}, 4900), ('normal control', {'last_paid': 1000, 'list_price': 754, 'locked': 900, 'lock_until': 155, 'renewal_day': 206, 'cap_pct': 10}, 754), ('normal control', {'last_paid': 2000, 'list_price': 3042, 'locked': 1900, 'lock_until': 55, 'renewal_day': 55, 'cap_pct': 5}, 1900), ('normal control', {'last_paid': 2000, 'list_price': 1532, 'locked': 2000, 'lock_until': 313, 'renewal_day': 57, 'cap_pct': 20}, 1532)]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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)

prompt:
Renewal increases exceed the promised percentage cap.

Input {last_paid, list_price, locked|None, lock_until, renewal_day, cap_pct}. While the lock is active (renewal_day <= lock_until) the target is min(list_price, locked); otherwise list_price. The renewal price is min(target, last_paid*(100+cap_pct)//100). Return cents.

split: open-access


prompt:
Customers with many small events are billed for far more units than they used.

Input {events in milli-units, free units, div (units per package), round up|down, price per package}. Units = ceil(sum(events)/1000) once per invoice. Billable = max(0, units - free). Packages = ceil or floor(billable/div) by round. Return [units, packages, packages*price].

split: open-access


prompt:
The free allowance never reduces the bill.

Input {events in milli-units, free units, div (units per package), round up|down, price per package}. Units = ceil(sum(events)/1000) once per invoice. Billable = max(0, units - free). Packages = ceil or floor(billable/div) by round. Return [units, packages, packages*price].

split: open-access


prompt:
Exact package multiples and zero usage are billed an extra package.

Input {events in milli-units, free units, div (units per package), round up|down, price per package}. Units = ceil(sum(events)/1000) once per invoice. Billable = max(0, units - free). Packages = ceil or floor(billable/div) by round. Return [units, packages, packages*price].

split: open-access


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

N = 1
observations = []
def solve(x):
    if x['status'] in ('open', 'void', 'refunded'):
        return 0
    return (x['list'] * x['left'] * 2 + x['period']) // (2 * x['period'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 13, 'period': 31}, 0), ('regression', {'list': 4900, 'paid': 2450, 'status': 'partial', 'left': 24, 'period': 31}, 1897), ('partial-repair probe', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 3, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 4950, 'status': 'void', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'void', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 0, 'status': 'open', 'left': 4, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'open', 'left': 29, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('regression', {'list': 4900, 'paid': 2450, 'status': 'paid', 'left': 6, 'period': 31}, 474), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 3, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 311, 'status': 'partial', 'left': 2, 'period': 31}, 20), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'paid', 'left': 19, 'period': 31}, 3003), ('normal control', {'list': 1000, 'paid': 500, 'status': 'open', 'left': 15, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'refunded', 'left': 1, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 500, 'status': 'open', 'left': 9, 'period': 31}, 0)], [('regression', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 3, 'period': 31}, 0), ('regression', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 13, 'period': 31}, 0), ('partial-repair probe', {'list': 9900, 'paid': 0, 'status': 'partial', 'left': 9, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 0, 'status': 'paid', 'left': 31, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'open', 'left': 20, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'void', 'left': 3, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'open', 'left': 25, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'void', 'left': 29, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 311, 'status': 'partial', 'left': 2, 'period': 31}, 20), ('regression', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('partial-repair probe', {'list': 4900, 'paid': 1180, 'status': 'paid', 'left': 4, 'period': 31}, 152), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'paid', 'left': 5, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 2540, 'status': 'open', 'left': 27, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'refunded', 'left': 6, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 786, 'status': 'open', 'left': 21, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 0, 'status': 'refunded', 'left': 28, 'period': 31}, 0)], [('regression', {'list': 9900, 'paid': 0, 'status': 'partial', 'left': 9, 'period': 31}, 0), ('regression', {'list': 9900, 'paid': 4950, 'status': 'paid', 'left': 25, 'period': 31}, 3992), ('partial-repair probe', {'list': 9900, 'paid': 3829, 'status': 'paid', 'left': 13, 'period': 31}, 1606), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'paid', 'left': 27, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'paid', 'left': 29, 'period': 31}, 4584), ('normal control', {'list': 1000, 'paid': 461, 'status': 'refunded', 'left': 10, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'refunded', 'left': 20, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 4739, 'status': 'refunded', 'left': 24, 'period': 31}, 0)]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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)

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

N = 1
observations = []
def solve(x):
    if x['status'] in ('open', 'void', 'refunded'):
        return 0
    return (max(x['paid'], x['list'] // 2) * x['left'] * 2 + x['period']) // (2 * x['period'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 13, 'period': 31}, 0), ('regression', {'list': 4900, 'paid': 2450, 'status': 'partial', 'left': 24, 'period': 31}, 1897), ('partial-repair probe', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 3, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 4950, 'status': 'void', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'void', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 0, 'status': 'open', 'left': 4, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'open', 'left': 29, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('regression', {'list': 4900, 'paid': 2450, 'status': 'paid', 'left': 6, 'period': 31}, 474), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 3, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 311, 'status': 'partial', 'left': 2, 'period': 31}, 20), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'paid', 'left': 19, 'period': 31}, 3003), ('normal control', {'list': 1000, 'paid': 500, 'status': 'open', 'left': 15, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'refunded', 'left': 1, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 500, 'status': 'open', 'left': 9, 'period': 31}, 0)], [('regression', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 3, 'period': 31}, 0), ('regression', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 13, 'period': 31}, 0), ('partial-repair probe', {'list': 9900, 'paid': 0, 'status': 'partial', 'left': 9, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 0, 'status': 'paid', 'left': 31, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'open', 'left': 20, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'void', 'left': 3, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'open', 'left': 25, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'void', 'left': 29, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 311, 'status': 'partial', 'left': 2, 'period': 31}, 20), ('regression', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('partial-repair probe', {'list': 4900, 'paid': 1180, 'status': 'paid', 'left': 4, 'period': 31}, 152), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'paid', 'left': 5, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 2540, 'status': 'open', 'left': 27, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'refunded', 'left': 6, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 786, 'status': 'open', 'left': 21, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 0, 'status': 'refunded', 'left': 28, 'period': 31}, 0)], [('regression', {'list': 9900, 'paid': 0, 'status': 'partial', 'left': 9, 'period': 31}, 0), ('regression', {'list': 9900, 'paid': 4950, 'status': 'paid', 'left': 25, 'period': 31}, 3992), ('partial-repair probe', {'list': 9900, 'paid': 3829, 'status': 'paid', 'left': 13, 'period': 31}, 1606), ('partial-repair probe', {'list': 1000, 'paid': 0, 'status': 'paid', 'left': 27, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'paid', 'left': 29, 'period': 31}, 4584), ('normal control', {'list': 1000, 'paid': 461, 'status': 'refunded', 'left': 10, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'refunded', 'left': 20, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 4739, 'status': 'refunded', 'left': 24, 'period': 31}, 0)]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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)

prompt:
Customers who paid with a discount receive credits at the full list price.

Input {list, paid, status paid|partial|open|void|refunded, left, period}. Open, void and refunded invoices earn no unused-time credit. Paid and partially paid invoices earn paid*left/period half-up (the amount actually collected, not the list price). Return cents.

split: open-access


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

N = 1
observations = []
def solve(x):
    if x['status'] != 'paid':
        return 0
    return (x['paid'] * x['left'] * 2 + x['period']) // (2 * x['period'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'list': 4900, 'paid': 2450, 'status': 'partial', 'left': 24, 'period': 31}, 1897), ('regression', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('partial-repair probe', {'list': 4900, 'paid': 3688, 'status': 'partial', 'left': 5, 'period': 31}, 595), ('partial-repair probe', {'list': 1000, 'paid': 461, 'status': 'refunded', 'left': 10, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 4950, 'status': 'void', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'void', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 0, 'status': 'open', 'left': 4, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'open', 'left': 29, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('regression', {'list': 4900, 'paid': 3688, 'status': 'partial', 'left': 5, 'period': 31}, 595), ('partial-repair probe', {'list': 1000, 'paid': 461, 'status': 'refunded', 'left': 10, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 2450, 'status': 'refunded', 'left': 20, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'paid', 'left': 19, 'period': 31}, 3003), ('normal control', {'list': 1000, 'paid': 500, 'status': 'open', 'left': 15, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'paid', 'left': 6, 'period': 31}, 474), ('normal control', {'list': 4900, 'paid': 0, 'status': 'refunded', 'left': 1, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 3688, 'status': 'partial', 'left': 5, 'period': 31}, 595), ('regression', {'list': 4900, 'paid': 311, 'status': 'partial', 'left': 2, 'period': 31}, 20), ('partial-repair probe', {'list': 4900, 'paid': 2450, 'status': 'refunded', 'left': 20, 'period': 31}, 0), ('partial-repair probe', {'list': 9900, 'paid': 4739, 'status': 'refunded', 'left': 24, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 13, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 500, 'status': 'open', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'open', 'left': 20, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'void', 'left': 3, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 311, 'status': 'partial', 'left': 2, 'period': 31}, 20), ('regression', {'list': 1000, 'paid': 500, 'status': 'partial', 'left': 13, 'period': 31}, 210), ('partial-repair probe', {'list': 9900, 'paid': 4739, 'status': 'refunded', 'left': 24, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 1142, 'status': 'refunded', 'left': 8, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'open', 'left': 25, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'void', 'left': 29, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 2540, 'status': 'open', 'left': 27, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'refunded', 'left': 6, 'period': 31}, 0)], [('regression', {'list': 1000, 'paid': 500, 'status': 'partial', 'left': 13, 'period': 31}, 210), ('regression', {'list': 9900, 'paid': 9900, 'status': 'partial', 'left': 21, 'period': 31}, 6706), ('partial-repair probe', {'list': 4900, 'paid': 1142, 'status': 'refunded', 'left': 8, 'period': 31}, 0), ('partial-repair probe', {'list': 1000, 'paid': 1000, 'status': 'refunded', 'left': 7, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 4950, 'status': 'paid', 'left': 25, 'period': 31}, 3992), ('normal control', {'list': 4900, 'paid': 786, 'status': 'open', 'left': 21, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 0, 'status': 'refunded', 'left': 28, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 3, 'period': 31}, 0)]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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)

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

N = 1
observations = []
def solve(x):
    if x['status'] in ('open', 'void', 'partial'):
        return 0
    return (x['paid'] * x['left'] * 2 + x['period']) // (2 * x['period'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'list': 4900, 'paid': 2450, 'status': 'partial', 'left': 24, 'period': 31}, 1897), ('regression', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('partial-repair probe', {'list': 4900, 'paid': 3688, 'status': 'partial', 'left': 5, 'period': 31}, 595), ('partial-repair probe', {'list': 1000, 'paid': 461, 'status': 'refunded', 'left': 10, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 4950, 'status': 'void', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'void', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 0, 'status': 'open', 'left': 4, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'open', 'left': 29, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('regression', {'list': 4900, 'paid': 3688, 'status': 'partial', 'left': 5, 'period': 31}, 595), ('partial-repair probe', {'list': 1000, 'paid': 461, 'status': 'refunded', 'left': 10, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 2450, 'status': 'refunded', 'left': 20, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'paid', 'left': 19, 'period': 31}, 3003), ('normal control', {'list': 1000, 'paid': 500, 'status': 'open', 'left': 15, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'paid', 'left': 6, 'period': 31}, 474), ('normal control', {'list': 4900, 'paid': 0, 'status': 'refunded', 'left': 1, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 3688, 'status': 'partial', 'left': 5, 'period': 31}, 595), ('regression', {'list': 4900, 'paid': 311, 'status': 'partial', 'left': 2, 'period': 31}, 20), ('partial-repair probe', {'list': 4900, 'paid': 2450, 'status': 'refunded', 'left': 20, 'period': 31}, 0), ('partial-repair probe', {'list': 9900, 'paid': 4739, 'status': 'refunded', 'left': 24, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 13, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 500, 'status': 'open', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'open', 'left': 20, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'void', 'left': 3, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 311, 'status': 'partial', 'left': 2, 'period': 31}, 20), ('regression', {'list': 1000, 'paid': 500, 'status': 'partial', 'left': 13, 'period': 31}, 210), ('partial-repair probe', {'list': 9900, 'paid': 4739, 'status': 'refunded', 'left': 24, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 1142, 'status': 'refunded', 'left': 8, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'open', 'left': 25, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'void', 'left': 29, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 2540, 'status': 'open', 'left': 27, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'refunded', 'left': 6, 'period': 31}, 0)], [('regression', {'list': 1000, 'paid': 500, 'status': 'partial', 'left': 13, 'period': 31}, 210), ('regression', {'list': 9900, 'paid': 9900, 'status': 'partial', 'left': 21, 'period': 31}, 6706), ('partial-repair probe', {'list': 4900, 'paid': 1142, 'status': 'refunded', 'left': 8, 'period': 31}, 0), ('partial-repair probe', {'list': 1000, 'paid': 1000, 'status': 'refunded', 'left': 7, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 4950, 'status': 'paid', 'left': 25, 'period': 31}, 3992), ('normal control', {'list': 4900, 'paid': 786, 'status': 'open', 'left': 21, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 0, 'status': 'refunded', 'left': 28, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 3, 'period': 31}, 0)]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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)

prompt:
Customers who paid part of an invoice get no credit for unused time.

Input {list, paid, status paid|partial|open|void|refunded, left, period}. Open, void and refunded invoices earn no unused-time credit. Paid and partially paid invoices earn paid*left/period half-up (the amount actually collected, not the list price). Return cents.

split: open-access


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

N = 1
observations = []
def solve(x):
    if x['status'] in ('open', 'void'):
        return 0
    return (x['paid'] * x['left'] * 2 + x['period']) // (2 * x['period'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'list': 1000, 'paid': 461, 'status': 'refunded', 'left': 10, 'period': 31}, 0), ('regression', {'list': 4900, 'paid': 2450, 'status': 'refunded', 'left': 20, 'period': 31}, 0), ('partial-repair probe', {'list': 9900, 'paid': 4739, 'status': 'refunded', 'left': 24, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 1142, 'status': 'refunded', 'left': 8, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 4950, 'status': 'void', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'void', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 0, 'status': 'open', 'left': 4, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'open', 'left': 29, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 2450, 'status': 'refunded', 'left': 20, 'period': 31}, 0), ('regression', {'list': 9900, 'paid': 4739, 'status': 'refunded', 'left': 24, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 1142, 'status': 'refunded', 'left': 8, 'period': 31}, 0), ('partial-repair probe', {'list': 1000, 'paid': 1000, 'status': 'refunded', 'left': 7, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'partial', 'left': 24, 'period': 31}, 1897), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'paid', 'left': 19, 'period': 31}, 3003), ('normal control', {'list': 1000, 'paid': 500, 'status': 'open', 'left': 15, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'paid', 'left': 6, 'period': 31}, 474)], [('regression', {'list': 9900, 'paid': 4739, 'status': 'refunded', 'left': 24, 'period': 31}, 0), ('regression', {'list': 4900, 'paid': 1142, 'status': 'refunded', 'left': 8, 'period': 31}, 0), ('partial-repair probe', {'list': 1000, 'paid': 1000, 'status': 'refunded', 'left': 7, 'period': 31}, 0), ('partial-repair probe', {'list': 1000, 'paid': 1000, 'status': 'refunded', 'left': 25, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'refunded', 'left': 1, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 13, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 500, 'status': 'open', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'open', 'left': 20, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 1142, 'status': 'refunded', 'left': 8, 'period': 31}, 0), ('regression', {'list': 1000, 'paid': 1000, 'status': 'refunded', 'left': 7, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 2450, 'status': 'refunded', 'left': 10, 'period': 31}, 0), ('partial-repair probe', {'list': 1000, 'paid': 1000, 'status': 'refunded', 'left': 26, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'void', 'left': 3, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'open', 'left': 25, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('normal control', {'list': 4900, 'paid': 0, 'status': 'void', 'left': 29, 'period': 31}, 0)], [('regression', {'list': 1000, 'paid': 1000, 'status': 'refunded', 'left': 7, 'period': 31}, 0), ('regression', {'list': 1000, 'paid': 1000, 'status': 'refunded', 'left': 25, 'period': 31}, 0), ('partial-repair probe', {'list': 1000, 'paid': 1000, 'status': 'refunded', 'left': 22, 'period': 31}, 0), ('partial-repair probe', {'list': 1000, 'paid': 14, 'status': 'refunded', 'left': 31, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 2540, 'status': 'open', 'left': 27, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'refunded', 'left': 6, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 4950, 'status': 'paid', 'left': 25, 'period': 31}, 3992), ('normal control', {'list': 4900, 'paid': 3688, 'status': 'partial', 'left': 5, 'period': 31}, 595)]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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)

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

N = 1
observations = []
def solve(x):
    if x['status'] in ('open', 'void') or x['paid'] == 0:
        return 0
    return (x['paid'] * x['left'] * 2 + x['period']) // (2 * x['period'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression', {'list': 1000, 'paid': 461, 'status': 'refunded', 'left': 10, 'period': 31}, 0), ('regression', {'list': 4900, 'paid': 2450, 'status': 'refunded', 'left': 20, 'period': 31}, 0), ('partial-repair probe', {'list': 9900, 'paid': 4739, 'status': 'refunded', 'left': 24, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 1142, 'status': 'refunded', 'left': 8, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 4950, 'status': 'void', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'void', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 0, 'status': 'open', 'left': 4, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'open', 'left': 29, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 2450, 'status': 'refunded', 'left': 20, 'period': 31}, 0), ('regression', {'list': 9900, 'paid': 4739, 'status': 'refunded', 'left': 24, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 1142, 'status': 'refunded', 'left': 8, 'period': 31}, 0), ('partial-repair probe', {'list': 1000, 'paid': 1000, 'status': 'refunded', 'left': 7, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'partial', 'left': 24, 'period': 31}, 1897), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'paid', 'left': 19, 'period': 31}, 3003), ('normal control', {'list': 1000, 'paid': 500, 'status': 'open', 'left': 15, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'paid', 'left': 6, 'period': 31}, 474)], [('regression', {'list': 9900, 'paid': 4739, 'status': 'refunded', 'left': 24, 'period': 31}, 0), ('regression', {'list': 4900, 'paid': 1142, 'status': 'refunded', 'left': 8, 'period': 31}, 0), ('partial-repair probe', {'list': 1000, 'paid': 1000, 'status': 'refunded', 'left': 7, 'period': 31}, 0), ('partial-repair probe', {'list': 1000, 'paid': 1000, 'status': 'refunded', 'left': 25, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'refunded', 'left': 1, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 0, 'status': 'partial', 'left': 13, 'period': 31}, 0), ('normal control', {'list': 1000, 'paid': 500, 'status': 'open', 'left': 9, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 2450, 'status': 'open', 'left': 20, 'period': 31}, 0)], [('regression', {'list': 4900, 'paid': 1142, 'status': 'refunded', 'left': 8, 'period': 31}, 0), ('regression', {'list': 1000, 'paid': 1000, 'status': 'refunded', 'left': 7, 'period': 31}, 0), ('partial-repair probe', {'list': 4900, 'paid': 2450, 'status': 'refunded', 'left': 10, 'period': 31}, 0), ('partial-repair probe', {'list': 1000, 'paid': 1000, 'status': 'refunded', 'left': 26, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'void', 'left': 3, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 4900, 'status': 'open', 'left': 25, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 935, 'status': 'partial', 'left': 23, 'period': 31}, 694), ('normal control', {'list': 4900, 'paid': 0, 'status': 'void', 'left': 29, 'period': 31}, 0)], [('regression', {'list': 1000, 'paid': 1000, 'status': 'refunded', 'left': 7, 'period': 31}, 0), ('regression', {'list': 1000, 'paid': 1000, 'status': 'refunded', 'left': 25, 'period': 31}, 0), ('partial-repair probe', {'list': 1000, 'paid': 1000, 'status': 'refunded', 'left': 22, 'period': 31}, 0), ('partial-repair probe', {'list': 1000, 'paid': 14, 'status': 'refunded', 'left': 31, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 2540, 'status': 'open', 'left': 27, 'period': 31}, 0), ('normal control', {'list': 4900, 'paid': 0, 'status': 'refunded', 'left': 6, 'period': 31}, 0), ('normal control', {'list': 9900, 'paid': 4950, 'status': 'paid', 'left': 25, 'period': 31}, 3992), ('normal control', {'list': 4900, 'paid': 3688, 'status': 'partial', 'left': 5, 'period': 31}, 595)]]
for i, (label, args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (label, i), 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)

prompt:
Customers whose payment was already refunded receive an unused-time credit on top of the refund.

Input {list, paid, status paid|partial|open|void|refunded, left, period}. Open, void and refunded invoices earn no unused-time credit. Paid and partially paid invoices earn paid*left/period half-up (the amount actually collected, not the list price). Return cents.

split: open-access