code wiki / (root) / nx_allergen_test.nx

nx_allergen_test.nx source

↩ module page · 63 lines · 2888 B

1// nx_allergen_test.nx -- smoke for nx_allergen. Proves big-9 rollup with 2// HIDDEN-allergen detection, personalized safety, cross-contact risk, and 3// substitution that never reintroduces an avoided allergen. 4// Exit code = failed assertion number; 0 = all pass. 5 6import "nx_syscalls.nx" 7import "nx_allergen.nx" 8 9func main() -> i64 { 10 // --- hidden allergen: soy sauce carries BOTH soy AND wheat --- 11 if nx_ingredient_allergens(ING_SOY_SAUCE) != (AL_SOY | AL_WHEAT) { return 1 } 12 13 // --- recipe rollup (tofu + soy sauce + rice) --- 14 var m: i64 = 0 15 m = al_mask_add(m, ING_TOFU) 16 m = al_mask_add(m, ING_SOY_SAUCE) 17 m = al_mask_add(m, ING_RICE) 18 if al_contains(m, AL_SOY) != 1 { return 2 } 19 if al_contains(m, AL_WHEAT) != 1 { return 3 } // hidden wheat caught by rollup 20 if al_contains(m, AL_PEANUT) != 0 { return 4 } 21 22 // --- personalized safety --- 23 if al_safe_for(m, AL_PEANUT) != 1 { return 5 } // peanut-avoider: safe 24 if al_safe_for(m, AL_SOY) != 0 { return 6 } // soy-avoider: NOT safe 25 if al_safe_for(m, AL_WHEAT) != 0 { return 7 } // wheat-avoider: NOT safe (hidden) 26 27 // --- allergen count --- 28 var d: i64 = 0 29 d = al_mask_add(d, ING_MILK) 30 d = al_mask_add(d, ING_EGG) 31 d = al_mask_add(d, ING_WHEAT_FLOUR) 32 if al_count(d) != 3 { return 8 } 33 34 // --- cross-contact "may contain" --- 35 if al_cross_contact_risk(AL_PEANUT, AL_PEANUT) != 1 { return 9 } // peanut facility, peanut-avoider 36 if al_cross_contact_risk(AL_PEANUT, AL_MILK) != 0 { return 10 } 37 38 // --- safe substitution --- 39 // milk -> oat milk, safe for a milk-avoider. 40 let s1: i64 = al_substitute(ING_MILK, AL_MILK) 41 if s1 != ING_OAT_MILK { return 11 } 42 if al_safe_for(nx_ingredient_allergens(s1), AL_MILK) != 1 { return 12 } 43 // soy sauce -> coconut aminos, safe for a soy-avoider. 44 if al_substitute(ING_SOY_SAUCE, AL_SOY) != ING_COCONUT_AMINOS { return 13 } 45 // wheat flour -> rice flour, safe even when avoiding wheat AND soy. 46 let s3: i64 = al_substitute(ING_WHEAT_FLOUR, AL_WHEAT | AL_SOY) 47 if s3 != ING_RICE_FLOUR { return 14 } 48 if al_safe_for(nx_ingredient_allergens(s3), AL_WHEAT | AL_SOY) != 1 { return 15 } 49 // already-safe ingredient is returned unchanged. 50 if al_substitute(ING_RICE, AL_MILK) != ING_RICE { return 16 } 51 52 // --- LIAR-KILL: a substitute NEVER reintroduces an avoided allergen. 53 // Even when avoiding milk AND the sub's category, the returned sub 54 // is allergen-clean (oat milk carries none of the big 9). --- 55 let s4: i64 = al_substitute(ING_MILK, AL_MILK | AL_SOY) 56 if s4 < 0 { return 17 } 57 if al_safe_for(nx_ingredient_allergens(s4), AL_MILK | AL_SOY) != 1 { return 18 } 58 59 // --- negative control: a plain ingredient has no big-9 allergen --- 60 if nx_ingredient_allergens(ING_RICE) != 0 { return 19 } 61 62 return 0 63}