code wiki / _hdl_build / test_render_coherence.nx

test_render_coherence.nx source

↩ module page · 48 lines · 3096 B

1// unit test for nx_render_coherence: the wet_without_context PREVENTATIVE. Proves (a) correct reframe strings, (b) the 2// INTEGRATION win -- after repair, go_anatomy_risk no longer fires wet_token_no_wet_context (the #1 render bug removed). 3import "nx_render_coherence.nx" 4import "nx_anatomy_risk.nx" 5import "nx_syscalls.nx" 6 7func t_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 8func t_streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8) { if (a[i]&0xff)!=(b[i]&0xff) { return 0 } i=i+1 } if b[i]!=(0 as u8) { return 0 } return 1 } 9func t_itoa(dst: *u8, off: i64, v: i64) -> i64 { let t: *u8=sys_mmap(28); var m: i64=v; var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var o: i64=off; var q: i64=k-1; while q>=0{dst[o]=t[q];o=o+1;q=q-1} return o } 10func t_emit(s: *u8) -> i64 { sys_write(1, s, t_slen(s)); return 0 } 11 12func check_repair(prompt: *u8, want_out: *u8, want_fired: i64) -> i64 { 13 let out: *u8 = sys_mmap(4096); let fb: *i64 = sys_mmap(16) as *i64 14 go_coherence_repair(prompt, t_slen(prompt), out, fb) 15 var ok: i64 = 1 16 if t_streq(out, want_out)==0 { ok=0 } 17 if fb[0] != want_fired { ok=0 } 18 if ok==1 { t_emit("PASS " as *u8) } else { t_emit("FAIL " as *u8) } 19 t_emit(out); t_emit(" fired=" as *u8); let d: *u8=sys_mmap(8); var n: i64=t_itoa(d,0,fb[0]); d[n]=0 as u8; t_emit(d); t_emit("\n" as *u8) 20 return ok 21} 22// integration: risk BEFORE vs AFTER repair 23func check_integration(prompt: *u8, want_before: i64, want_after: i64) -> i64 { 24 let f1: *u8 = sys_mmap(512); let rb: i64 = go_anatomy_risk(prompt, t_slen(prompt), f1) 25 let out: *u8 = sys_mmap(4096); let fb: *i64 = sys_mmap(16) as *i64 26 go_coherence_repair(prompt, t_slen(prompt), out, fb) 27 let f2: *u8 = sys_mmap(512); let ra: i64 = go_anatomy_risk(out, t_slen(out), f2) 28 var ok: i64 = 1 29 if rb != want_before { ok=0 } 30 if ra != want_after { ok=0 } 31 if ok==1 { t_emit("PASS " as *u8) } else { t_emit("FAIL " as *u8) } 32 let d: *u8=sys_mmap(32); var n: i64=t_itoa(d,0,rb); d[n]=47 as u8; n=t_itoa(d,n+1,ra); d[n]=0 as u8 33 t_emit("risk " as *u8); t_emit(d); t_emit(" [" as *u8); t_emit(out); t_emit("]\n" as *u8) 34 return ok 35} 36 37func main() -> i64 { 38 var all: i64 = 1 39 if check_repair("her wet skin in the studio" as *u8, "her dewy skin in the studio" as *u8, 1)==0 { all=0 } 40 if check_repair("her wet skin in the shower" as *u8, "her wet skin in the shower" as *u8, 0)==0 { all=0 } 41 if check_repair("soaked and dripping in the bedroom" as *u8, "glistening and glistening in the bedroom" as *u8, 1)==0 { all=0 } 42 if check_repair("photo in the wetlands" as *u8, "photo in the wetlands" as *u8, 0)==0 { all=0 } 43 if check_repair("her moist lips" as *u8, "her dewy lips" as *u8, 1)==0 { all=0 } 44 if check_integration("her wet skin glistening in the studio" as *u8, 800, 1000)==0 { all=0 } 45 if check_integration("her wet skin in the shower" as *u8, 1000, 1000)==0 { all=0 } 46 if all==1 { t_emit("ALL-PASS\n" as *u8) } else { t_emit("SOME-FAIL\n" as *u8) } 47 return 0 48}