"""Invented calculation migration acceptance cases; Python 3 standard library."""
from decimal import Decimal as D, ROUND_HALF_UP, ROUND_HALF_EVEN
import json

def net(amount, discount, blank_zero=False, percent_points=False, rounding=ROUND_HALF_UP):
    if discount is None:
        if not blank_zero:
            return None
        discount = '0'
    rate = D(discount) / (100 if percent_points else 1)
    return str((D(amount) * (1-rate)).quantize(D('0.01'), rounding=rounding))

cases = [
    ('ordinary', net('100','0.10'), net('100','0.10'), '90.00'),
    ('explicit_zero', net('100','0'), net('100','0'), '100.00'),
    ('blank_discount', net('100',None), net('100',None,blank_zero=True), None),
    ('percent_scale', net('100','0.10'), net('100','0.10',percent_points=True), '90.00'),
    ('rounding_tie', net('1.005','0'), net('1.005','0',rounding=ROUND_HALF_EVEN), '1.01'),
    ('stale_snapshot_after_change', net('200','0.10'), net('100','0.10'), '180.00'),
    ('full_discount', net('100','1'), net('100','1'), '0.00'),
    ('negative_adjustment', net('-100','0.10'), net('-100','0.10'), '-90.00'),
]
rows=[]
for name,expected,actual,oracle in cases:
    assert expected == oracle, name
    rows.append(dict(case=name,expected=expected,actual=actual,match=expected==actual))
assert sum(r['match'] for r in rows)==4
result=dict(cases=rows,passed=4,mismatched=4)
print(json.dumps(result,indent=2))
