code wiki / (root) / nx_water_quality_test.nx

nx_water_quality_test.nx source

↩ module page · 60 lines · 2343 B

1// nx_water_quality_test.nx -- smoke for nx_water_quality. Proves TDS taste 2// bands + composite taste score, health mineral thresholds, and the never- 3// poison safety gate (lead/arsenic/nitrate/PFAS/bacteria/THM). 4// Exit code = failed assertion number; 0 = all pass. 5 6import "nx_syscalls.nx" 7import "nx_water_quality.nx" 8 9func main() -> i64 { 10 // --- TDS palatability bands (WHO) --- 11 if wq_tds_taste_class(250) != WQ_EXCELLENT { return 1 } 12 if wq_tds_taste_class(30) != WQ_INSIPID { return 2 } 13 if wq_tds_taste_class(1000) != WQ_POOR { return 3 } 14 if wq_tds_taste_class(1500) != WQ_UNACCEPTABLE { return 4 } 15 16 // --- composite taste score: an ideally-mineralized water scores 100 --- 17 let good: *NxWaterSample = nx_water_sample_new() 18 good.tds = 250 19 good.ca = 50 20 good.mg = 25 21 good.ph_x10 = 75 22 if wq_taste_score(good) != 100 { return 5 } 23 24 // --- near-distilled water tastes flat --- 25 let flat: *NxWaterSample = nx_water_sample_new() 26 flat.tds = 2 27 flat.ph_x10 = 60 28 if wq_taste_score(flat) != 15 { return 6 } 29 30 // --- health: needs the WHO desirable minerals --- 31 if wq_is_healthful(good) != 1 { return 7 } 32 let poor_min: *NxWaterSample = nx_water_sample_new() 33 poor_min.tds = 250 34 poor_min.ca = 5 35 poor_min.mg = 5 36 poor_min.ph_x10 = 75 37 if wq_is_potable(poor_min) != 1 { return 8 } // safe to drink 38 if wq_is_healthful(poor_min) != 0 { return 9 } // but not mineral-healthful 39 40 // --- NEVER-POISON safety gate --- 41 if wq_safety_admit(good) != WQ_SAFE { return 10 } 42 let lead: *NxWaterSample = nx_water_sample_new() 43 lead.tds = 250 44 lead.lead_ppb = 20 45 if wq_safety_admit(lead) != WQ_REFUSED_LEAD { return 11 } // > 15 ppb 46 let pfas: *NxWaterSample = nx_water_sample_new() 47 pfas.pfas_ppt = 5 48 if wq_safety_admit(pfas) != WQ_REFUSED_PFAS { return 12 } // > 4 ppt (EPA 2024) 49 let bug: *NxWaterSample = nx_water_sample_new() 50 bug.bacteria = 1 51 if wq_safety_admit(bug) != WQ_REFUSED_BACTERIA { return 13 } 52 let ars: *NxWaterSample = nx_water_sample_new() 53 ars.arsenic_ppb = 15 54 if wq_safety_admit(ars) != WQ_REFUSED_ARSENIC { return 14 } 55 let nit: *NxWaterSample = nx_water_sample_new() 56 nit.nitrate_mgl = 12 57 if wq_safety_admit(nit) != WQ_REFUSED_NITRATE { return 15 } 58 59 return 0 60}