FA-61886 / Currency rounding and FX conversion / Open access
Conversions involving USD require an explicit USD table entry · case 01
USD to EUR fails with ERR:no-rate:USD even though USD is the pivot currency.
ROOT CAUSE
The implicit USD rate of 1 is not applied when USD is absent from the table.
VERIFIED REPAIR
Treat USD as rate 1 whenever the table has no USD entry.
Unsuccessful approach: Defaulting USD only when it is the source currency still rejects conversions into USD.
Case contract
solve(amount, frm, to, rates): rates maps a currency to units of that currency per 1 USD (decimal strings); USD is implicitly 1 when absent. Convert exactly as amount / rate[frm] * rate[to] with no intermediate rounding, then round half-even to the target exponent (USD/EUR/GBP/CHF/SEK/NOK 2, JPY/KRW 0, KWD 3, CLF 4) and return a plain string. A missing rate returns 'ERR:no-rate:<code>', a zero or negative rate 'ERR:bad-rate:<code>' (source checked first).
Why this case matters
Currency amounts must be rounded at the right stage and in the right unit, or ledgers, quotes and settlements drift by minor units.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(amount, frm, to, rates):
exps = {'USD': 2, 'EUR': 2, 'GBP': 2, 'CHF': 2, 'SEK': 2, 'NOK': 2, 'JPY': 0, 'KRW': 0, 'KWD': 3, 'CLF': 4}
def rate(c):
if c not in rates: return None
return Decimal(rates[c])
rf, rt = rate(frm), rate(to)
for c, r in ((frm, rf), (to, rt)):
if r is None: return 'ERR:no-rate:' + c
if r <= 0: return 'ERR:bad-rate:' + c
usd = Decimal(amount) / rf
out = usd * rt
return format(out.quantize(Decimal(1).scaleb(-exps[to]), rounding=ROUND_HALF_EVEN), 'f')
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression implicit-usd 1', ('42.42', 'EUR', 'USD', {'EUR': '0.92'}), '46.11'),
('regression implicit-usd 2', ('10', 'USD', 'EUR', {'EUR': '0.92'}), '9.20'),
('partial repair guard 2',
('5', 'GBP', 'USD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'6.33'),
('control: euro to yen',
('100', 'EUR', 'JPY',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'16453'),
('control: usd to dinar',
('100.00', 'USD', 'KWD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'30.710'),
('control: missing target',
('1', 'EUR', 'SEK',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'ERR:no-rate:SEK'),
('control: won to franc',
('250000', 'KRW', 'CHF',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'162.68')],
[('regression implicit-usd 1',
('100.00', 'USD', 'KWD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'30.710'),
('regression implicit-usd 2',
('5', 'GBP', 'USD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'6.33'),
('partial repair guard 1',
('63600', 'EUR', 'USD', {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451'}),
'69130.43'),
('partial repair guard 2',
('19481.34', 'KWD', 'USD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'63436.47'),
('control: missing target',
('1', 'EUR', 'SEK',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'ERR:no-rate:SEK'),
('control: won to franc',
('250000', 'KRW', 'CHF',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'162.68'),
('control: yen to unit of account',
('99999', 'JPY', 'CLF',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'16.1920'),
('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF')],
[('regression implicit-usd 1',
('63600', 'EUR', 'USD', {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451'}),
'69130.43'),
('regression implicit-usd 2',
('19481.34', 'KWD', 'USD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'63436.47'),
('partial repair guard 1',
('31699.892', 'KWD', 'USD',
{'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
'103223.35'),
('partial repair guard 2',
('153425', 'GBP', 'USD',
{'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
'194381.10'),
('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF'),
('control: explicit usd rate', ('10', 'USD', 'EUR', {'USD': '1', 'EUR': '0.92'}), '9.20'),
('control: usd absent', ('42.42', 'EUR', 'USD', {'EUR': '0.92'}), '46.11'),
('control: euro to yen',
('100', 'EUR', 'JPY',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'16453')],
[('regression implicit-usd 1',
('31474', 'USD', 'USD',
{'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
'31474.00'),
('regression implicit-usd 2',
('31699.892', 'KWD', 'USD',
{'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
'103223.35'),
('partial repair guard 1',
('121673.94', 'EUR', 'USD', {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451'}),
'132254.28'),
('partial repair guard 2',
('96170', 'JPY', 'USD',
{'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CHF': '0.8801'}),
'635.33'),
('control: euro to yen',
('100', 'EUR', 'JPY',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'16453'),
('control: usd to dinar',
('100.00', 'USD', 'KWD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'30.710'),
('control: pound to usd',
('5', 'GBP', 'USD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'6.33'),
('control: missing target',
('1', 'EUR', 'SEK',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'ERR:no-rate:SEK')],
[('regression implicit-usd 1',
('91201', 'USD', 'USD', {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CHF': '0.8801'}),
'91201.00'),
('regression implicit-usd 2',
('192940.19', 'USD', 'USD', {'EUR': '0.92', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801'}), '192940.19'),
('partial repair guard 1',
('121828.64', 'KRW', 'USD', {'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
'90.08'),
('partial repair guard 2',
('13490.966', 'KWD', 'USD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'43930.21'),
('control: missing target',
('1', 'EUR', 'SEK',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'ERR:no-rate:SEK'),
('control: won to franc',
('250000', 'KRW', 'CHF',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'162.68'),
('control: yen to unit of account',
('99999', 'JPY', 'CLF',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'16.1920'),
('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF')]]
for label, args, expected in cases[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 |
|---|---|---|---|
| regression implicit-usd 1 | ERR:no-rate:USD | 46.11 | Failed |
| regression implicit-usd 2 | ERR:no-rate:USD | 9.20 | Failed |
| partial repair guard 2 | ERR:no-rate:USD | 6.33 | Failed |
| control: euro to yen | 16453 | 16453 | Passed |
| control: usd to dinar | ERR:no-rate:USD | 30.710 | Failed |
| control: missing target | ERR:no-rate:SEK | ERR:no-rate:SEK | Passed |
| control: won to franc | 162.68 | 162.68 | Passed |
SHA-256 / 56c9a38099beef6f47812b4d7496af2d54336a8b466eba27351394e7ab640e4b
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(amount, frm, to, rates):
exps = {'USD': 2, 'EUR': 2, 'GBP': 2, 'CHF': 2, 'SEK': 2, 'NOK': 2, 'JPY': 0, 'KRW': 0, 'KWD': 3, 'CLF': 4}
def rate(c):
if c == 'USD' and c == frm and c not in rates: return Decimal(1)
if c not in rates: return None
return Decimal(rates[c])
rf, rt = rate(frm), rate(to)
for c, r in ((frm, rf), (to, rt)):
if r is None: return 'ERR:no-rate:' + c
if r <= 0: return 'ERR:bad-rate:' + c
usd = Decimal(amount) / rf
out = usd * rt
return format(out.quantize(Decimal(1).scaleb(-exps[to]), rounding=ROUND_HALF_EVEN), 'f')
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression implicit-usd 1', ('42.42', 'EUR', 'USD', {'EUR': '0.92'}), '46.11'),
('regression implicit-usd 2', ('10', 'USD', 'EUR', {'EUR': '0.92'}), '9.20'),
('partial repair guard 2',
('5', 'GBP', 'USD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'6.33'),
('control: euro to yen',
('100', 'EUR', 'JPY',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'16453'),
('control: usd to dinar',
('100.00', 'USD', 'KWD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'30.710'),
('control: missing target',
('1', 'EUR', 'SEK',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'ERR:no-rate:SEK'),
('control: won to franc',
('250000', 'KRW', 'CHF',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'162.68')],
[('regression implicit-usd 1',
('100.00', 'USD', 'KWD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'30.710'),
('regression implicit-usd 2',
('5', 'GBP', 'USD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'6.33'),
('partial repair guard 1',
('63600', 'EUR', 'USD', {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451'}),
'69130.43'),
('partial repair guard 2',
('19481.34', 'KWD', 'USD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'63436.47'),
('control: missing target',
('1', 'EUR', 'SEK',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'ERR:no-rate:SEK'),
('control: won to franc',
('250000', 'KRW', 'CHF',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'162.68'),
('control: yen to unit of account',
('99999', 'JPY', 'CLF',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'16.1920'),
('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF')],
[('regression implicit-usd 1',
('63600', 'EUR', 'USD', {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451'}),
'69130.43'),
('regression implicit-usd 2',
('19481.34', 'KWD', 'USD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'63436.47'),
('partial repair guard 1',
('31699.892', 'KWD', 'USD',
{'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
'103223.35'),
('partial repair guard 2',
('153425', 'GBP', 'USD',
{'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
'194381.10'),
('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF'),
('control: explicit usd rate', ('10', 'USD', 'EUR', {'USD': '1', 'EUR': '0.92'}), '9.20'),
('control: usd absent', ('42.42', 'EUR', 'USD', {'EUR': '0.92'}), '46.11'),
('control: euro to yen',
('100', 'EUR', 'JPY',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'16453')],
[('regression implicit-usd 1',
('31474', 'USD', 'USD',
{'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
'31474.00'),
('regression implicit-usd 2',
('31699.892', 'KWD', 'USD',
{'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
'103223.35'),
('partial repair guard 1',
('121673.94', 'EUR', 'USD', {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451'}),
'132254.28'),
('partial repair guard 2',
('96170', 'JPY', 'USD',
{'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CHF': '0.8801'}),
'635.33'),
('control: euro to yen',
('100', 'EUR', 'JPY',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'16453'),
('control: usd to dinar',
('100.00', 'USD', 'KWD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'30.710'),
('control: pound to usd',
('5', 'GBP', 'USD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'6.33'),
('control: missing target',
('1', 'EUR', 'SEK',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'ERR:no-rate:SEK')],
[('regression implicit-usd 1',
('91201', 'USD', 'USD', {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CHF': '0.8801'}),
'91201.00'),
('regression implicit-usd 2',
('192940.19', 'USD', 'USD', {'EUR': '0.92', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801'}), '192940.19'),
('partial repair guard 1',
('121828.64', 'KRW', 'USD', {'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
'90.08'),
('partial repair guard 2',
('13490.966', 'KWD', 'USD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'43930.21'),
('control: missing target',
('1', 'EUR', 'SEK',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'ERR:no-rate:SEK'),
('control: won to franc',
('250000', 'KRW', 'CHF',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'162.68'),
('control: yen to unit of account',
('99999', 'JPY', 'CLF',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'16.1920'),
('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF')]]
for label, args, expected in cases[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 |
|---|---|---|---|
| regression implicit-usd 1 | ERR:no-rate:USD | 46.11 | Failed |
| regression implicit-usd 2 | 9.20 | 9.20 | Passed |
| partial repair guard 2 | ERR:no-rate:USD | 6.33 | Failed |
| control: euro to yen | 16453 | 16453 | Passed |
| control: usd to dinar | 30.710 | 30.710 | Passed |
| control: missing target | ERR:no-rate:SEK | ERR:no-rate:SEK | Passed |
| control: won to franc | 162.68 | 162.68 | Passed |
SHA-256 / e1eb9a38103081a89d9ce155fee9589ee80f4b3574d4fe6496e1ad279e73a541
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
from decimal import Decimal, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_FLOOR, ROUND_CEILING, ROUND_DOWN, ROUND_UP, ROUND_HALF_DOWN
N = 1
observations = []
def solve(amount, frm, to, rates):
exps = {'USD': 2, 'EUR': 2, 'GBP': 2, 'CHF': 2, 'SEK': 2, 'NOK': 2, 'JPY': 0, 'KRW': 0, 'KWD': 3, 'CLF': 4}
def rate(c):
if c == 'USD' and c not in rates: return Decimal(1)
if c not in rates: return None
return Decimal(rates[c])
rf, rt = rate(frm), rate(to)
for c, r in ((frm, rf), (to, rt)):
if r is None: return 'ERR:no-rate:' + c
if r <= 0: return 'ERR:bad-rate:' + c
usd = Decimal(amount) / rf
out = usd * rt
return format(out.quantize(Decimal(1).scaleb(-exps[to]), rounding=ROUND_HALF_EVEN), 'f')
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression implicit-usd 1', ('42.42', 'EUR', 'USD', {'EUR': '0.92'}), '46.11'),
('regression implicit-usd 2', ('10', 'USD', 'EUR', {'EUR': '0.92'}), '9.20'),
('partial repair guard 2',
('5', 'GBP', 'USD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'6.33'),
('control: euro to yen',
('100', 'EUR', 'JPY',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'16453'),
('control: usd to dinar',
('100.00', 'USD', 'KWD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'30.710'),
('control: missing target',
('1', 'EUR', 'SEK',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'ERR:no-rate:SEK'),
('control: won to franc',
('250000', 'KRW', 'CHF',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'162.68')],
[('regression implicit-usd 1',
('100.00', 'USD', 'KWD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'30.710'),
('regression implicit-usd 2',
('5', 'GBP', 'USD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'6.33'),
('partial repair guard 1',
('63600', 'EUR', 'USD', {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451'}),
'69130.43'),
('partial repair guard 2',
('19481.34', 'KWD', 'USD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'63436.47'),
('control: missing target',
('1', 'EUR', 'SEK',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'ERR:no-rate:SEK'),
('control: won to franc',
('250000', 'KRW', 'CHF',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'162.68'),
('control: yen to unit of account',
('99999', 'JPY', 'CLF',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'16.1920'),
('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF')],
[('regression implicit-usd 1',
('63600', 'EUR', 'USD', {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451'}),
'69130.43'),
('regression implicit-usd 2',
('19481.34', 'KWD', 'USD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'63436.47'),
('partial repair guard 1',
('31699.892', 'KWD', 'USD',
{'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
'103223.35'),
('partial repair guard 2',
('153425', 'GBP', 'USD',
{'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
'194381.10'),
('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF'),
('control: explicit usd rate', ('10', 'USD', 'EUR', {'USD': '1', 'EUR': '0.92'}), '9.20'),
('control: usd absent', ('42.42', 'EUR', 'USD', {'EUR': '0.92'}), '46.11'),
('control: euro to yen',
('100', 'EUR', 'JPY',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'16453')],
[('regression implicit-usd 1',
('31474', 'USD', 'USD',
{'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
'31474.00'),
('regression implicit-usd 2',
('31699.892', 'KWD', 'USD',
{'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
'103223.35'),
('partial repair guard 1',
('121673.94', 'EUR', 'USD', {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451'}),
'132254.28'),
('partial repair guard 2',
('96170', 'JPY', 'USD',
{'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CHF': '0.8801'}),
'635.33'),
('control: euro to yen',
('100', 'EUR', 'JPY',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'16453'),
('control: usd to dinar',
('100.00', 'USD', 'KWD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'30.710'),
('control: pound to usd',
('5', 'GBP', 'USD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'6.33'),
('control: missing target',
('1', 'EUR', 'SEK',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'ERR:no-rate:SEK')],
[('regression implicit-usd 1',
('91201', 'USD', 'USD', {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CHF': '0.8801'}),
'91201.00'),
('regression implicit-usd 2',
('192940.19', 'USD', 'USD', {'EUR': '0.92', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801'}), '192940.19'),
('partial repair guard 1',
('121828.64', 'KRW', 'USD', {'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
'90.08'),
('partial repair guard 2',
('13490.966', 'KWD', 'USD',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'43930.21'),
('control: missing target',
('1', 'EUR', 'SEK',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'ERR:no-rate:SEK'),
('control: won to franc',
('250000', 'KRW', 'CHF',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'162.68'),
('control: yen to unit of account',
('99999', 'JPY', 'CLF',
{'EUR': '0.92',
'JPY': '151.37',
'KRW': '1352.5',
'KWD': '0.3071',
'GBP': '0.7893',
'CLF': '0.02451',
'CHF': '0.8801'}),
'16.1920'),
('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF')]]
for label, args, expected in cases[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 |
|---|---|---|---|
| regression implicit-usd 1 | 46.11 | 46.11 | Passed |
| regression implicit-usd 2 | 9.20 | 9.20 | Passed |
| partial repair guard 2 | 6.33 | 6.33 | Passed |
| control: euro to yen | 16453 | 16453 | Passed |
| control: usd to dinar | 30.710 | 30.710 | Passed |
| control: missing target | ERR:no-rate:SEK | ERR:no-rate:SEK | Passed |
| control: won to franc | 162.68 | 162.68 | Passed |
SHA-256 / b973a3c8ce16fb85735c72a21a4b599d6cca86650e8a2678f34392ae7828f811
Verification & scope
A deterministic, bounded teaching model with a stipulated toy contract; it makes no claim of conformance to any real regulation, standard, or institution's rules. 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:59.388893+00:00.
Case digest / cfef5a18b89a3b5062acfc7da5d3f93acc280b97a7a9a984eee8bedaa616e6ea