code wiki / (root) / nx_emulsion_test.nx

nx_emulsion_test.nx source

↩ module page · 35 lines · 1564 B

1// nx_emulsion_test.nx -- smoke for nx_emulsion. Proves HLB lookup, blend 2// HLB, emulsion-type prediction, required-HLB matching, and Stokes creaming 3// stability. Exit code = failed assertion number; 0 = all pass. 4 5import "nx_syscalls.nx" 6import "nx_emulsion.nx" 7 8func main() -> i64 { 9 // --- HLB lookups --- 10 if em_emulsifier_hlb(EM_TWEEN80) != 150 { return 1 } 11 if em_emulsifier_hlb(EM_SPAN80) != 43 { return 2 } 12 if em_required_hlb(EM_OIL_OLIVE) != 70 { return 3 } 13 14 // --- blend HLB (weighted mean) --- 15 if em_blend_hlb(43, 50, 150, 50) != 96 { return 4 } // 50/50 span+tween 16 if em_blend_hlb(43, 75, 150, 25) != 69 { return 5 } // tuned toward olive's 7.0 17 18 // --- emulsion type (Griffin split at HLB 7.0) --- 19 if em_emulsion_type(150) != EM_OW { return 6 } 20 if em_emulsion_type(43) != EM_WO { return 7 } 21 if em_emulsion_type(96) != EM_OW { return 8 } 22 23 // --- required-HLB matching --- 24 if em_match(70, 69, 10) != 1 { return 9 } // tuned blend matches olive oil 25 if em_match(70, 150, 10) != 0 { return 10 } // tween alone overshoots (would not match) 26 27 // --- Stokes creaming stability (smaller droplet + thicker phase = stabler) --- 28 if em_creaming_index(100, 2, 1000) != 400 { return 11 } 29 if em_creaming_index(100, 10, 1000) != 10000 { return 12 } 30 if em_more_stable(400, 10000) != 1 { return 13 } // 2 um beats 10 um 31 if em_more_stable(2000, 10000) != 1 { return 14 } // thicker continuous phase stabilizes 32 if em_more_stable(10000, 400) != 0 { return 15 } 33 34 return 0 35}