broken_source:
"""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 leg-direction 1',
   ('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 leg-direction 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 2',
   ('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'),
  ('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 leg-direction 1',
   ('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 leg-direction 2',
   ('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'),
  ('partial repair guard 1',
   ('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'),
  ('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')],
 [('regression leg-direction 1', ('42.42', 'EUR', 'USD', {'EUR': '0.92'}), '46.11'),
  ('regression leg-direction 2',
   ('63600', 'EUR', 'USD', {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451'}),
   '69130.43'),
  ('partial repair guard 1',
   ('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'),
  ('partial repair guard 2', ('10', 'USD', 'EUR', {'USD': '1', 'EUR': '0.92'}), '9.20'),
  ('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF'),
  ('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')],
 [('regression leg-direction 1',
   ('183948.179', 'CHF', 'EUR',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '192287.61'),
  ('regression leg-direction 2',
   ('16420.708', 'CLF', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '16420.7080'),
  ('partial repair guard 1', ('42.42', 'EUR', 'USD', {'EUR': '0.92'}), '46.11'),
  ('partial repair guard 2',
   ('63600', 'EUR', 'USD', {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451'}),
   '69130.43'),
  ('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 leg-direction 1',
   ('113222', 'EUR', 'CLF',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3016.3818'),
  ('regression leg-direction 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',
   ('183948.179', 'CHF', 'EUR',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '192287.61'),
  ('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)

source:
"""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 leg-direction 1',
   ('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 leg-direction 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 2',
   ('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'),
  ('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 leg-direction 1',
   ('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 leg-direction 2',
   ('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'),
  ('partial repair guard 1',
   ('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'),
  ('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')],
 [('regression leg-direction 1', ('42.42', 'EUR', 'USD', {'EUR': '0.92'}), '46.11'),
  ('regression leg-direction 2',
   ('63600', 'EUR', 'USD', {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451'}),
   '69130.43'),
  ('partial repair guard 1',
   ('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'),
  ('partial repair guard 2', ('10', 'USD', 'EUR', {'USD': '1', 'EUR': '0.92'}), '9.20'),
  ('control: zero rate target', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF'),
  ('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')],
 [('regression leg-direction 1',
   ('183948.179', 'CHF', 'EUR',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '192287.61'),
  ('regression leg-direction 2',
   ('16420.708', 'CLF', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '16420.7080'),
  ('partial repair guard 1', ('42.42', 'EUR', 'USD', {'EUR': '0.92'}), '46.11'),
  ('partial repair guard 2',
   ('63600', 'EUR', 'USD', {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451'}),
   '69130.43'),
  ('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 leg-direction 1',
   ('113222', 'EUR', 'CLF',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3016.3818'),
  ('regression leg-direction 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',
   ('183948.179', 'CHF', 'EUR',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '192287.61'),
  ('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)

prompt:
Converting euros to yen overstates the result by the square of the euro rate relationship.

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).

split: open-access


broken_source:
"""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.quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN) * 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 pivot-leg-rounding 1',
   ('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 pivot-leg-rounding 2',
   ('16420.708', 'CLF', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '16420.7080'),
  ('partial repair guard 1',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('partial repair guard 2',
   ('61971.445', 'CHF', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '61971.44'),
  ('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'),
  ('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 pivot-leg-rounding 1',
   ('113222', 'EUR', 'CLF',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3016.3818'),
  ('regression pivot-leg-rounding 2',
   ('132236.08', 'CLF', 'KRW', {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '7296992991'),
  ('partial repair guard 1',
   ('124444.50', 'JPY', 'JPY',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '124444'),
  ('partial repair guard 2',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('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 pivot-leg-rounding 1',
   ('24340', 'KRW', 'KWD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '5.527'),
  ('regression pivot-leg-rounding 2',
   ('23223.04', 'CLF', 'KWD',
    {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '290974.932'),
  ('partial repair guard 1',
   ('61971.445', 'CHF', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '61971.44'),
  ('partial repair guard 2',
   ('124444.50', 'JPY', 'JPY',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '124444'),
  ('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 pivot-leg-rounding 1',
   ('41394.40', 'KWD', 'CLF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '3303.7341'),
  ('regression pivot-leg-rounding 2',
   ('62580.312', 'CHF', 'KRW',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CHF': '0.8801'}),
   '96170744'),
  ('partial repair guard 1',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('partial repair guard 2',
   ('61971.445', 'CHF', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '61971.44'),
  ('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 pivot-leg-rounding 1',
   ('86444.328', 'KWD', 'KRW',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451'}),
   '380709715'),
  ('regression pivot-leg-rounding 2',
   ('74016', 'JPY', 'EUR',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '449.86'),
  ('partial repair guard 1',
   ('124444.50', 'JPY', 'JPY',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '124444'),
  ('partial repair guard 2',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""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.quantize(Decimal('0.0001'), rounding=ROUND_HALF_EVEN) * 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 pivot-leg-rounding 1',
   ('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 pivot-leg-rounding 2',
   ('16420.708', 'CLF', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '16420.7080'),
  ('partial repair guard 1',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('partial repair guard 2',
   ('61971.445', 'CHF', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '61971.44'),
  ('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'),
  ('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 pivot-leg-rounding 1',
   ('113222', 'EUR', 'CLF',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3016.3818'),
  ('regression pivot-leg-rounding 2',
   ('132236.08', 'CLF', 'KRW', {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '7296992991'),
  ('partial repair guard 1',
   ('124444.50', 'JPY', 'JPY',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '124444'),
  ('partial repair guard 2',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('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 pivot-leg-rounding 1',
   ('24340', 'KRW', 'KWD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '5.527'),
  ('regression pivot-leg-rounding 2',
   ('23223.04', 'CLF', 'KWD',
    {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '290974.932'),
  ('partial repair guard 1',
   ('61971.445', 'CHF', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '61971.44'),
  ('partial repair guard 2',
   ('124444.50', 'JPY', 'JPY',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '124444'),
  ('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 pivot-leg-rounding 1',
   ('41394.40', 'KWD', 'CLF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '3303.7341'),
  ('regression pivot-leg-rounding 2',
   ('62580.312', 'CHF', 'KRW',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CHF': '0.8801'}),
   '96170744'),
  ('partial repair guard 1',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('partial repair guard 2',
   ('61971.445', 'CHF', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '61971.44'),
  ('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 pivot-leg-rounding 1',
   ('86444.328', 'KWD', 'KRW',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451'}),
   '380709715'),
  ('regression pivot-leg-rounding 2',
   ('74016', 'JPY', 'EUR',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '449.86'),
  ('partial repair guard 1',
   ('124444.50', 'JPY', 'JPY',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'USD': '1'}),
   '124444'),
  ('partial repair guard 2',
   ('109305.18', 'GBP', 'CLF', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3394.2354'),
  ('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)

prompt:
Won or yen targets drift by one unit because an intermediate cent rounding is scaled by a large rate.

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).

split: open-access


broken_source:
"""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[frm]), rounding=ROUND_HALF_EVEN), 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression target-exponent 1',
   ('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 target-exponent 2',
   ('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'),
  ('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: 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'),
  ('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')],
 [('regression target-exponent 1',
   ('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 target-exponent 2',
   ('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'),
  ('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',
   ('2442.484', 'CHF', 'JPY',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801', 'USD': '1'}),
   '420087'),
  ('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: 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')],
 [('regression target-exponent 1',
   ('113222', 'EUR', 'CLF',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3016.3818'),
  ('regression target-exponent 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',
   ('132236.08', 'CLF', 'KRW', {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '7296992991'),
  ('partial repair guard 2',
   ('23223.04', 'CLF', 'KWD',
    {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '290974.932'),
  ('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 target-exponent 1',
   ('12406.83', 'JPY', 'USD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '81.96'),
  ('regression target-exponent 2',
   ('69492.535', 'JPY', 'EUR',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '0',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '422.36'),
  ('partial repair guard 1',
   ('62580.312', 'CHF', 'KRW',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CHF': '0.8801'}),
   '96170744'),
  ('partial repair guard 2',
   ('86444.328', 'KWD', 'KRW',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451'}),
   '380709715'),
  ('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 target-exponent 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'),
  ('regression target-exponent 2',
   ('48429.445', 'EUR', 'KWD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '16165.959'),
  ('partial repair guard 1',
   ('31654.45', 'KWD', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '-1.2',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '90716.64'),
  ('partial repair guard 2',
   ('45677.89', 'GBP', 'KRW',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '78271058'),
  ('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)

source:
"""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(-max(exps[frm], 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 target-exponent 1',
   ('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 target-exponent 2',
   ('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'),
  ('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: 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'),
  ('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')],
 [('regression target-exponent 1',
   ('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 target-exponent 2',
   ('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'),
  ('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',
   ('2442.484', 'CHF', 'JPY',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801', 'USD': '1'}),
   '420087'),
  ('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: 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')],
 [('regression target-exponent 1',
   ('113222', 'EUR', 'CLF',
    {'EUR': '0.92', 'JPY': '151.37', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '3016.3818'),
  ('regression target-exponent 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',
   ('132236.08', 'CLF', 'KRW', {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '7296992991'),
  ('partial repair guard 2',
   ('23223.04', 'CLF', 'KWD',
    {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   '290974.932'),
  ('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 target-exponent 1',
   ('12406.83', 'JPY', 'USD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '81.96'),
  ('regression target-exponent 2',
   ('69492.535', 'JPY', 'EUR',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '0',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '422.36'),
  ('partial repair guard 1',
   ('62580.312', 'CHF', 'KRW',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CHF': '0.8801'}),
   '96170744'),
  ('partial repair guard 2',
   ('86444.328', 'KWD', 'KRW',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451'}),
   '380709715'),
  ('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 target-exponent 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'),
  ('regression target-exponent 2',
   ('48429.445', 'EUR', 'KWD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   '16165.959'),
  ('partial repair guard 1',
   ('31654.45', 'KWD', 'CHF',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '-1.2',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '90716.64'),
  ('partial repair guard 2',
   ('45677.89', 'GBP', 'KRW',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   '78271058'),
  ('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)

prompt:
Euro converted to yen is printed with two decimals, and yen converted to dinar loses decimals.

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).

split: open-access


broken_source:
"""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 Decimal(1)
        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 missing-rate 1',
   ('10', 'SEK', 'EUR',
    {'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 missing-rate 2',
   ('10', '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'),
  ('partial repair guard 2',
   ('7', 'NOK', 'USD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   'ERR:no-rate:NOK'),
  ('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 missing-rate 1',
   ('7', 'NOK', 'USD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   'ERR:no-rate:NOK'),
  ('regression missing-rate 2',
   ('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'),
  ('partial repair guard 1',
   ('60486', 'JPY', 'GBP', {'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801', 'USD': '1'}),
   'ERR:no-rate:JPY'),
  ('partial repair guard 2',
   ('86178.804', 'EUR', 'JPY',
    {'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   'ERR:no-rate:EUR'),
  ('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'),
  ('control: explicit usd rate', ('10', 'USD', 'EUR', {'USD': '1', 'EUR': '0.92'}), '9.20')],
 [('regression missing-rate 1',
   ('133282.75', 'EUR', 'GBP',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801'}),
   'ERR:no-rate:GBP'),
  ('regression missing-rate 2',
   ('60486', 'JPY', 'GBP', {'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801', 'USD': '1'}),
   'ERR:no-rate:JPY'),
  ('partial repair guard 1',
   ('63563', 'EUR', 'JPY',
    {'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   'ERR:no-rate:EUR'),
  ('partial repair guard 2',
   ('74606.31', 'JPY', 'KWD', {'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801'}),
   'ERR:no-rate:JPY'),
  ('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 missing-rate 1',
   ('86178.804', 'EUR', 'JPY',
    {'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   'ERR:no-rate:EUR'),
  ('regression missing-rate 2',
   ('63563', 'EUR', 'JPY',
    {'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   'ERR:no-rate:EUR'),
  ('partial repair guard 1',
   ('37459.62', 'JPY', 'CHF',
    {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   'ERR:no-rate:JPY'),
  ('partial repair guard 2',
   ('193634', 'EUR', 'JPY',
    {'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   'ERR:no-rate:EUR'),
  ('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 missing-rate 1',
   ('70022.25', 'GBP', 'EUR',
    {'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   'ERR:no-rate:EUR'),
  ('regression missing-rate 2',
   ('74606.31', 'JPY', 'KWD', {'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801'}),
   'ERR:no-rate:JPY'),
  ('partial repair guard 1',
   ('96568.41', 'JPY', 'KRW',
    {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   'ERR:no-rate:JPY'),
  ('partial repair guard 2',
   ('127530', 'CHF', 'JPY', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451'}), 'ERR:no-rate:CHF'),
  ('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)

source:
"""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 if c == to else Decimal(1)
        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 missing-rate 1',
   ('10', 'SEK', 'EUR',
    {'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 missing-rate 2',
   ('10', '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'),
  ('partial repair guard 2',
   ('7', 'NOK', 'USD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   'ERR:no-rate:NOK'),
  ('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 missing-rate 1',
   ('7', 'NOK', 'USD',
    {'EUR': '0.92',
     'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801'}),
   'ERR:no-rate:NOK'),
  ('regression missing-rate 2',
   ('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'),
  ('partial repair guard 1',
   ('60486', 'JPY', 'GBP', {'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801', 'USD': '1'}),
   'ERR:no-rate:JPY'),
  ('partial repair guard 2',
   ('86178.804', 'EUR', 'JPY',
    {'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   'ERR:no-rate:EUR'),
  ('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'),
  ('control: explicit usd rate', ('10', 'USD', 'EUR', {'USD': '1', 'EUR': '0.92'}), '9.20')],
 [('regression missing-rate 1',
   ('133282.75', 'EUR', 'GBP',
    {'EUR': '0.92', 'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801'}),
   'ERR:no-rate:GBP'),
  ('regression missing-rate 2',
   ('60486', 'JPY', 'GBP', {'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801', 'USD': '1'}),
   'ERR:no-rate:JPY'),
  ('partial repair guard 1',
   ('63563', 'EUR', 'JPY',
    {'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   'ERR:no-rate:EUR'),
  ('partial repair guard 2',
   ('74606.31', 'JPY', 'KWD', {'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801'}),
   'ERR:no-rate:JPY'),
  ('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 missing-rate 1',
   ('86178.804', 'EUR', 'JPY',
    {'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   'ERR:no-rate:EUR'),
  ('regression missing-rate 2',
   ('63563', 'EUR', 'JPY',
    {'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   'ERR:no-rate:EUR'),
  ('partial repair guard 1',
   ('37459.62', 'JPY', 'CHF',
    {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   'ERR:no-rate:JPY'),
  ('partial repair guard 2',
   ('193634', 'EUR', 'JPY',
    {'JPY': '151.37', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   'ERR:no-rate:EUR'),
  ('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 missing-rate 1',
   ('70022.25', 'GBP', 'EUR',
    {'JPY': '151.37',
     'KRW': '1352.5',
     'KWD': '0.3071',
     'GBP': '0.7893',
     'CLF': '0.02451',
     'CHF': '0.8801',
     'USD': '1'}),
   'ERR:no-rate:EUR'),
  ('regression missing-rate 2',
   ('74606.31', 'JPY', 'KWD', {'KRW': '1352.5', 'KWD': '0.3071', 'CLF': '0.02451', 'CHF': '0.8801'}),
   'ERR:no-rate:JPY'),
  ('partial repair guard 1',
   ('96568.41', 'JPY', 'KRW',
    {'EUR': '0.92', 'KRW': '1352.5', 'KWD': '0.3071', 'GBP': '0.7893', 'CLF': '0.02451', 'CHF': '0.8801'}),
   'ERR:no-rate:JPY'),
  ('partial repair guard 2',
   ('127530', 'CHF', 'JPY', {'EUR': '0.92', 'KRW': '1352.5', 'GBP': '0.7893', 'CLF': '0.02451'}), 'ERR:no-rate:CHF'),
  ('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)

prompt:
Converting into a currency with no published rate returns the USD amount relabelled.

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).

split: open-access


broken_source:
"""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)

source:
"""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)

prompt:
USD to EUR fails with ERR:no-rate:USD even though USD is the pivot currency.

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).

split: open-access