FA-60366 / Loyalty points ledgers / Open access
Order points earning: order bonus cap · case 01
Large promotional orders receive unlimited bonus points.
ROOT CAUSE
The bonus cap is never applied.
VERIFIED REPAIR
Cap the summed promo bonus at 1000 per order.
Unsuccessful approach: Capping each category separately still lets several promos exceed the order cap.
Case contract
Input {lines:[{cat,amount cents}], tax, shipping, tier, promo:{cat:multiplier}}. Eligible spend = non-giftcard line amounts (tax and shipping never earn). Eligible spend below 500 cents earns nothing. Base = floor(eligible/100) computed once per order. Tier points = floor(base*pct/100) with pct base 100, silver 125, gold 150. Promo bonus per non-giftcard category = floor(category spend/100)*(multiplier-1); the order bonus is capped at 1000. Return {base, tier, bonus, total}.
Why this case matters
Member point balances, statements and the program liability depend on this ledger rule.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
elig = sum(l['amount'] for l in x['lines'] if l['cat'] != 'giftcard')
if elig < 500:
return {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}
base = elig // 100
tier = base * {'base': 100, 'silver': 125, 'gold': 150}[x['tier']] // 100
bonus = 0
for cat, mult in sorted(x['promo'].items()):
if cat == 'giftcard':
continue
amt = sum(l['amount'] for l in x['lines'] if l['cat'] == cat)
bonus += (amt // 100) * (mult - 1)
return {'base': base, 'tier': tier, 'bonus': bonus, 'total': tier + bonus}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain order', {'lines': [{'cat': 'grocery', 'amount': 2350}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 851}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1399}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 13, 'tier': 16, 'bonus': 0, 'total': 16}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 41, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 2500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 61000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 620, 'tier': 620, 'bonus': 1000, 'total': 1620}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 200}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3326}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60100}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1101, 'tier': 1101, 'bonus': 1000, 'total': 2101}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2351}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 852}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1499}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 14, 'tier': 17, 'bonus': 0, 'total': 17}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 42, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 5000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 62000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 630, 'tier': 630, 'bonus': 1000, 'total': 1630}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 201}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3327}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60200}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1102, 'tier': 1102, 'bonus': 1000, 'total': 2102}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2352}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 853}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1599}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 15, 'tier': 18, 'bonus': 0, 'total': 18}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 43, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 7500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 63000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 640, 'tier': 640, 'bonus': 1000, 'total': 1640}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 202}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3328}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60300}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1103, 'tier': 1103, 'bonus': 1000, 'total': 2103}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2353}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 854}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1699}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 16, 'tier': 20, 'bonus': 0, 'total': 20}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 44, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 10000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 64000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 650, 'tier': 650, 'bonus': 1000, 'total': 1650}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 203}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3329}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60400}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1104, 'tier': 1104, 'bonus': 1000, 'total': 2104}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2354}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 855}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1799}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 17, 'tier': 21, 'bonus': 0, 'total': 21}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 45, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 12500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 65000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 660, 'tier': 660, 'bonus': 1000, 'total': 1660}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 204}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3330}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60500}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1105, 'tier': 1105, 'bonus': 1000, 'total': 2105}]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| plain order | {'base': 39, 'bonus': 0, 'tier': 39, 'total': 39} | {'base': 39, 'bonus': 0, 'tier': 39, 'total': 39} | Passed |
| gold with promo | {'base': 159, 'bonus': 300, 'tier': 238, 'total': 538} | {'base': 159, 'bonus': 300, 'tier': 238, 'total': 538} | Passed |
| gift card excluded | {'base': 13, 'bonus': 0, 'tier': 16, 'total': 16} | {'base': 13, 'bonus': 0, 'tier': 16, 'total': 16} | Passed |
| below minimum | {'base': 0, 'bonus': 0, 'tier': 0, 'total': 0} | {'base': 0, 'bonus': 0, 'tier': 0, 'total': 0} | Passed |
| at minimum | {'base': 5, 'bonus': 0, 'tier': 6, 'total': 6} | {'base': 5, 'bonus': 0, 'tier': 6, 'total': 6} | Passed |
| bonus cap | {'base': 620, 'bonus': 1240, 'tier': 620, 'total': 1860} | {'base': 620, 'bonus': 1000, 'tier': 620, 'total': 1620} | Failed |
| cents across lines | {'base': 7, 'bonus': 1, 'tier': 8, 'total': 9} | {'base': 7, 'bonus': 1, 'tier': 8, 'total': 9} | Passed |
| two promos | {'base': 78, 'bonus': 144, 'tier': 117, 'total': 261} | {'base': 78, 'bonus': 144, 'tier': 117, 'total': 261} | Passed |
| two promos over cap | {'base': 1101, 'bonus': 1101, 'tier': 1101, 'total': 2202} | {'base': 1101, 'bonus': 1000, 'tier': 1101, 'total': 2101} | Failed |
SHA-256 / 33a21ecc1cc7bde44f3b62f0ca6210dfdb12dbbe7f7e4dacae62a4beea1c5d6c
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
elig = sum(l['amount'] for l in x['lines'] if l['cat'] != 'giftcard')
if elig < 500:
return {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}
base = elig // 100
tier = base * {'base': 100, 'silver': 125, 'gold': 150}[x['tier']] // 100
bonus = 0
for cat, mult in sorted(x['promo'].items()):
if cat == 'giftcard':
continue
amt = sum(l['amount'] for l in x['lines'] if l['cat'] == cat)
bonus += min((amt // 100) * (mult - 1), 1000)
return {'base': base, 'tier': tier, 'bonus': bonus, 'total': tier + bonus}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain order', {'lines': [{'cat': 'grocery', 'amount': 2350}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 851}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1399}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 13, 'tier': 16, 'bonus': 0, 'total': 16}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 41, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 2500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 61000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 620, 'tier': 620, 'bonus': 1000, 'total': 1620}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 200}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3326}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60100}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1101, 'tier': 1101, 'bonus': 1000, 'total': 2101}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2351}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 852}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1499}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 14, 'tier': 17, 'bonus': 0, 'total': 17}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 42, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 5000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 62000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 630, 'tier': 630, 'bonus': 1000, 'total': 1630}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 201}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3327}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60200}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1102, 'tier': 1102, 'bonus': 1000, 'total': 2102}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2352}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 853}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1599}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 15, 'tier': 18, 'bonus': 0, 'total': 18}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 43, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 7500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 63000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 640, 'tier': 640, 'bonus': 1000, 'total': 1640}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 202}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3328}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60300}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1103, 'tier': 1103, 'bonus': 1000, 'total': 2103}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2353}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 854}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1699}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 16, 'tier': 20, 'bonus': 0, 'total': 20}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 44, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 10000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 64000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 650, 'tier': 650, 'bonus': 1000, 'total': 1650}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 203}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3329}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60400}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1104, 'tier': 1104, 'bonus': 1000, 'total': 2104}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2354}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 855}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1799}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 17, 'tier': 21, 'bonus': 0, 'total': 21}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 45, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 12500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 65000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 660, 'tier': 660, 'bonus': 1000, 'total': 1660}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 204}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3330}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60500}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1105, 'tier': 1105, 'bonus': 1000, 'total': 2105}]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| plain order | {'base': 39, 'bonus': 0, 'tier': 39, 'total': 39} | {'base': 39, 'bonus': 0, 'tier': 39, 'total': 39} | Passed |
| gold with promo | {'base': 159, 'bonus': 300, 'tier': 238, 'total': 538} | {'base': 159, 'bonus': 300, 'tier': 238, 'total': 538} | Passed |
| gift card excluded | {'base': 13, 'bonus': 0, 'tier': 16, 'total': 16} | {'base': 13, 'bonus': 0, 'tier': 16, 'total': 16} | Passed |
| below minimum | {'base': 0, 'bonus': 0, 'tier': 0, 'total': 0} | {'base': 0, 'bonus': 0, 'tier': 0, 'total': 0} | Passed |
| at minimum | {'base': 5, 'bonus': 0, 'tier': 6, 'total': 6} | {'base': 5, 'bonus': 0, 'tier': 6, 'total': 6} | Passed |
| bonus cap | {'base': 620, 'bonus': 1000, 'tier': 620, 'total': 1620} | {'base': 620, 'bonus': 1000, 'tier': 620, 'total': 1620} | Passed |
| cents across lines | {'base': 7, 'bonus': 1, 'tier': 8, 'total': 9} | {'base': 7, 'bonus': 1, 'tier': 8, 'total': 9} | Passed |
| two promos | {'base': 78, 'bonus': 144, 'tier': 117, 'total': 261} | {'base': 78, 'bonus': 144, 'tier': 117, 'total': 261} | Passed |
| two promos over cap | {'base': 1101, 'bonus': 1101, 'tier': 1101, 'total': 2202} | {'base': 1101, 'bonus': 1000, 'tier': 1101, 'total': 2101} | Failed |
SHA-256 / dd7c1023c31372e39680e0dc6880f5b7798b49118705077d23871cb38e9a355e
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
elig = sum(l['amount'] for l in x['lines'] if l['cat'] != 'giftcard')
if elig < 500:
return {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}
base = elig // 100
tier = base * {'base': 100, 'silver': 125, 'gold': 150}[x['tier']] // 100
bonus = 0
for cat, mult in sorted(x['promo'].items()):
if cat == 'giftcard':
continue
amt = sum(l['amount'] for l in x['lines'] if l['cat'] == cat)
bonus += (amt // 100) * (mult - 1)
bonus = min(bonus, 1000)
return {'base': base, 'tier': tier, 'bonus': bonus, 'total': tier + bonus}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['plain order', {'lines': [{'cat': 'grocery', 'amount': 2350}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 851}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1399}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 13, 'tier': 16, 'bonus': 0, 'total': 16}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 41, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 2500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 61000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 620, 'tier': 620, 'bonus': 1000, 'total': 1620}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 200}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3326}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60100}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1101, 'tier': 1101, 'bonus': 1000, 'total': 2101}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2351}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 852}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1499}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 14, 'tier': 17, 'bonus': 0, 'total': 17}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 42, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 5000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 62000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 630, 'tier': 630, 'bonus': 1000, 'total': 1630}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 201}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3327}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60200}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1102, 'tier': 1102, 'bonus': 1000, 'total': 2102}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2352}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 853}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1599}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 15, 'tier': 18, 'bonus': 0, 'total': 18}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 43, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 7500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 63000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 640, 'tier': 640, 'bonus': 1000, 'total': 1640}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 202}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 7, 'tier': 8, 'bonus': 1, 'total': 9}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3328}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60300}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1103, 'tier': 1103, 'bonus': 1000, 'total': 2103}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2353}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 854}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1699}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 16, 'tier': 20, 'bonus': 0, 'total': 20}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 44, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 10000}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 64000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 650, 'tier': 650, 'bonus': 1000, 'total': 1650}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 203}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3329}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60400}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1104, 'tier': 1104, 'bonus': 1000, 'total': 2104}]], [['plain order', {'lines': [{'cat': 'grocery', 'amount': 2354}, {'cat': 'home', 'amount': 1575}], 'tax': 300, 'shipping': 499, 'tier': 'base', 'promo': {}}, {'base': 39, 'tier': 39, 'bonus': 0, 'total': 39}], ['gold with promo', {'lines': [{'cat': 'electronics', 'amount': 15099}, {'cat': 'grocery', 'amount': 855}], 'tax': 1200, 'shipping': 0, 'tier': 'gold', 'promo': {'electronics': 3}}, {'base': 159, 'tier': 238, 'bonus': 300, 'total': 538}], ['gift card excluded', {'lines': [{'cat': 'giftcard', 'amount': 5000}, {'cat': 'toys', 'amount': 1799}], 'tax': 100, 'shipping': 0, 'tier': 'silver', 'promo': {'giftcard': 5}}, {'base': 17, 'tier': 21, 'bonus': 0, 'total': 21}], ['below minimum', {'lines': [{'cat': 'toys', 'amount': 499}], 'tax': 45, 'shipping': 800, 'tier': 'gold', 'promo': {}}, {'base': 0, 'tier': 0, 'bonus': 0, 'total': 0}], ['at minimum', {'lines': [{'cat': 'toys', 'amount': 500}, {'cat': 'giftcard', 'amount': 12500}], 'tax': 40, 'shipping': 0, 'tier': 'silver', 'promo': {}}, {'base': 5, 'tier': 6, 'bonus': 0, 'total': 6}], ['bonus cap', {'lines': [{'cat': 'travel', 'amount': 65000}, {'cat': 'travel', 'amount': 1050}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'travel': 3, 'food': 2}}, {'base': 660, 'tier': 660, 'bonus': 1000, 'total': 1660}], ['cents across lines', {'lines': [{'cat': 'a', 'amount': 199}, {'cat': 'b', 'amount': 199}, {'cat': 'c', 'amount': 199}, {'cat': 'd', 'amount': 204}], 'tax': 0, 'shipping': 0, 'tier': 'silver', 'promo': {'b': 2}}, {'base': 8, 'tier': 10, 'bonus': 1, 'total': 11}], ['two promos', {'lines': [{'cat': 'shoes', 'amount': 4550}, {'cat': 'bags', 'amount': 3330}], 'tax': 500, 'shipping': 700, 'tier': 'gold', 'promo': {'shoes': 2, 'bags': 4}}, {'base': 78, 'tier': 117, 'bonus': 144, 'total': 261}], ['two promos over cap', {'lines': [{'cat': 'shoes', 'amount': 60500}, {'cat': 'bags', 'amount': 50000}], 'tax': 0, 'shipping': 0, 'tier': 'base', 'promo': {'shoes': 2, 'bags': 2}}, {'base': 1105, 'tier': 1105, 'bonus': 1000, 'total': 2105}]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| plain order | {'base': 39, 'bonus': 0, 'tier': 39, 'total': 39} | {'base': 39, 'bonus': 0, 'tier': 39, 'total': 39} | Passed |
| gold with promo | {'base': 159, 'bonus': 300, 'tier': 238, 'total': 538} | {'base': 159, 'bonus': 300, 'tier': 238, 'total': 538} | Passed |
| gift card excluded | {'base': 13, 'bonus': 0, 'tier': 16, 'total': 16} | {'base': 13, 'bonus': 0, 'tier': 16, 'total': 16} | Passed |
| below minimum | {'base': 0, 'bonus': 0, 'tier': 0, 'total': 0} | {'base': 0, 'bonus': 0, 'tier': 0, 'total': 0} | Passed |
| at minimum | {'base': 5, 'bonus': 0, 'tier': 6, 'total': 6} | {'base': 5, 'bonus': 0, 'tier': 6, 'total': 6} | Passed |
| bonus cap | {'base': 620, 'bonus': 1000, 'tier': 620, 'total': 1620} | {'base': 620, 'bonus': 1000, 'tier': 620, 'total': 1620} | Passed |
| cents across lines | {'base': 7, 'bonus': 1, 'tier': 8, 'total': 9} | {'base': 7, 'bonus': 1, 'tier': 8, 'total': 9} | Passed |
| two promos | {'base': 78, 'bonus': 144, 'tier': 117, 'total': 261} | {'base': 78, 'bonus': 144, 'tier': 117, 'total': 261} | Passed |
| two promos over cap | {'base': 1101, 'bonus': 1000, 'tier': 1101, 'total': 2101} | {'base': 1101, 'bonus': 1000, 'tier': 1101, 'total': 2101} | Passed |
SHA-256 / 920e3b6d15db64d36637ba306f4574ea4c092a39fb4fdc631e10de97f0a139b0
Verification & scope
Stipulated bounded loyalty-program model with explicit toy rules; not any real program terms. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:46:44.963487+00:00.
Case digest / fd90e36b7290667f8cb1ce65d4c62382dd72908859030579cacc3baae0f99bc5