code wiki / (root) / nx_food_chem_react_test.nx

nx_food_chem_react_test.nx source

↩ module page · 63 lines · 2853 B

1// nx_food_chem_react_test.nx -- smoke for nx_food_chem_react. Proves the 2// three browning reactions are correctly distinguished from conditions, 3// with real thresholds, plus enzymatic-browning prevention. 4// Exit code = failed assertion number; 0 = all pass. 5 6import "nx_syscalls.nx" 7import "nx_food_chem_react.nx" 8 9func main() -> i64 { 10 // --- Maillard: needs protein + reducing sugar + dry heat >= 140 C --- 11 if fcr_maillard(1, 1, 180) != 1 { return 1 } // seared steak 12 if fcr_maillard(1, 1, 100) != 0 { return 2 } // boiling: no browning 13 if fcr_maillard(0, 1, 180) != 0 { return 3 } // no protein: no Maillard 14 // rate rises with temp; alkaline pH doubles it (pretzel lye dip) 15 if fcr_maillard_rate(180, 6000) != 40 { return 4 } 16 if fcr_maillard_rate(180, 8000) != 80 { return 5 } 17 if fcr_maillard_rate(120, 7000) != 0 { return 6 } 18 19 // --- caramelization: per-sugar onset, no protein needed --- 20 if fcr_caramelization_temp(FCR_SUGAR_FRUCTOSE) != 110 { return 7 } 21 if fcr_caramelizes(FCR_SUGAR_SUCROSE, 170) != 1 { return 8 } 22 if fcr_caramelizes(FCR_SUGAR_SUCROSE, 150) != 0 { return 9 } 23 if fcr_caramelizes(FCR_SUGAR_FRUCTOSE, 120) != 1 { return 10 } 24 25 // --- enzymatic browning + its prevention (cut apple) --- 26 if fcr_enzymatic_browning(1, 1, 3900, 20, 0) != 1 { return 11 } // cut apple browns 27 if fcr_enzymatic_browning(1, 1, 2200, 20, 0) != 0 { return 12 } // lemon (acid) stops it 28 if fcr_enzymatic_browning(1, 1, 3900, 75, 0) != 0 { return 13 } // blanched (heat) stops it 29 if fcr_enzymatic_browning(1, 1, 3900, 20, 1) != 0 { return 14 } // vitamin C stops it 30 if fcr_enzymatic_browning(1, 0, 3900, 20, 0) != 0 { return 15 } // submerged (no O2) stops it 31 32 // --- the CLASSIFIER: right reaction from the scenario --- 33 // Seared steak -> Maillard. 34 let steak: *NxCookScenario = nx_cook_scenario_new() 35 steak.has_protein = 1 36 steak.has_reducing_sugar = 1 37 steak.has_sugar = 1 38 steak.temp_c = 200 39 if fcr_predict_browning(steak) != FCR_MAILLARD { return 16 } 40 41 // Molten sugar (sucrose, no protein) -> caramelization. 42 let caramel: *NxCookScenario = nx_cook_scenario_new() 43 caramel.has_sugar = 1 44 caramel.sugar_id = FCR_SUGAR_SUCROSE 45 caramel.temp_c = 175 46 if fcr_predict_browning(caramel) != FCR_CARAMELIZATION { return 17 } 47 48 // Cut apple on the counter -> enzymatic browning. 49 let apple: *NxCookScenario = nx_cook_scenario_new() 50 apple.has_sugar = 1 51 apple.sugar_id = FCR_SUGAR_FRUCTOSE 52 apple.has_ppo = 1 53 apple.o2_present = 1 54 apple.ph_milli = 3900 55 apple.temp_c = 20 56 if fcr_predict_browning(apple) != FCR_ENZYMATIC_BROWNING { return 18 } 57 58 // Lemon-dipped cut apple -> no browning at all. 59 apple.ph_milli = 2200 60 if fcr_predict_browning(apple) != FCR_NONE { return 19 } 61 62 return 0 63}