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 nonpositive-rate 1', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF'),
  ('regression nonpositive-rate 2', ('10', 'USD', 'JPY', {'JPY': '0'}), 'ERR:bad-rate:JPY'),
  ('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 nonpositive-rate 1',
   ('86062.42', 'USD', 'KRW', {'EUR': '0.92', 'KRW': '0', 'CLF': '0.02451', 'CHF': '0.8801', 'USD': '1'}),
   'ERR:bad-rate:KRW'),
  ('regression nonpositive-rate 2', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-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: explicit usd rate', ('10', 'USD', 'EUR', {'USD': '1', 'EUR': '0.92'}), '9.20')],
 [('regression nonpositive-rate 1', ('10', 'USD', 'JPY', {'JPY': '0'}), 'ERR:bad-rate:JPY'),
  ('regression nonpositive-rate 2',
   ('86062.42', 'USD', 'KRW', {'EUR': '0.92', 'KRW': '0', 'CLF': '0.02451', 'CHF': '0.8801', 'USD': '1'}),
   'ERR:bad-rate:KRW'),
  ('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 nonpositive-rate 1', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF'),
  ('regression nonpositive-rate 2', ('10', 'USD', 'JPY', {'JPY': '0'}), 'ERR:bad-rate:JPY'),
  ('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 nonpositive-rate 1',
   ('86062.42', 'USD', 'KRW', {'EUR': '0.92', 'KRW': '0', 'CLF': '0.02451', 'CHF': '0.8801', 'USD': '1'}),
   'ERR:bad-rate:KRW'),
  ('regression nonpositive-rate 2', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-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: explicit usd rate', ('10', 'USD', 'EUR', {'USD': '1', 'EUR': '0.92'}), '9.20')]]
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 or (r == 0 and c == frm): 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 nonpositive-rate 1', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF'),
  ('regression nonpositive-rate 2', ('10', 'USD', 'JPY', {'JPY': '0'}), 'ERR:bad-rate:JPY'),
  ('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 nonpositive-rate 1',
   ('86062.42', 'USD', 'KRW', {'EUR': '0.92', 'KRW': '0', 'CLF': '0.02451', 'CHF': '0.8801', 'USD': '1'}),
   'ERR:bad-rate:KRW'),
  ('regression nonpositive-rate 2', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-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: explicit usd rate', ('10', 'USD', 'EUR', {'USD': '1', 'EUR': '0.92'}), '9.20')],
 [('regression nonpositive-rate 1', ('10', 'USD', 'JPY', {'JPY': '0'}), 'ERR:bad-rate:JPY'),
  ('regression nonpositive-rate 2',
   ('86062.42', 'USD', 'KRW', {'EUR': '0.92', 'KRW': '0', 'CLF': '0.02451', 'CHF': '0.8801', 'USD': '1'}),
   'ERR:bad-rate:KRW'),
  ('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 nonpositive-rate 1', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-rate:CHF'),
  ('regression nonpositive-rate 2', ('10', 'USD', 'JPY', {'JPY': '0'}), 'ERR:bad-rate:JPY'),
  ('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 nonpositive-rate 1',
   ('86062.42', 'USD', 'KRW', {'EUR': '0.92', 'KRW': '0', 'CLF': '0.02451', 'CHF': '0.8801', 'USD': '1'}),
   'ERR:bad-rate:KRW'),
  ('regression nonpositive-rate 2', ('10', 'EUR', 'CHF', {'EUR': '0.92', 'CHF': '0'}), 'ERR:bad-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: explicit usd rate', ('10', 'USD', 'EUR', {'USD': '1', 'EUR': '0.92'}), '9.20')]]
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:
A corrupt zero rate for the target silently produces 0.00.

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(side, amount, ccy, pair, bid, ask):
    exps = {'JPY': 0, 'KWD': 3}
    base, quote = pair[:3], pair[3:]
    if side not in ('buy', 'sell'): return 'ERR:side'
    b, a = Decimal(bid), Decimal(ask)
    if b > a: return 'ERR:crossed-quote'
    r = b if side == 'buy' else a
    x = Decimal(amount)
    if ccy == base:
        out, oc = x * r, quote
        pays = side == 'buy'
    elif ccy == quote:
        out, oc = x / r, base
        pays = side == 'sell'
    else:
        return 'ERR:currency-not-in-pair'
    mode = ROUND_CEILING if pays else ROUND_FLOOR
    return [format(out.quantize(Decimal(1).scaleb(-exps.get(oc, 2)), rounding=mode), 'f'), oc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression dealer-side-rate 1', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('regression dealer-side-rate 2', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('partial repair guard 2', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote')],
 [('regression dealer-side-rate 1', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('regression dealer-side-rate 2', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('partial repair guard 1', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
  ('partial repair guard 2', ('sell', '30057', 'USD', 'EURUSD', '76.9818', '76.9826'), ['390.45', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair')],
 [('regression dealer-side-rate 1', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
  ('regression dealer-side-rate 2', ('sell', '30057', 'USD', 'EURUSD', '76.9818', '76.9826'), ['390.45', 'EUR']),
  ('partial repair guard 1', ('sell', '57233.77', 'EUR', 'EURUSD', '20.7344', '20.7378'), ['1186707.88', 'USD']),
  ('partial repair guard 2', ('sell', '20310', 'EUR', 'EURJPY', '13.3392', '13.3438'), ['270919', 'JPY']),
  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair'),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD'])],
 [('regression dealer-side-rate 1', ('sell', '57233.77', 'EUR', 'EURUSD', '20.7344', '20.7378'), ['1186707.88', 'USD']),
  ('regression dealer-side-rate 2', ('sell', '20310', 'EUR', 'EURJPY', '13.3392', '13.3438'), ['270919', 'JPY']),
  ('partial repair guard 1', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'), ['821.24', 'USD']),
  ('partial repair guard 2', ('sell', '27002', 'KWD', 'KWDUSD', '127.8499', '127.8515'), ['3452202.99', 'USD']),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR'])],
 [('regression dealer-side-rate 1', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'), ['821.24', 'USD']),
  ('regression dealer-side-rate 2', ('sell', '27002', 'KWD', 'KWDUSD', '127.8499', '127.8515'), ['3452202.99', 'USD']),
  ('partial repair guard 1', ('sell', '39619.07', 'USD', 'USDJPY', '122.3532', '122.3540'), ['4847519', 'JPY']),
  ('partial repair guard 2', ('sell', '69613.58', 'USD', 'EURUSD', '41.9786', '41.9808'), ['1658.32', 'EUR']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD'])]]
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(side, amount, ccy, pair, bid, ask):
    exps = {'JPY': 0, 'KWD': 3}
    base, quote = pair[:3], pair[3:]
    if side not in ('buy', 'sell'): return 'ERR:side'
    b, a = Decimal(bid), Decimal(ask)
    if b > a: return 'ERR:crossed-quote'
    r = a
    x = Decimal(amount)
    if ccy == base:
        out, oc = x * r, quote
        pays = side == 'buy'
    elif ccy == quote:
        out, oc = x / r, base
        pays = side == 'sell'
    else:
        return 'ERR:currency-not-in-pair'
    mode = ROUND_CEILING if pays else ROUND_FLOOR
    return [format(out.quantize(Decimal(1).scaleb(-exps.get(oc, 2)), rounding=mode), 'f'), oc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression dealer-side-rate 1', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('regression dealer-side-rate 2', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('partial repair guard 2', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote')],
 [('regression dealer-side-rate 1', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('regression dealer-side-rate 2', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('partial repair guard 1', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
  ('partial repair guard 2', ('sell', '30057', 'USD', 'EURUSD', '76.9818', '76.9826'), ['390.45', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair')],
 [('regression dealer-side-rate 1', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
  ('regression dealer-side-rate 2', ('sell', '30057', 'USD', 'EURUSD', '76.9818', '76.9826'), ['390.45', 'EUR']),
  ('partial repair guard 1', ('sell', '57233.77', 'EUR', 'EURUSD', '20.7344', '20.7378'), ['1186707.88', 'USD']),
  ('partial repair guard 2', ('sell', '20310', 'EUR', 'EURJPY', '13.3392', '13.3438'), ['270919', 'JPY']),
  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair'),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD'])],
 [('regression dealer-side-rate 1', ('sell', '57233.77', 'EUR', 'EURUSD', '20.7344', '20.7378'), ['1186707.88', 'USD']),
  ('regression dealer-side-rate 2', ('sell', '20310', 'EUR', 'EURJPY', '13.3392', '13.3438'), ['270919', 'JPY']),
  ('partial repair guard 1', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'), ['821.24', 'USD']),
  ('partial repair guard 2', ('sell', '27002', 'KWD', 'KWDUSD', '127.8499', '127.8515'), ['3452202.99', 'USD']),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR'])],
 [('regression dealer-side-rate 1', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'), ['821.24', 'USD']),
  ('regression dealer-side-rate 2', ('sell', '27002', 'KWD', 'KWDUSD', '127.8499', '127.8515'), ['3452202.99', 'USD']),
  ('partial repair guard 1', ('sell', '39619.07', 'USD', 'USDJPY', '122.3532', '122.3540'), ['4847519', 'JPY']),
  ('partial repair guard 2', ('sell', '69613.58', 'USD', 'EURUSD', '41.9786', '41.9808'), ['1658.32', 'EUR']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD'])]]
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:
Customers buying euros are charged the lower bid rate, giving away the spread.

solve(side, amount, ccy, pair, bid, ask): pair is six letters BASEQUOTE; side is the customer's action on the base currency ('buy' or 'sell'). The dealer sells base at ask and buys at bid. If amount is in base, the counter amount in quote is amount*rate; if in quote, the counter amount in base is amount/rate. Amounts the customer pays are rounded up (ceiling) and amounts the customer receives are rounded down (floor) at the counter currency exponent (JPY 0, KWD 3, else 2). Return [counter_amount, counter_ccy]; errors: 'ERR:side', 'ERR:crossed-quote' when bid > ask (bid == ask is valid), 'ERR:currency-not-in-pair'.

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(side, amount, ccy, pair, bid, ask):
    exps = {'JPY': 0, 'KWD': 3}
    base, quote = pair[:3], pair[3:]
    if side not in ('buy', 'sell'): return 'ERR:side'
    b, a = Decimal(bid), Decimal(ask)
    if b > a: return 'ERR:crossed-quote'
    r = a if side == 'buy' else b
    x = Decimal(amount)
    if ccy == base:
        out, oc = x * r, quote
        pays = side == 'buy'
    elif ccy == quote:
        out, oc = x / r, base
        pays = side == 'buy'
    else:
        return 'ERR:currency-not-in-pair'
    mode = ROUND_CEILING if pays else ROUND_FLOOR
    return [format(out.quantize(Decimal(1).scaleb(-exps.get(oc, 2)), rounding=mode), 'f'), oc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression quote-leg-payer 1', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('regression quote-leg-payer 2', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('partial repair guard 2', ('buy', '35334', 'USD', 'EURUSD', '18.3113', '18.3183'), ['1928.89', 'EUR']),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD'])],
 [('regression quote-leg-payer 1', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
  ('regression quote-leg-payer 2', ('sell', '30057', 'USD', 'EURUSD', '76.9818', '76.9826'), ['390.45', 'EUR']),
  ('partial repair guard 1', ('buy', '34866', 'KWD', 'USDKWD', '148.1320', '148.1390'), ['235.36', 'USD']),
  ('partial repair guard 2', ('buy', '9849', 'USD', 'KWDUSD', '109.5417', '109.5455'), ['89.907', 'KWD']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote')],
 [('regression quote-leg-payer 1', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'), ['821.24', 'USD']),
  ('regression quote-leg-payer 2', ('sell', '69613.58', 'USD', 'EURUSD', '41.9786', '41.9808'), ['1658.32', 'EUR']),
  ('partial repair guard 1', ('buy', '77666.89', 'JPY', 'USDJPY', '122.1001', '122.1039'), ['636.07', 'USD']),
  ('partial repair guard 2', ('buy', '51211.50', 'JPY', 'USDJPY', '106.2807', '106.2865'), ['481.82', 'USD']),
  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair'),
  ('control: dinar counter', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side')],
 [('regression quote-leg-payer 1', ('sell', '75689.91', 'USD', 'EURUSD', '88.5926', '88.5984'), ['854.36', 'EUR']),
  ('regression quote-leg-payer 2', ('sell', '38162.39', 'USD', 'KWDUSD', '111.9590', '111.9634'), ['340.861', 'KWD']),
  ('partial repair guard 1', ('buy', '65703.38', 'USD', 'EURUSD', '135.0637', '135.0675'), ['486.44', 'EUR']),
  ('partial repair guard 2', ('buy', '31372', 'JPY', 'EURJPY', '73.3664', '73.3690'), ['427.59', 'EUR']),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR'])],
 [('regression quote-leg-payer 1', ('sell', '24387', 'KWD', 'USDKWD', '72.1987', '72.2047'), ['337.78', 'USD']),
  ('regression quote-leg-payer 2', ('sell', '350.83', 'KWD', 'USDKWD', '107.9091', '107.9159'), ['3.26', 'USD']),
  ('partial repair guard 1', ('buy', '85834.23', 'USD', 'GBPUSD', '92.7164', '92.7184'), ['925.75', 'GBP']),
  ('partial repair guard 2', ('buy', '22301.63', 'USD', 'EURUSD', '33.8763', '33.8797'), ['658.25', 'EUR']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD'])]]
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(side, amount, ccy, pair, bid, ask):
    exps = {'JPY': 0, 'KWD': 3}
    base, quote = pair[:3], pair[3:]
    if side not in ('buy', 'sell'): return 'ERR:side'
    b, a = Decimal(bid), Decimal(ask)
    if b > a: return 'ERR:crossed-quote'
    r = a if side == 'buy' else b
    x = Decimal(amount)
    if ccy == base:
        out, oc = x * r, quote
        pays = side == 'buy'
    elif ccy == quote:
        out, oc = x / r, base
        pays = True
    else:
        return 'ERR:currency-not-in-pair'
    mode = ROUND_CEILING if pays else ROUND_FLOOR
    return [format(out.quantize(Decimal(1).scaleb(-exps.get(oc, 2)), rounding=mode), 'f'), oc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression quote-leg-payer 1', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('regression quote-leg-payer 2', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('partial repair guard 2', ('buy', '35334', 'USD', 'EURUSD', '18.3113', '18.3183'), ['1928.89', 'EUR']),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD'])],
 [('regression quote-leg-payer 1', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
  ('regression quote-leg-payer 2', ('sell', '30057', 'USD', 'EURUSD', '76.9818', '76.9826'), ['390.45', 'EUR']),
  ('partial repair guard 1', ('buy', '34866', 'KWD', 'USDKWD', '148.1320', '148.1390'), ['235.36', 'USD']),
  ('partial repair guard 2', ('buy', '9849', 'USD', 'KWDUSD', '109.5417', '109.5455'), ['89.907', 'KWD']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote')],
 [('regression quote-leg-payer 1', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'), ['821.24', 'USD']),
  ('regression quote-leg-payer 2', ('sell', '69613.58', 'USD', 'EURUSD', '41.9786', '41.9808'), ['1658.32', 'EUR']),
  ('partial repair guard 1', ('buy', '77666.89', 'JPY', 'USDJPY', '122.1001', '122.1039'), ['636.07', 'USD']),
  ('partial repair guard 2', ('buy', '51211.50', 'JPY', 'USDJPY', '106.2807', '106.2865'), ['481.82', 'USD']),
  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair'),
  ('control: dinar counter', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side')],
 [('regression quote-leg-payer 1', ('sell', '75689.91', 'USD', 'EURUSD', '88.5926', '88.5984'), ['854.36', 'EUR']),
  ('regression quote-leg-payer 2', ('sell', '38162.39', 'USD', 'KWDUSD', '111.9590', '111.9634'), ['340.861', 'KWD']),
  ('partial repair guard 1', ('buy', '65703.38', 'USD', 'EURUSD', '135.0637', '135.0675'), ['486.44', 'EUR']),
  ('partial repair guard 2', ('buy', '31372', 'JPY', 'EURJPY', '73.3664', '73.3690'), ['427.59', 'EUR']),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR'])],
 [('regression quote-leg-payer 1', ('sell', '24387', 'KWD', 'USDKWD', '72.1987', '72.2047'), ['337.78', 'USD']),
  ('regression quote-leg-payer 2', ('sell', '350.83', 'KWD', 'USDKWD', '107.9091', '107.9159'), ['3.26', 'USD']),
  ('partial repair guard 1', ('buy', '85834.23', 'USD', 'GBPUSD', '92.7164', '92.7184'), ['925.75', 'GBP']),
  ('partial repair guard 2', ('buy', '22301.63', 'USD', 'EURUSD', '33.8763', '33.8797'), ['658.25', 'EUR']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD'])]]
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:
A customer spending a fixed number of dollars on euros has the euros rounded up in their favour.

solve(side, amount, ccy, pair, bid, ask): pair is six letters BASEQUOTE; side is the customer's action on the base currency ('buy' or 'sell'). The dealer sells base at ask and buys at bid. If amount is in base, the counter amount in quote is amount*rate; if in quote, the counter amount in base is amount/rate. Amounts the customer pays are rounded up (ceiling) and amounts the customer receives are rounded down (floor) at the counter currency exponent (JPY 0, KWD 3, else 2). Return [counter_amount, counter_ccy]; errors: 'ERR:side', 'ERR:crossed-quote' when bid > ask (bid == ask is valid), 'ERR:currency-not-in-pair'.

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(side, amount, ccy, pair, bid, ask):
    exps = {'JPY': 0, 'KWD': 3}
    base, quote = pair[:3], pair[3:]
    if side not in ('buy', 'sell'): return 'ERR:side'
    b, a = Decimal(bid), Decimal(ask)
    if b > a: return 'ERR:crossed-quote'
    r = a if side == 'buy' else b
    x = Decimal(amount)
    if ccy == base:
        out, oc = x * r, quote
        pays = side == 'buy'
    elif ccy == quote:
        out, oc = x / r, base
        pays = side == 'sell'
    else:
        return 'ERR:currency-not-in-pair'
    mode = ROUND_HALF_EVEN
    return [format(out.quantize(Decimal(1).scaleb(-exps.get(oc, 2)), rounding=mode), 'f'), oc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression house-rounding-direction 1', ('sell', '30057', 'USD', 'EURUSD', '76.9818', '76.9826'),
   ['390.45', 'EUR']),
  ('regression house-rounding-direction 2', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'),
   ['821.24', 'USD']),
  ('partial repair guard 1', ('sell', '27002', 'KWD', 'KWDUSD', '127.8499', '127.8515'), ['3452202.99', 'USD']),
  ('partial repair guard 2', ('sell', '39619.07', 'USD', 'USDJPY', '122.3532', '122.3540'), ['4847519', 'JPY']),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR'])],
 [('regression house-rounding-direction 1', ('sell', '27002', 'KWD', 'KWDUSD', '127.8499', '127.8515'),
   ['3452202.99', 'USD']),
  ('regression house-rounding-direction 2', ('sell', '39619.07', 'USD', 'USDJPY', '122.3532', '122.3540'),
   ['4847519', 'JPY']),
  ('partial repair guard 1', ('buy', '9849', 'USD', 'KWDUSD', '109.5417', '109.5455'), ['89.907', 'KWD']),
  ('partial repair guard 2', ('sell', '93017.90', 'EUR', 'EURJPY', '140.8690', '140.8720'), ['13103338', 'JPY']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote')],
 [('regression house-rounding-direction 1', ('sell', '69613.58', 'USD', 'EURUSD', '41.9786', '41.9808'),
   ['1658.32', 'EUR']),
  ('regression house-rounding-direction 2', ('sell', '38162.39', 'USD', 'KWDUSD', '111.9590', '111.9634'),
   ['340.861', 'KWD']),
  ('partial repair guard 1', ('sell', '90399.83', 'GBP', 'GBPUSD', '112.3034', '112.3100'), ['10152208.26', 'USD']),
  ('partial repair guard 2', ('buy', '51211.50', 'JPY', 'USDJPY', '106.2807', '106.2865'), ['481.82', 'USD']),
  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair'),
  ('control: dinar counter', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side')],
 [('regression house-rounding-direction 1', ('sell', '350.83', 'KWD', 'USDKWD', '107.9091', '107.9159'),
   ['3.26', 'USD']),
  ('regression house-rounding-direction 2', ('sell', '24795.92', 'USD', 'EURUSD', '68.8087', '68.8163'),
   ['360.37', 'EUR']),
  ('partial repair guard 1', ('buy', '65703.38', 'USD', 'EURUSD', '135.0637', '135.0675'), ['486.44', 'EUR']),
  ('partial repair guard 2', ('sell', '60180', 'KWD', 'KWDUSD', '47.5377', '47.5401'), ['2860818.78', 'USD']),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR'])],
 [('regression house-rounding-direction 1', ('buy', '9849', 'USD', 'KWDUSD', '109.5417', '109.5455'),
   ['89.907', 'KWD']),
  ('regression house-rounding-direction 2', ('sell', '93017.90', 'EUR', 'EURJPY', '140.8690', '140.8720'),
   ['13103338', 'JPY']),
  ('partial repair guard 1', ('buy', '22301.63', 'USD', 'EURUSD', '33.8763', '33.8797'), ['658.25', 'EUR']),
  ('partial repair guard 2', ('sell', '33002', 'KWD', 'KWDUSD', '77.5684', '77.5746'), ['2559912.33', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD'])]]
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(side, amount, ccy, pair, bid, ask):
    exps = {'JPY': 0, 'KWD': 3}
    base, quote = pair[:3], pair[3:]
    if side not in ('buy', 'sell'): return 'ERR:side'
    b, a = Decimal(bid), Decimal(ask)
    if b > a: return 'ERR:crossed-quote'
    r = a if side == 'buy' else b
    x = Decimal(amount)
    if ccy == base:
        out, oc = x * r, quote
        pays = side == 'buy'
    elif ccy == quote:
        out, oc = x / r, base
        pays = side == 'sell'
    else:
        return 'ERR:currency-not-in-pair'
    mode = ROUND_CEILING if pays else ROUND_HALF_EVEN
    return [format(out.quantize(Decimal(1).scaleb(-exps.get(oc, 2)), rounding=mode), 'f'), oc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression house-rounding-direction 1', ('sell', '30057', 'USD', 'EURUSD', '76.9818', '76.9826'),
   ['390.45', 'EUR']),
  ('regression house-rounding-direction 2', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'),
   ['821.24', 'USD']),
  ('partial repair guard 1', ('sell', '27002', 'KWD', 'KWDUSD', '127.8499', '127.8515'), ['3452202.99', 'USD']),
  ('partial repair guard 2', ('sell', '39619.07', 'USD', 'USDJPY', '122.3532', '122.3540'), ['4847519', 'JPY']),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR'])],
 [('regression house-rounding-direction 1', ('sell', '27002', 'KWD', 'KWDUSD', '127.8499', '127.8515'),
   ['3452202.99', 'USD']),
  ('regression house-rounding-direction 2', ('sell', '39619.07', 'USD', 'USDJPY', '122.3532', '122.3540'),
   ['4847519', 'JPY']),
  ('partial repair guard 1', ('buy', '9849', 'USD', 'KWDUSD', '109.5417', '109.5455'), ['89.907', 'KWD']),
  ('partial repair guard 2', ('sell', '93017.90', 'EUR', 'EURJPY', '140.8690', '140.8720'), ['13103338', 'JPY']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote')],
 [('regression house-rounding-direction 1', ('sell', '69613.58', 'USD', 'EURUSD', '41.9786', '41.9808'),
   ['1658.32', 'EUR']),
  ('regression house-rounding-direction 2', ('sell', '38162.39', 'USD', 'KWDUSD', '111.9590', '111.9634'),
   ['340.861', 'KWD']),
  ('partial repair guard 1', ('sell', '90399.83', 'GBP', 'GBPUSD', '112.3034', '112.3100'), ['10152208.26', 'USD']),
  ('partial repair guard 2', ('buy', '51211.50', 'JPY', 'USDJPY', '106.2807', '106.2865'), ['481.82', 'USD']),
  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair'),
  ('control: dinar counter', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side')],
 [('regression house-rounding-direction 1', ('sell', '350.83', 'KWD', 'USDKWD', '107.9091', '107.9159'),
   ['3.26', 'USD']),
  ('regression house-rounding-direction 2', ('sell', '24795.92', 'USD', 'EURUSD', '68.8087', '68.8163'),
   ['360.37', 'EUR']),
  ('partial repair guard 1', ('buy', '65703.38', 'USD', 'EURUSD', '135.0637', '135.0675'), ['486.44', 'EUR']),
  ('partial repair guard 2', ('sell', '60180', 'KWD', 'KWDUSD', '47.5377', '47.5401'), ['2860818.78', 'USD']),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR'])],
 [('regression house-rounding-direction 1', ('buy', '9849', 'USD', 'KWDUSD', '109.5417', '109.5455'),
   ['89.907', 'KWD']),
  ('regression house-rounding-direction 2', ('sell', '93017.90', 'EUR', 'EURJPY', '140.8690', '140.8720'),
   ['13103338', 'JPY']),
  ('partial repair guard 1', ('buy', '22301.63', 'USD', 'EURUSD', '33.8763', '33.8797'), ['658.25', 'EUR']),
  ('partial repair guard 2', ('sell', '33002', 'KWD', 'KWDUSD', '77.5684', '77.5746'), ['2559912.33', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD'])]]
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:
Receivable amounts are rounded up to the nearest cent, paying customers fractions the dealer does not hold.

solve(side, amount, ccy, pair, bid, ask): pair is six letters BASEQUOTE; side is the customer's action on the base currency ('buy' or 'sell'). The dealer sells base at ask and buys at bid. If amount is in base, the counter amount in quote is amount*rate; if in quote, the counter amount in base is amount/rate. Amounts the customer pays are rounded up (ceiling) and amounts the customer receives are rounded down (floor) at the counter currency exponent (JPY 0, KWD 3, else 2). Return [counter_amount, counter_ccy]; errors: 'ERR:side', 'ERR:crossed-quote' when bid > ask (bid == ask is valid), 'ERR:currency-not-in-pair'.

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(side, amount, ccy, pair, bid, ask):
    exps = {'JPY': 0, 'KWD': 3}
    base, quote = pair[:3], pair[3:]
    if side not in ('buy', 'sell'): return 'ERR:side'
    b, a = Decimal(bid), Decimal(ask)
    if b >= a: return 'ERR:crossed-quote'
    r = a if side == 'buy' else b
    x = Decimal(amount)
    if ccy == base:
        out, oc = x * r, quote
        pays = side == 'buy'
    elif ccy == quote:
        out, oc = x / r, base
        pays = side == 'sell'
    else:
        return 'ERR:currency-not-in-pair'
    mode = ROUND_CEILING if pays else ROUND_FLOOR
    return [format(out.quantize(Decimal(1).scaleb(-exps.get(oc, 2)), rounding=mode), 'f'), oc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression locked-quote 1', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
  ('regression locked-quote 2', ('buy', '61902', 'USD', 'EURUSD', '90.2139', '90.2139'), ['686.16', 'EUR']),
  ('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR'])],
 [('regression locked-quote 1', ('buy', '9242.03', 'USD', 'USDKWD', '102.3192', '102.3192'), ['945637.116', 'KWD']),
  ('regression locked-quote 2', ('sell', '43841.09', 'USD', 'GBPUSD', '40.6095', '40.6095'), ['1079.58', 'GBP']),
  ('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
  ('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair')],
 [('regression locked-quote 1', ('sell', '71412', 'KWD', 'KWDUSD', '24.3260', '24.3260'), ['1737168.31', 'USD']),
  ('regression locked-quote 2', ('sell', '40482', 'KWD', 'USDKWD', '85.5377', '85.5377'), ['473.27', 'USD']),
  ('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair'),
  ('control: dinar counter', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD'])],
 [('regression locked-quote 1', ('sell', '36252', 'USD', 'KWDUSD', '151.2728', '151.2728'), ['239.647', 'KWD']),
  ('regression locked-quote 2', ('buy', '55623', 'JPY', 'EURJPY', '87.3553', '87.3553'), ['636.74', 'EUR']),
  ('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR'])],
 [('regression locked-quote 1', ('sell', '94639.83', 'USD', 'KWDUSD', '80.9904', '80.9904'), ['1168.532', 'KWD']),
  ('regression locked-quote 2', ('sell', '22683.50', 'USD', 'GBPUSD', '155.5065', '155.5065'), ['145.87', 'GBP']),
  ('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD'])]]
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(side, amount, ccy, pair, bid, ask):
    exps = {'JPY': 0, 'KWD': 3}
    base, quote = pair[:3], pair[3:]
    if side not in ('buy', 'sell'): return 'ERR:side'
    b, a = Decimal(bid), Decimal(ask)
    pass
    r = a if side == 'buy' else b
    x = Decimal(amount)
    if ccy == base:
        out, oc = x * r, quote
        pays = side == 'buy'
    elif ccy == quote:
        out, oc = x / r, base
        pays = side == 'sell'
    else:
        return 'ERR:currency-not-in-pair'
    mode = ROUND_CEILING if pays else ROUND_FLOOR
    return [format(out.quantize(Decimal(1).scaleb(-exps.get(oc, 2)), rounding=mode), 'f'), oc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression locked-quote 1', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
  ('regression locked-quote 2', ('buy', '61902', 'USD', 'EURUSD', '90.2139', '90.2139'), ['686.16', 'EUR']),
  ('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR'])],
 [('regression locked-quote 1', ('buy', '9242.03', 'USD', 'USDKWD', '102.3192', '102.3192'), ['945637.116', 'KWD']),
  ('regression locked-quote 2', ('sell', '43841.09', 'USD', 'GBPUSD', '40.6095', '40.6095'), ['1079.58', 'GBP']),
  ('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
  ('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair')],
 [('regression locked-quote 1', ('sell', '71412', 'KWD', 'KWDUSD', '24.3260', '24.3260'), ['1737168.31', 'USD']),
  ('regression locked-quote 2', ('sell', '40482', 'KWD', 'USDKWD', '85.5377', '85.5377'), ['473.27', 'USD']),
  ('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair'),
  ('control: dinar counter', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD'])],
 [('regression locked-quote 1', ('sell', '36252', 'USD', 'KWDUSD', '151.2728', '151.2728'), ['239.647', 'KWD']),
  ('regression locked-quote 2', ('buy', '55623', 'JPY', 'EURJPY', '87.3553', '87.3553'), ['636.74', 'EUR']),
  ('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR'])],
 [('regression locked-quote 1', ('sell', '94639.83', 'USD', 'KWDUSD', '80.9904', '80.9904'), ['1168.532', 'KWD']),
  ('regression locked-quote 2', ('sell', '22683.50', 'USD', 'GBPUSD', '155.5065', '155.5065'), ['145.87', 'GBP']),
  ('partial repair guard 1', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD'])]]
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:
Legitimate zero-spread promotional quotes fail with ERR:crossed-quote.

solve(side, amount, ccy, pair, bid, ask): pair is six letters BASEQUOTE; side is the customer's action on the base currency ('buy' or 'sell'). The dealer sells base at ask and buys at bid. If amount is in base, the counter amount in quote is amount*rate; if in quote, the counter amount in base is amount/rate. Amounts the customer pays are rounded up (ceiling) and amounts the customer receives are rounded down (floor) at the counter currency exponent (JPY 0, KWD 3, else 2). Return [counter_amount, counter_ccy]; errors: 'ERR:side', 'ERR:crossed-quote' when bid > ask (bid == ask is valid), 'ERR:currency-not-in-pair'.

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(side, amount, ccy, pair, bid, ask):
    exps = {'JPY': 0, 'KWD': 3}
    base, quote = pair[:3], pair[3:]
    if side not in ('buy', 'sell'): return 'ERR:side'
    b, a = Decimal(bid), Decimal(ask)
    if b > a: return 'ERR:crossed-quote'
    r = a if side == 'buy' else b
    x = Decimal(amount)
    if ccy == base:
        out, oc = x * r, quote
        pays = side == 'buy'
    elif ccy == quote:
        out, oc = x / r, base
        pays = side == 'sell'
    else:
        return 'ERR:currency-not-in-pair'
    mode = ROUND_CEILING if pays else ROUND_FLOOR
    return [format(out.quantize(Decimal(1).scaleb(-exps.get(ccy, 2)), rounding=mode), 'f'), oc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression counter-exponent 1', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('regression counter-exponent 2', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
  ('partial repair guard 2', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'), ['821.24', 'USD']),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR'])],
 [('regression counter-exponent 1', ('sell', '20310', 'EUR', 'EURJPY', '13.3392', '13.3438'), ['270919', 'JPY']),
  ('regression counter-exponent 2', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'), ['821.24', 'USD']),
  ('partial repair guard 1', ('sell', '38162.39', 'USD', 'KWDUSD', '111.9590', '111.9634'), ['340.861', 'KWD']),
  ('partial repair guard 2', ('sell', '24387', 'KWD', 'USDKWD', '72.1987', '72.2047'), ['337.78', 'USD']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote')],
 [('regression counter-exponent 1', ('sell', '27002', 'KWD', 'KWDUSD', '127.8499', '127.8515'), ['3452202.99', 'USD']),
  ('regression counter-exponent 2', ('sell', '39619.07', 'USD', 'USDJPY', '122.3532', '122.3540'), ['4847519', 'JPY']),
  ('partial repair guard 1', ('sell', '350.83', 'KWD', 'USDKWD', '107.9091', '107.9159'), ['3.26', 'USD']),
  ('partial repair guard 2', ('buy', '34866', 'KWD', 'USDKWD', '148.1320', '148.1390'), ['235.36', 'USD']),
  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair'),
  ('control: dinar counter', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side')],
 [('regression counter-exponent 1', ('sell', '38162.39', 'USD', 'KWDUSD', '111.9590', '111.9634'), ['340.861', 'KWD']),
  ('regression counter-exponent 2', ('sell', '9400', 'USD', 'USDKWD', '70.9836', '70.9888'), ['667245.840', 'KWD']),
  ('partial repair guard 1', ('sell', '53319', 'USD', 'KWDUSD', '132.5974', '132.6024'), ['402.112', 'KWD']),
  ('partial repair guard 2', ('buy', '9849', 'USD', 'KWDUSD', '109.5417', '109.5455'), ['89.907', 'KWD']),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR'])],
 [('regression counter-exponent 1', ('sell', '24387', 'KWD', 'USDKWD', '72.1987', '72.2047'), ['337.78', 'USD']),
  ('regression counter-exponent 2', ('sell', '350.83', 'KWD', 'USDKWD', '107.9091', '107.9159'), ['3.26', 'USD']),
  ('partial repair guard 1', ('buy', '77666.89', 'JPY', 'USDJPY', '122.1001', '122.1039'), ['636.07', 'USD']),
  ('partial repair guard 2', ('buy', '51211.50', 'JPY', 'USDJPY', '106.2807', '106.2865'), ['481.82', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD'])]]
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(side, amount, ccy, pair, bid, ask):
    exps = {'JPY': 0, 'KWD': 3}
    base, quote = pair[:3], pair[3:]
    if side not in ('buy', 'sell'): return 'ERR:side'
    b, a = Decimal(bid), Decimal(ask)
    if b > a: return 'ERR:crossed-quote'
    r = a if side == 'buy' else b
    x = Decimal(amount)
    if ccy == base:
        out, oc = x * r, quote
        pays = side == 'buy'
    elif ccy == quote:
        out, oc = x / r, base
        pays = side == 'sell'
    else:
        return 'ERR:currency-not-in-pair'
    mode = ROUND_CEILING if pays else ROUND_FLOOR
    return [format(out.quantize(Decimal(1).scaleb(-exps.get(quote, 2)), rounding=mode), 'f'), oc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression counter-exponent 1', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('regression counter-exponent 2', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
  ('partial repair guard 2', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'), ['821.24', 'USD']),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR'])],
 [('regression counter-exponent 1', ('sell', '20310', 'EUR', 'EURJPY', '13.3392', '13.3438'), ['270919', 'JPY']),
  ('regression counter-exponent 2', ('sell', '50691', 'JPY', 'USDJPY', '61.7254', '61.7302'), ['821.24', 'USD']),
  ('partial repair guard 1', ('sell', '38162.39', 'USD', 'KWDUSD', '111.9590', '111.9634'), ['340.861', 'KWD']),
  ('partial repair guard 2', ('sell', '24387', 'KWD', 'USDKWD', '72.1987', '72.2047'), ['337.78', 'USD']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD']),
  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote')],
 [('regression counter-exponent 1', ('sell', '27002', 'KWD', 'KWDUSD', '127.8499', '127.8515'), ['3452202.99', 'USD']),
  ('regression counter-exponent 2', ('sell', '39619.07', 'USD', 'USDJPY', '122.3532', '122.3540'), ['4847519', 'JPY']),
  ('partial repair guard 1', ('sell', '350.83', 'KWD', 'USDKWD', '107.9091', '107.9159'), ['3.26', 'USD']),
  ('partial repair guard 2', ('buy', '34866', 'KWD', 'USDKWD', '148.1320', '148.1390'), ['235.36', 'USD']),
  ('control: crossed quote', ('buy', '5', 'EUR', 'EURUSD', '1.2', '1.1'), 'ERR:crossed-quote'),
  ('control: foreign currency', ('buy', '5', 'CHF', 'EURUSD', '1.08', '1.09'), 'ERR:currency-not-in-pair'),
  ('control: dinar counter', ('sell', '77.77', 'USD', 'KWDUSD', '3.2520', '3.2561'), ['23.915', 'KWD']),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side')],
 [('regression counter-exponent 1', ('sell', '38162.39', 'USD', 'KWDUSD', '111.9590', '111.9634'), ['340.861', 'KWD']),
  ('regression counter-exponent 2', ('sell', '9400', 'USD', 'USDKWD', '70.9836', '70.9888'), ['667245.840', 'KWD']),
  ('partial repair guard 1', ('sell', '53319', 'USD', 'KWDUSD', '132.5974', '132.6024'), ['402.112', 'KWD']),
  ('partial repair guard 2', ('buy', '9849', 'USD', 'KWDUSD', '109.5417', '109.5455'), ['89.907', 'KWD']),
  ('control: bad side', ('hold', '5', 'EUR', 'EURUSD', '1.08', '1.09'), 'ERR:side'),
  ('control: buy base in base', ('buy', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.50', 'USD']),
  ('control: sell base in base', ('sell', '1000', 'EUR', 'EURUSD', '1.0831', '1.0835'), ['1083.10', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR'])],
 [('regression counter-exponent 1', ('sell', '24387', 'KWD', 'USDKWD', '72.1987', '72.2047'), ['337.78', 'USD']),
  ('regression counter-exponent 2', ('sell', '350.83', 'KWD', 'USDKWD', '107.9091', '107.9159'), ['3.26', 'USD']),
  ('partial repair guard 1', ('buy', '77666.89', 'JPY', 'USDJPY', '122.1001', '122.1039'), ['636.07', 'USD']),
  ('partial repair guard 2', ('buy', '51211.50', 'JPY', 'USDJPY', '106.2807', '106.2865'), ['481.82', 'USD']),
  ('control: spend quote', ('buy', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.29', 'EUR']),
  ('control: receive quote', ('sell', '100', 'USD', 'EURUSD', '1.0831', '1.0835'), ['92.33', 'EUR']),
  ('control: yen counter', ('buy', '10.01', 'USD', 'USDJPY', '151.20', '151.24'), ['1514', 'JPY']),
  ('control: locked quote', ('sell', '250', 'GBP', 'GBPUSD', '1.2650', '1.2650'), ['316.25', 'USD'])]]
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:
Dollars converted to yen are returned with cents, and yen converted to dollars are whole numbers.

solve(side, amount, ccy, pair, bid, ask): pair is six letters BASEQUOTE; side is the customer's action on the base currency ('buy' or 'sell'). The dealer sells base at ask and buys at bid. If amount is in base, the counter amount in quote is amount*rate; if in quote, the counter amount in base is amount/rate. Amounts the customer pays are rounded up (ceiling) and amounts the customer receives are rounded down (floor) at the counter currency exponent (JPY 0, KWD 3, else 2). Return [counter_amount, counter_ccy]; errors: 'ERR:side', 'ERR:crossed-quote' when bid > ask (bid == ask is valid), 'ERR:currency-not-in-pair'.

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 = {'DEM': '1.95583', 'FRF': '6.55957', 'ITL': '1936.27', 'ESP': '166.386', 'IEP': '0.787564', 'NLG': '2.20371', 'BEF': '40.3399', 'PTE': '200.482', 'ATS': '13.7603', 'FIM': '5.94573', 'EUR': '1'}
    zero = ('ITL', 'ESP', 'BEF', 'PTE')
    if frm not in rates or to not in rates: return 'ERR:currency'
    def q(v, c):
        return v.quantize(Decimal(1) if c in zero else Decimal('0.01'), rounding=ROUND_HALF_UP)
    x = Decimal(amount)
    if frm == to: return format(q(x, to), 'f')
    if frm == 'EUR':
        eur = x
    elif to == 'EUR':
        return format(q(x / Decimal(rates[frm]), 'EUR'), 'f')
    else:
        eur = (x * (Decimal(1) / Decimal(rates[frm])).quantize(Decimal('1e-6'))).quantize(Decimal('0.001'), rounding=ROUND_HALF_UP)
    return format(q(eur * Decimal(rates[to]), to), 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression inverse-rate 1', ('987654321', 'ITL', 'DEM'), '997631.50'),
  ('regression inverse-rate 2', ('123456789', 'ESP', 'FRF'), '4867136.96'),
  ('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38'),
  ('control: lira to euro', ('1000000', 'ITL', 'EUR'), '516.46'),
  ('control: euro to lira', ('10', 'EUR', 'ITL'), '19363'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101')],
 [('regression inverse-rate 1', ('99999999', 'PTE', 'NLG'), '1099205.90'),
  ('regression inverse-rate 2', ('123456', 'ESP', 'IEP'), '584.36'),
  ('partial repair guard 2', ('2701255', 'ESP', 'DEM'), '31752.65'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
  ('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency'),
  ('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1'),
  ('control: schilling to markka', ('987.65', 'ATS', 'FIM'), '426.75')],
 [('regression inverse-rate 1', ('2542824', 'FRF', 'ESP'), '64499703'),
  ('regression inverse-rate 2', ('204024', 'ESP', 'PTE'), '245833'),
  ('partial repair guard 1', ('2898066', 'FRF', 'ATS'), '6079401.18'),
  ('partial repair guard 2', ('1936907', 'ESP', 'FRF'), '76360.26'),
  ('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1'),
  ('control: schilling to markka', ('987.65', 'ATS', 'FIM'), '426.75'),
  ('control: franc to franc', ('12.345', 'BEF', 'FRF'), '2.01'),
  ('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38')],
 [('regression inverse-rate 1', ('2732281.35', 'DEM', 'FRF'), '9163675.15'),
  ('regression inverse-rate 2', ('1991579.94', 'NLG', 'DEM'), '1767560.97'),
  ('partial repair guard 1', ('3124364', 'BEF', 'FRF'), '508044.99'),
  ('partial repair guard 2', ('3838340.18', 'IEP', 'ATS'), '67063390.89'),
  ('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38'),
  ('control: lira to euro', ('1000000', 'ITL', 'EUR'), '516.46'),
  ('control: euro to lira', ('10', 'EUR', 'ITL'), '19363'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101')],
 [('regression inverse-rate 1', ('4401171', 'FIM', 'DEM'), '1447751.96'),
  ('regression inverse-rate 2', ('2414493', 'DEM', 'PTE'), '247497168'),
  ('partial repair guard 1', ('3438237', 'IEP', 'FRF'), '28636855.27'),
  ('partial repair guard 2', ('987654321', 'ITL', 'DEM'), '997631.50'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
  ('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency'),
  ('control: peseta to punt', ('123456', 'ESP', 'IEP'), '584.36'),
  ('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1')]]
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 = {'DEM': '1.95583', 'FRF': '6.55957', 'ITL': '1936.27', 'ESP': '166.386', 'IEP': '0.787564', 'NLG': '2.20371', 'BEF': '40.3399', 'PTE': '200.482', 'ATS': '13.7603', 'FIM': '5.94573', 'EUR': '1'}
    zero = ('ITL', 'ESP', 'BEF', 'PTE')
    if frm not in rates or to not in rates: return 'ERR:currency'
    def q(v, c):
        return v.quantize(Decimal(1) if c in zero else Decimal('0.01'), rounding=ROUND_HALF_UP)
    x = Decimal(amount)
    if frm == to: return format(q(x, to), 'f')
    if frm == 'EUR':
        eur = x
    elif to == 'EUR':
        return format(q(x / Decimal(rates[frm]), 'EUR'), 'f')
    else:
        eur = (x * (Decimal(1) / Decimal(rates[frm])).quantize(Decimal('1e-10'))).quantize(Decimal('0.001'), rounding=ROUND_HALF_UP)
    return format(q(eur * Decimal(rates[to]), to), 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression inverse-rate 1', ('987654321', 'ITL', 'DEM'), '997631.50'),
  ('regression inverse-rate 2', ('123456789', 'ESP', 'FRF'), '4867136.96'),
  ('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38'),
  ('control: lira to euro', ('1000000', 'ITL', 'EUR'), '516.46'),
  ('control: euro to lira', ('10', 'EUR', 'ITL'), '19363'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101')],
 [('regression inverse-rate 1', ('99999999', 'PTE', 'NLG'), '1099205.90'),
  ('regression inverse-rate 2', ('123456', 'ESP', 'IEP'), '584.36'),
  ('partial repair guard 2', ('2701255', 'ESP', 'DEM'), '31752.65'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
  ('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency'),
  ('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1'),
  ('control: schilling to markka', ('987.65', 'ATS', 'FIM'), '426.75')],
 [('regression inverse-rate 1', ('2542824', 'FRF', 'ESP'), '64499703'),
  ('regression inverse-rate 2', ('204024', 'ESP', 'PTE'), '245833'),
  ('partial repair guard 1', ('2898066', 'FRF', 'ATS'), '6079401.18'),
  ('partial repair guard 2', ('1936907', 'ESP', 'FRF'), '76360.26'),
  ('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1'),
  ('control: schilling to markka', ('987.65', 'ATS', 'FIM'), '426.75'),
  ('control: franc to franc', ('12.345', 'BEF', 'FRF'), '2.01'),
  ('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38')],
 [('regression inverse-rate 1', ('2732281.35', 'DEM', 'FRF'), '9163675.15'),
  ('regression inverse-rate 2', ('1991579.94', 'NLG', 'DEM'), '1767560.97'),
  ('partial repair guard 1', ('3124364', 'BEF', 'FRF'), '508044.99'),
  ('partial repair guard 2', ('3838340.18', 'IEP', 'ATS'), '67063390.89'),
  ('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38'),
  ('control: lira to euro', ('1000000', 'ITL', 'EUR'), '516.46'),
  ('control: euro to lira', ('10', 'EUR', 'ITL'), '19363'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101')],
 [('regression inverse-rate 1', ('4401171', 'FIM', 'DEM'), '1447751.96'),
  ('regression inverse-rate 2', ('2414493', 'DEM', 'PTE'), '247497168'),
  ('partial repair guard 1', ('3438237', 'IEP', 'FRF'), '28636855.27'),
  ('partial repair guard 2', ('987654321', 'ITL', 'DEM'), '997631.50'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
  ('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency'),
  ('control: peseta to punt', ('123456', 'ESP', 'IEP'), '584.36'),
  ('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1')]]
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:
Large lira amounts convert to a EUR intermediate that is off by a few thousandths.

solve(amount, frm, to): stipulated legacy-currency triangulation. Fixed rates are units per 1 EUR (DEM 1.95583, FRF 6.55957, ITL 1936.27, ESP 166.386, IEP 0.787564, NLG 2.20371, BEF 40.3399, PTE 200.482, ATS 13.7603, FIM 5.94573). Exponents: ITL, ESP, BEF, PTE 0; others and EUR 2. Legacy to legacy: divide by the source rate, round the EUR intermediate half-up to 3 decimals, multiply by the target rate, round half-up to the target exponent. Legacy to EUR: divide and round half-up to 2 decimals. EUR to legacy: multiply and round half-up to the target exponent. Same currency: round the amount half-up to its exponent. Inverse rates are never used. Unknown codes return 'ERR:currency'.

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 = {'DEM': '1.95583', 'FRF': '6.55957', 'ITL': '1936.27', 'ESP': '166.386', 'IEP': '0.787564', 'NLG': '2.20371', 'BEF': '40.3399', 'PTE': '200.482', 'ATS': '13.7603', 'FIM': '5.94573', 'EUR': '1'}
    zero = ('ITL', 'ESP', 'BEF', 'PTE')
    if frm not in rates or to not in rates: return 'ERR:currency'
    def q(v, c):
        return v.quantize(Decimal(1) if c in zero else Decimal('0.01'), rounding=ROUND_HALF_UP)
    x = Decimal(amount)
    if frm == to: return format(q(x, to), 'f')
    if frm == 'EUR':
        eur = x
    elif to == 'EUR':
        return format(q(x / Decimal(rates[frm]), 'EUR'), 'f')
    else:
        eur = (x / Decimal(rates[frm])).quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
    return format(q(eur * Decimal(rates[to]), to), 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression intermediate-precision 1', ('100', 'DEM', 'FRF'), '335.38'),
  ('regression intermediate-precision 2', ('0.01', 'NLG', 'PTE'), '1'),
  ('partial repair guard 2', ('987.65', 'ATS', 'FIM'), '426.75'),
  ('control: lira to euro', ('1000000', 'ITL', 'EUR'), '516.46'),
  ('control: euro to lira', ('10', 'EUR', 'ITL'), '19363'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
  ('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency')],
 [('regression intermediate-precision 1', ('987.65', 'ATS', 'FIM'), '426.75'),
  ('regression intermediate-precision 2', ('12.345', 'BEF', 'FRF'), '2.01'),
  ('partial repair guard 1', ('874590.00', 'DEM', 'ITL'), '865843339'),
  ('partial repair guard 2', ('2943493', 'NLG', 'ESP'), '222241596'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
  ('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency'),
  ('control: peseta to punt', ('123456', 'ESP', 'IEP'), '584.36'),
  ('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1')],
 [('regression intermediate-precision 1', ('2732281.35', 'DEM', 'FRF'), '9163675.15'),
  ('regression intermediate-precision 2', ('1991579.94', 'NLG', 'DEM'), '1767560.97'),
  ('partial repair guard 1', ('3066738', 'BEF', 'ITL'), '147199987'),
  ('partial repair guard 2', ('404894', 'FIM', 'ITL'), '131856660'),
  ('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1'),
  ('control: schilling to markka', ('987.65', 'ATS', 'FIM'), '426.75'),
  ('control: franc to franc', ('12.345', 'BEF', 'FRF'), '2.01'),
  ('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38')],
 [('regression intermediate-precision 1', ('4401171', 'FIM', 'DEM'), '1447751.96'),
  ('regression intermediate-precision 2', ('4407915', 'NLG', 'FRF'), '13120613.42'),
  ('partial repair guard 1', ('1491996', 'DEM', 'ATS'), '10496982.14'),
  ('partial repair guard 2', ('2701255', 'ESP', 'DEM'), '31752.65'),
  ('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38'),
  ('control: lira to euro', ('1000000', 'ITL', 'EUR'), '516.46'),
  ('control: euro to lira', ('10', 'EUR', 'ITL'), '19363'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101')],
 [('regression intermediate-precision 1', ('321003', 'BEF', 'DEM'), '15563.43'),
  ('regression intermediate-precision 2', ('1369593', 'ATS', 'NLG'), '219340.12'),
  ('partial repair guard 1', ('2258512', 'PTE', 'ATS'), '155015.42'),
  ('partial repair guard 2', ('4761183', 'FRF', 'FIM'), '4315634.80'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
  ('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency'),
  ('control: peseta to punt', ('123456', 'ESP', 'IEP'), '584.36'),
  ('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1')]]
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 = {'DEM': '1.95583', 'FRF': '6.55957', 'ITL': '1936.27', 'ESP': '166.386', 'IEP': '0.787564', 'NLG': '2.20371', 'BEF': '40.3399', 'PTE': '200.482', 'ATS': '13.7603', 'FIM': '5.94573', 'EUR': '1'}
    zero = ('ITL', 'ESP', 'BEF', 'PTE')
    if frm not in rates or to not in rates: return 'ERR:currency'
    def q(v, c):
        return v.quantize(Decimal(1) if c in zero else Decimal('0.01'), rounding=ROUND_HALF_UP)
    x = Decimal(amount)
    if frm == to: return format(q(x, to), 'f')
    if frm == 'EUR':
        eur = x
    elif to == 'EUR':
        return format(q(x / Decimal(rates[frm]), 'EUR'), 'f')
    else:
        eur = (x / Decimal(rates[frm])).quantize(Decimal('1e-20'), rounding=ROUND_HALF_UP)
    return format(q(eur * Decimal(rates[to]), to), 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression intermediate-precision 1', ('100', 'DEM', 'FRF'), '335.38'),
  ('regression intermediate-precision 2', ('0.01', 'NLG', 'PTE'), '1'),
  ('partial repair guard 2', ('987.65', 'ATS', 'FIM'), '426.75'),
  ('control: lira to euro', ('1000000', 'ITL', 'EUR'), '516.46'),
  ('control: euro to lira', ('10', 'EUR', 'ITL'), '19363'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
  ('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency')],
 [('regression intermediate-precision 1', ('987.65', 'ATS', 'FIM'), '426.75'),
  ('regression intermediate-precision 2', ('12.345', 'BEF', 'FRF'), '2.01'),
  ('partial repair guard 1', ('874590.00', 'DEM', 'ITL'), '865843339'),
  ('partial repair guard 2', ('2943493', 'NLG', 'ESP'), '222241596'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
  ('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency'),
  ('control: peseta to punt', ('123456', 'ESP', 'IEP'), '584.36'),
  ('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1')],
 [('regression intermediate-precision 1', ('2732281.35', 'DEM', 'FRF'), '9163675.15'),
  ('regression intermediate-precision 2', ('1991579.94', 'NLG', 'DEM'), '1767560.97'),
  ('partial repair guard 1', ('3066738', 'BEF', 'ITL'), '147199987'),
  ('partial repair guard 2', ('404894', 'FIM', 'ITL'), '131856660'),
  ('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1'),
  ('control: schilling to markka', ('987.65', 'ATS', 'FIM'), '426.75'),
  ('control: franc to franc', ('12.345', 'BEF', 'FRF'), '2.01'),
  ('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38')],
 [('regression intermediate-precision 1', ('4401171', 'FIM', 'DEM'), '1447751.96'),
  ('regression intermediate-precision 2', ('4407915', 'NLG', 'FRF'), '13120613.42'),
  ('partial repair guard 1', ('1491996', 'DEM', 'ATS'), '10496982.14'),
  ('partial repair guard 2', ('2701255', 'ESP', 'DEM'), '31752.65'),
  ('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38'),
  ('control: lira to euro', ('1000000', 'ITL', 'EUR'), '516.46'),
  ('control: euro to lira', ('10', 'EUR', 'ITL'), '19363'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101')],
 [('regression intermediate-precision 1', ('321003', 'BEF', 'DEM'), '15563.43'),
  ('regression intermediate-precision 2', ('1369593', 'ATS', 'NLG'), '219340.12'),
  ('partial repair guard 1', ('2258512', 'PTE', 'ATS'), '155015.42'),
  ('partial repair guard 2', ('4761183', 'FRF', 'FIM'), '4315634.80'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
  ('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency'),
  ('control: peseta to punt', ('123456', 'ESP', 'IEP'), '584.36'),
  ('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1')]]
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:
Legacy-to-legacy amounts differ from the reference triangulation by a few minor units.

solve(amount, frm, to): stipulated legacy-currency triangulation. Fixed rates are units per 1 EUR (DEM 1.95583, FRF 6.55957, ITL 1936.27, ESP 166.386, IEP 0.787564, NLG 2.20371, BEF 40.3399, PTE 200.482, ATS 13.7603, FIM 5.94573). Exponents: ITL, ESP, BEF, PTE 0; others and EUR 2. Legacy to legacy: divide by the source rate, round the EUR intermediate half-up to 3 decimals, multiply by the target rate, round half-up to the target exponent. Legacy to EUR: divide and round half-up to 2 decimals. EUR to legacy: multiply and round half-up to the target exponent. Same currency: round the amount half-up to its exponent. Inverse rates are never used. Unknown codes return 'ERR:currency'.

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 = {'DEM': '1.95583', 'FRF': '6.55957', 'ITL': '1936.27', 'ESP': '166.386', 'IEP': '0.787564', 'NLG': '2.20371', 'BEF': '40.3399', 'PTE': '200.482', 'ATS': '13.7603', 'FIM': '5.94573', 'EUR': '1'}
    zero = ('ITL', 'ESP', 'BEF', 'PTE')
    if frm not in rates or to not in rates: return 'ERR:currency'
    def q(v, c):
        return v.quantize(Decimal(1) if c in zero else Decimal('0.01'), rounding=ROUND_HALF_UP)
    x = Decimal(amount)
    if frm == to: return format(q(x, to), 'f')
    if frm == 'EUR':
        eur = x
    elif to == 'EUR':
        return format(q(x / Decimal(rates[frm]), 'EUR'), 'f')
    else:
        return format(q(x * (Decimal(rates[to]) / Decimal(rates[frm])).quantize(Decimal('1e-6')), to), 'f')
    return format(q(eur * Decimal(rates[to]), to), 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression direct-cross-rate 1', ('100', 'DEM', 'FRF'), '335.38'),
  ('regression direct-cross-rate 2', ('123456', 'ESP', 'IEP'), '584.36'),
  ('partial repair guard 2', ('987.65', 'ATS', 'FIM'), '426.75'),
  ('control: lira to euro', ('1000000', 'ITL', 'EUR'), '516.46'),
  ('control: euro to lira', ('10', 'EUR', 'ITL'), '19363'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
  ('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency')],
 [('regression direct-cross-rate 1', ('987.65', 'ATS', 'FIM'), '426.75'),
  ('regression direct-cross-rate 2', ('2542824', 'FRF', 'ESP'), '64499703'),
  ('partial repair guard 1', ('874590.00', 'DEM', 'ITL'), '865843339'),
  ('partial repair guard 2', ('2943493', 'NLG', 'ESP'), '222241596'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
  ('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency'),
  ('control: peseta to punt', ('123456', 'ESP', 'IEP'), '584.36'),
  ('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1')],
 [('regression direct-cross-rate 1', ('2732281.35', 'DEM', 'FRF'), '9163675.15'),
  ('regression direct-cross-rate 2', ('1991579.94', 'NLG', 'DEM'), '1767560.97'),
  ('partial repair guard 1', ('3066738', 'BEF', 'ITL'), '147199987'),
  ('partial repair guard 2', ('404894', 'FIM', 'ITL'), '131856660'),
  ('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1'),
  ('control: schilling to markka', ('987.65', 'ATS', 'FIM'), '426.75'),
  ('control: franc to franc', ('12.345', 'BEF', 'FRF'), '2.01'),
  ('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38')],
 [('regression direct-cross-rate 1', ('4401171', 'FIM', 'DEM'), '1447751.96'),
  ('regression direct-cross-rate 2', ('4407915', 'NLG', 'FRF'), '13120613.42'),
  ('partial repair guard 1', ('1491996', 'DEM', 'ATS'), '10496982.14'),
  ('partial repair guard 2', ('2701255', 'ESP', 'DEM'), '31752.65'),
  ('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38'),
  ('control: lira to euro', ('1000000', 'ITL', 'EUR'), '516.46'),
  ('control: euro to lira', ('10', 'EUR', 'ITL'), '19363'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101')],
 [('regression direct-cross-rate 1', ('321003', 'BEF', 'DEM'), '15563.43'),
  ('regression direct-cross-rate 2', ('1369593', 'ATS', 'NLG'), '219340.12'),
  ('partial repair guard 1', ('2258512', 'PTE', 'ATS'), '155015.42'),
  ('partial repair guard 2', ('4761183', 'FRF', 'FIM'), '4315634.80'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
  ('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency'),
  ('control: peseta to punt', ('123456', 'ESP', 'IEP'), '584.36'),
  ('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1')]]
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 = {'DEM': '1.95583', 'FRF': '6.55957', 'ITL': '1936.27', 'ESP': '166.386', 'IEP': '0.787564', 'NLG': '2.20371', 'BEF': '40.3399', 'PTE': '200.482', 'ATS': '13.7603', 'FIM': '5.94573', 'EUR': '1'}
    zero = ('ITL', 'ESP', 'BEF', 'PTE')
    if frm not in rates or to not in rates: return 'ERR:currency'
    def q(v, c):
        return v.quantize(Decimal(1) if c in zero else Decimal('0.01'), rounding=ROUND_HALF_UP)
    x = Decimal(amount)
    if frm == to: return format(q(x, to), 'f')
    if frm == 'EUR':
        eur = x
    elif to == 'EUR':
        return format(q(x / Decimal(rates[frm]), 'EUR'), 'f')
    else:
        return format(q(x * Decimal(rates[to]) / Decimal(rates[frm]), to), 'f')
    return format(q(eur * Decimal(rates[to]), to), 'f')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression direct-cross-rate 1', ('100', 'DEM', 'FRF'), '335.38'),
  ('regression direct-cross-rate 2', ('123456', 'ESP', 'IEP'), '584.36'),
  ('partial repair guard 2', ('987.65', 'ATS', 'FIM'), '426.75'),
  ('control: lira to euro', ('1000000', 'ITL', 'EUR'), '516.46'),
  ('control: euro to lira', ('10', 'EUR', 'ITL'), '19363'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
  ('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency')],
 [('regression direct-cross-rate 1', ('987.65', 'ATS', 'FIM'), '426.75'),
  ('regression direct-cross-rate 2', ('2542824', 'FRF', 'ESP'), '64499703'),
  ('partial repair guard 1', ('874590.00', 'DEM', 'ITL'), '865843339'),
  ('partial repair guard 2', ('2943493', 'NLG', 'ESP'), '222241596'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
  ('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency'),
  ('control: peseta to punt', ('123456', 'ESP', 'IEP'), '584.36'),
  ('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1')],
 [('regression direct-cross-rate 1', ('2732281.35', 'DEM', 'FRF'), '9163675.15'),
  ('regression direct-cross-rate 2', ('1991579.94', 'NLG', 'DEM'), '1767560.97'),
  ('partial repair guard 1', ('3066738', 'BEF', 'ITL'), '147199987'),
  ('partial repair guard 2', ('404894', 'FIM', 'ITL'), '131856660'),
  ('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1'),
  ('control: schilling to markka', ('987.65', 'ATS', 'FIM'), '426.75'),
  ('control: franc to franc', ('12.345', 'BEF', 'FRF'), '2.01'),
  ('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38')],
 [('regression direct-cross-rate 1', ('4401171', 'FIM', 'DEM'), '1447751.96'),
  ('regression direct-cross-rate 2', ('4407915', 'NLG', 'FRF'), '13120613.42'),
  ('partial repair guard 1', ('1491996', 'DEM', 'ATS'), '10496982.14'),
  ('partial repair guard 2', ('2701255', 'ESP', 'DEM'), '31752.65'),
  ('control: mark to franc', ('100', 'DEM', 'FRF'), '335.38'),
  ('control: lira to euro', ('1000000', 'ITL', 'EUR'), '516.46'),
  ('control: euro to lira', ('10', 'EUR', 'ITL'), '19363'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101')],
 [('regression direct-cross-rate 1', ('321003', 'BEF', 'DEM'), '15563.43'),
  ('regression direct-cross-rate 2', ('1369593', 'ATS', 'NLG'), '219340.12'),
  ('partial repair guard 1', ('2258512', 'PTE', 'ATS'), '155015.42'),
  ('partial repair guard 2', ('4761183', 'FRF', 'FIM'), '4315634.80'),
  ('control: same currency rounding', ('100.5', 'ITL', 'ITL'), '101'),
  ('control: unknown', ('5', 'XEU', 'DEM'), 'ERR:currency'),
  ('control: peseta to punt', ('123456', 'ESP', 'IEP'), '584.36'),
  ('control: guilder to escudo', ('0.01', 'NLG', 'PTE'), '1')]]
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:
Mark to franc conversions disagree with the triangulated reference amount.

solve(amount, frm, to): stipulated legacy-currency triangulation. Fixed rates are units per 1 EUR (DEM 1.95583, FRF 6.55957, ITL 1936.27, ESP 166.386, IEP 0.787564, NLG 2.20371, BEF 40.3399, PTE 200.482, ATS 13.7603, FIM 5.94573). Exponents: ITL, ESP, BEF, PTE 0; others and EUR 2. Legacy to legacy: divide by the source rate, round the EUR intermediate half-up to 3 decimals, multiply by the target rate, round half-up to the target exponent. Legacy to EUR: divide and round half-up to 2 decimals. EUR to legacy: multiply and round half-up to the target exponent. Same currency: round the amount half-up to its exponent. Inverse rates are never used. Unknown codes return 'ERR:currency'.

split: open-access