from pathlib import Path import csv, math p = Path(__file__).resolve().parent def read(n): with (p/n).open(encoding="utf-8") as f: return list(csv.DictReader(f)) r=read("bls-powered-equipment-fatalities.csv"); c=read("bls-two-year-comparison.csv"); z=read("bls-population-comparison.csv") assert len(r)==24 and len(c)==6 and len(z)==9 for v in c: for name, prefix in [("US all ownership","us"),("Private manufacturing","manufacturing")]: counts=[] for year in (2023,2024): x=next(a for a in r if a["calendar_year"]==str(year) and a["population"]==name and a["oiics_v3_event_code"]==v["event_code"]) assert x["fatalities"]==v[f"{prefix}_{year}"] counts.append(int(x["fatalities"]) if x["fatalities"] else None) assert v[f"{prefix}_2023_24"]==("" if None in counts else str(sum(counts))) m=v["manufacturing_2023_24"]; n=v["us_2023_24"] assert (float(v["manufacturing_share_of_us_pct"]) if m else None)==(round(int(m)/int(n)*100,2) if m else None) for row in z: assert abs(float(row["maintenance_share_pct"])-100*int(row["maintenance_event_deaths_652"])/int(row["running_equipment_deaths_65"]))<0.0001 assert round(38/92*100,1)==41.3 assert round(107/439*100,1)==24.4 assert round(92/439*100,1)==21.0 assert round(38/107*100,1)==35.5 assert round(54/332*100,1)==16.3 assert round((38/107)/(54/332),2)==2.18 assert round(403/592*100,1)==68.1 assert sum([348,55,31,7,151])==592 assert sum([325,165,67,30,21,10,3,3])==624 assert round(490/624*100,1)==78.5 assert round(142/185*100,1)==76.8 and round(31/185*100,1)==16.8 assert 28400+31900==60300 and 24/16==1.5 print("PASS: 24 source cells; 6 combined rows; 9 population comparisons; headline and historical arithmetic.")