code wiki / _hdl_build / test_anatomy_risk.nx

test_anatomy_risk.nx source

↩ module page · 37 lines · 2623 B

1// unit test for nx_anatomy_risk: verifies score (x1000 weights) + fired factors per the ported anatomy_score_v2 model. 2import "nx_anatomy_risk.nx" 3import "nx_syscalls.nx" 4 5func t_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 6func 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 } 7func 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 } 8 9func check(prompt: *u8, want_score: i64, want_factors: *u8) -> i64 { 10 let fo: *u8 = sys_mmap(512) 11 let sc: i64 = go_anatomy_risk(prompt, t_slen(prompt), fo) 12 var ok: i64 = 1 13 if sc != want_score { ok = 0 } 14 if t_streq(want_factors, "NONE" as *u8)==1 { if fo[0]!=(0 as u8) { ok = 0 } } else { if t_streq(fo, want_factors)==0 { ok = 0 } } 15 let line: *u8 = sys_mmap(1024); var o: i64 = 0 16 if ok==1 { line[0]=80 as u8; line[1]=65 as u8; line[2]=83 as u8; line[3]=83 as u8; o=4 } else { line[0]=70 as u8; line[1]=65 as u8; line[2]=73 as u8; line[3]=76 as u8; o=4 } 17 line[o]=32 as u8; o=o+1 18 o = t_itoa(line, o, sc); line[o]=47 as u8; o=o+1; o=t_itoa(line, o, want_score) 19 line[o]=32 as u8; o=o+1; line[o]=91 as u8; o=o+1 20 var k: i64=0; while fo[k]!=(0 as u8){line[o]=fo[k];o=o+1;k=k+1} 21 line[o]=93 as u8; o=o+1; line[o]=10 as u8; o=o+1 22 sys_write(1, line, o) 23 return ok 24} 25 26func main() -> i64 { 27 var all: i64 = 1 28 if check("photograph of a woman in a summer dress at a cafe, natural daylight" as *u8, 1000, "NONE" as *u8)==0 { all=0 } 29 if check("photo of her from behind, gaze into the camera" as *u8, 600, "rear_pose_with_face_visible," as *u8)==0 { all=0 } 30 if check("her wet skin glistening in the studio" as *u8, 800, "wet_token_no_wet_context," as *u8)==0 { all=0 } 31 if check("wearing a silk dress, nude breasts exposed" as *u8, 800, "outfit_state_contradiction," as *u8)==0 { all=0 } 32 if check("extreme close-up of her thighs and hips" as *u8, 750, "ecu_close_up_mentions_full_body," as *u8)==0 { all=0 } 33 if check("her wet skin in the shower, warm water" as *u8, 1000, "NONE" as *u8)==0 { all=0 } 34 if check("photo from behind, gaze into the camera, her wet skin bare" as *u8, 400, "rear_pose_with_face_visible,wet_token_no_wet_context," as *u8)==0 { all=0 } 35 if all==1 { sys_write(1, "ALL-PASS\n" as *u8, 9) } else { sys_write(1, "SOME-FAIL\n" as *u8, 10) } 36 return 0 37}