nx_validation_test.nx source
↩ module page · 70 lines · 2483 B
1// nx_validation_test.nx -- smoke for nx_validation. Proves the model-derived
2// test targets, the band/ceiling/floor acceptance rules, and the overall
3// validation verdict (all pass -> validated; a deviation fails that test; a
4// safety breach is fatal). Exit code = failed assertion #; 0 = all pass.
5
6import "nx_syscalls.nx"
7import "nx_water_awg.nx"
8import "nx_water_quality.nx"
9import "nx_water_design.nx"
10import "nx_validation.nx"
11
12func main() -> i64 {
13 if val_water_count() != 7 { return 1 }
14
15 // --- targets are pulled from the actual models (not hand-typed) ---
16 let ty: *NxTestCase = val_water_case(VM_YIELD)
17 if ty.predicted != 34560 { return 2 } // == wa_daily_yield_ml(...)
18 let tr: *NxTestCase = val_water_case(VM_REMIN_TDS)
19 if tr.predicted != 227 { return 3 } // == designed water TDS
20
21 // --- acceptance rules ---
22 if val_pass(ty, 34000) != 1 { return 4 } // within +/-20% band
23 if val_pass(ty, 10000) != 0 { return 5 } // way low -> fail
24 let tb: *NxTestCase = val_water_case(VM_BACTERIA)
25 if val_pass(tb, 0) != 1 { return 6 } // ceiling 0
26 if val_pass(tb, 5) != 0 { return 7 }
27 let tt: *NxTestCase = val_water_case(VM_TASTE)
28 if val_pass(tt, 95) != 1 { return 8 } // floor 90
29 if val_pass(tt, 80) != 0 { return 9 }
30
31 // --- a prototype whose measurements MATCH the model is VALIDATED ---
32 let good: *i64 = sys_mmap(64) as *i64
33 good[0] = 34000
34 good[1] = 220
35 good[2] = 3
36 good[3] = 230
37 good[4] = 95
38 good[5] = 0
39 good[6] = 2
40 if val_run(good) != 7 { return 10 }
41 if val_validated(good) != 1 { return 11 }
42 if val_critical_pass(good) != 1 { return 12 }
43
44 // --- an out-of-tolerance yield falsifies the harvest model ---
45 let lowyield: *i64 = sys_mmap(64) as *i64
46 lowyield[0] = 10000
47 lowyield[1] = 220
48 lowyield[2] = 3
49 lowyield[3] = 230
50 lowyield[4] = 95
51 lowyield[5] = 0
52 lowyield[6] = 2
53 if val_run(lowyield) != 6 { return 13 }
54 if val_validated(lowyield) != 0 { return 14 }
55 if val_critical_pass(lowyield) != 1 { return 15 } // safety still ok
56
57 // --- a bacteria breach is a FATAL safety failure ---
58 let unsafe: *i64 = sys_mmap(64) as *i64
59 unsafe[0] = 34000
60 unsafe[1] = 220
61 unsafe[2] = 3
62 unsafe[3] = 230
63 unsafe[4] = 95
64 unsafe[5] = 5
65 unsafe[6] = 2
66 if val_critical_pass(unsafe) != 0 { return 16 }
67 if val_validated(unsafe) != 0 { return 17 }
68
69 return 0
70}