code wiki / (root) / nx_doc_decision_test.nx

nx_doc_decision_test.nx source

↩ module page · 84 lines · 3688 B

1// nx_doc_decision_test.nx -- KAT for D20 ADR-shape primitive. 2 3import "nx_syscalls.nx" 4import "nx_string_ops.nx" 5import "nx_doc_decision.nx" 6 7func main() -> i64 { 8 // ----- T1 Status sealed enum ----- 9 var i: i64 = 0 10 while i < NX_DECISION_N { 11 if nx_decision_status_is_valid(i) != 1 { return 1 + i } 12 i = i + 1 13 } 14 if nx_decision_status_is_valid(0 - 1) != 0 { return 10 } 15 if nx_decision_status_is_valid(NX_DECISION_N) != 0 { return 11 } 16 17 // ----- T2 Init defaults ----- 18 let r_buf: *u8 = sys_mmap(256) 19 let r: *NxDecisionRecord = r_buf as *NxDecisionRecord 20 nx_decision_record_init(r, 1, 20260521) 21 if r.id != 1 { return 20 } 22 if r.timestamp_q14 != 20260521 { return 21 } 23 if r.status != NX_DECISION_PROPOSED { return 22 } 24 if r.supersedes_id != 0 { return 23 } 25 if r.title_len != 0 { return 24 } 26 if r.problem_len != 0 { return 25 } 27 28 // ----- T3 Completeness rejects empty record ----- 29 if nx_decision_record_completeness(r) != 1 { return 30 } // title missing 30 let title: *u8 = "Use Boyer-Moore for nx_grep" 31 r.title_ptr = title 32 r.title_len = 28 33 if nx_decision_record_completeness(r) != 2 { return 31 } // problem missing 34 let problem: *u8 = "Substring search needs fast skip-on-mismatch." 35 r.problem_ptr = problem 36 r.problem_len = 45 37 if nx_decision_record_completeness(r) != 3 { return 32 } // chosen missing 38 let chosen: *u8 = "Boyer-Moore single-pattern baseline." 39 r.chosen_ptr = chosen 40 r.chosen_len = 36 41 if nx_decision_record_completeness(r) != 0 { return 33 } // complete! 42 43 // ----- T4 Invalid status fails completeness even if other fields set ----- 44 r.status = 9999 45 if nx_decision_record_completeness(r) != 4 { return 40 } 46 r.status = NX_DECISION_ACCEPTED 47 if nx_decision_record_completeness(r) != 0 { return 41 } 48 49 // ----- T5 Status name lookup ----- 50 if nx_str_equals(nx_decision_status_name(NX_DECISION_PROPOSED), 8, "PROPOSED", 8) != 1 { return 50 } 51 if nx_str_equals(nx_decision_status_name(NX_DECISION_ACCEPTED), 8, "ACCEPTED", 8) != 1 { return 51 } 52 if nx_str_equals(nx_decision_status_name(NX_DECISION_SUPERSEDED), 10, "SUPERSEDED", 10) != 1 { return 52 } 53 if nx_str_equals(nx_decision_status_name(NX_DECISION_DEPRECATED), 10, "DEPRECATED", 10) != 1 { return 53 } 54 if nx_str_equals(nx_decision_status_name(NX_DECISION_REJECTED), 8, "REJECTED", 8) != 1 { return 54 } 55 56 // ----- T6 Emit complete ADR returns 0 ----- 57 // (Stdout output not verified here; smoke harness captures it 58 // for visual inspection. Substrate-honest: emit returns the 59 // completeness code which we already verified == 0.) 60 let rc_emit: i64 = nx_decision_record_emit(r) 61 if rc_emit != 0 { return 60 } 62 63 // ----- T7 Supersedes_id set and emit (writes supersedes line) ----- 64 r.supersedes_id = 7 65 let rc_emit2: i64 = nx_decision_record_emit(r) 66 if rc_emit2 != 0 { return 70 } 67 68 // ----- T8 Optional fields fill correctly ----- 69 let alts: *u8 = "KMP (no skip); Aho-Corasick (multi-pattern overkill); naive O(n*m)." 70 r.alternatives_ptr = alts 71 r.alternatives_len = 67 72 let formula: *u8 = "bm_shift[c] = pattern length - last index of c (or full length)." 73 r.formula_ptr = formula 74 r.formula_len = 64 75 let physics: *u8 = "Skip-on-mismatch lowers expected comparisons toward O(n/m)." 76 r.physics_justification_ptr = physics 77 r.physics_justification_len = 59 78 let research: *u8 = "SIMD vectorized skip; Muła-Lemire 2020; queued." 79 r.research_opportunities_ptr = research 80 r.research_opportunities_len = 47 81 if nx_decision_record_emit(r) != 0 { return 80 } 82 83 return 0 84}