nx_chem_solution_test.nx source
↩ module page · 33 lines · 1419 B
1// nx_chem_solution_test.nx -- smoke for nx_chem_solution. Proves
2// Henderson-Hasselbalch buffers, pH/pOH, molarity, dilution, titratable
3// acidity, and the high-acid tie to preservation.
4// Exit code = failed assertion number; 0 = all pass.
5
6import "nx_syscalls.nx"
7import "nx_chem_solution.nx"
8
9func main() -> i64 {
10 // --- Henderson-Hasselbalch (acetate buffer, pKa 4.76) ---
11 if cs_buffer_ph_at_pka(4760) != 4760 { return 1 } // 1:1 -> pH = pKa
12 if cs_buffer_ph_milli(4760, 1) != 5760 { return 2 } // 10:1 base:acid
13 if cs_buffer_ph_milli(4760, 0 - 1) != 3760 { return 3 } // 1:10 base:acid
14
15 // --- pH / pOH ---
16 if cs_poh_milli(4600) != 9400 { return 4 }
17
18 // --- tie to preservation: high-acid (botulinum cannot grow) ---
19 if cs_is_high_acid(3500) != 1 { return 5 } // sauerkraut
20 if cs_is_high_acid(5600) != 0 { return 6 } // green beans (low-acid)
21
22 // --- molarity: 5.85 g NaCl (MW 58.5) in 1 L = 100 mM (0.1 M) ---
23 if cs_molarity_mm(5850, 585, 1000) != 100 { return 7 }
24
25 // --- dilution C1V1 = C2V2 ---
26 if cs_dilute_final_conc(100, 10, 100) != 10 { return 8 } // 100 mM x10 mL -> 100 mL
27 if cs_dilute_volume_needed(100, 10, 100) != 10 { return 9 } // stock mL for 10 mM x 100 mL
28
29 // --- titratable acidity: 10 mL of 0.1 N NaOH, citric meq wt 64.04 ---
30 if cs_titratable_acid_mg(10, 100, 6404) != 64 { return 10 }
31
32 return 0
33}