"""Save as reproduce-cases.py beside worked-cases.json; Python 3 standard library only. These fictional calculations do not establish individual benefits or wage compliance. """ import json from decimal import Decimal as D from pathlib import Path data = json.loads(Path(__file__).with_name('worked-cases.json').read_text(encoding='utf-8'), parse_float=D) checks = [] c = data['capped_match'] for row in c['rows']: employee = c['eligible_pay'] * row['employee_fraction'] match = min(employee, c['eligible_pay'] * c['employee_pay_cap_fraction']) * c['employer_fraction'] assert employee == row['employee_dollars'] and match == row['match'] checks.append(f"Employee {employee}; capped employer match {match}") u = data['uncapped_below_limit_comparison'] assert u['eligible_employee_contribution'] * u['employer_fraction'] == u['match'] assert u['match'] - c['rows'][-1]['match'] == u['difference_vs_capped'] checks.append('Selected uncapped-formula illustration: 3200; difference 800') t = data['payroll_timing'] for pattern in t['patterns']: contributions = [t['monthly_pay'] * p for p in pattern['employee_monthly_fractions']] assert len(contributions) == t['months'] assert sum(contributions) == pattern['total_employee'] match = sum(min(v, t['monthly_pay'] * t['employee_pay_cap_fraction']) * t['employer_fraction'] for v in contributions) assert match == pattern['payroll_match'] annual = min(sum(contributions), t['monthly_pay'] * t['months'] * t['employee_pay_cap_fraction']) * t['employer_fraction'] assert annual == t['annual_formula_match'] checks.append(f'Employee {sum(contributions)}; payroll match {match}; annual formula {annual}') assert t['annual_formula_match'] - t['patterns'][1]['payroll_match'] == t['conditional_reconciliation'] v = data['vesting'] for row in v['rows']: a, b = [v['unchanged_employer_source_balance'] * row[k] for k in ['year2','year3']] assert (a, b, b-a) == (row['vested2'], row['vested3'], row['increase']) checks.append(f"{row['schedule']}: vested {a} to {b}; increase {b-a}") o = data['overtime']; weeks = o['daily_hours_by_week'] hours = sum(sum(w) for w in weeks) weekly_ot = sum(max(sum(w)-40,0) for w in weeks) daily_ot = sum(max(h-8,0) for w in weeks for h in w) period_ot = max(hours-80,0) assert period_ot == 0, 'This reproduction intentionally covers only the below-80-hour exercise.' straight = hours * o['constant_regular_rate'] premium = daily_ot * D('0.5') * o['constant_regular_rate'] assert (straight,weekly_ot,daily_ot,period_ot,premium) == (o['straight_time'],o['weekly_overtime_hours'],o['daily_overtime_hours'],o['eight_and_eighty_period_overtime_hours'],o['additional_daily_premium']) assert straight + weekly_ot * D('0.5') * o['constant_regular_rate'] == o['standard_gross'] assert straight + premium == o['eight_and_eighty_gross'] checks.append(f'72-hour exercise: standard {straight}; 8-and-80 {straight+premium}; difference {premium}') print(json.dumps({'version':data['version'],'passed':len(checks),'checks':checks},indent=2))