code wiki / _hdl_build / nx_research_backlog_test.nx

nx_research_backlog_test.nx source

↩ module page · 75 lines · 3998 B

1// nx_research_backlog_test.nx -- ACCEPTANCE GATE for the Researcher's gap-prioritized topic backlog. 2import "nx_research_backlog.nx" 3import "nx_syscalls.nx" 4 5func bt_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 6func bt_putn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); 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 i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 } 7 8func main() -> i64 { 9 var pass: i64 = 0 10 var total: i64 = 0 11 let target: i64 = 10 // target depth = 10 docs per topic 12 13 // a research backlog of 4 topics/terms (priority, current library_hits): 14 // 0 "photolithography" pri 9, hits 0 -> gap 9*1000 = 9000 (high prio, wide open = research FIRST) 15 // 1 "stepper motor" pri 5, hits 8 -> coverage 800, gap 200 -> 5*200 = 1000 16 // 2 "photoresist" pri 8, hits 2 -> coverage 200, gap 800 -> 8*800 = 6400 17 // 3 "G-code" pri 3, hits 10 -> covered 1000, gap 0 -> 0 (well covered, skip) 18 let pri: *i64 = sys_mmap(64) as *i64 19 let st: *i64 = sys_mmap(64) as *i64 20 let hits: *i64 = sys_mmap(64) as *i64 21 pri[0]=9; st[0]=RB_PENDING; hits[0]=0 22 pri[1]=5; st[1]=RB_PENDING; hits[1]=8 23 pri[2]=8; st[2]=RB_PENDING; hits[2]=2 24 pri[3]=3; st[3]=RB_PENDING; hits[3]=10 25 let N: i64 = 4 26 27 // T1: coverage + gap-score math 28 total = total + 1 29 var t1: i64 = 1 30 if rb_coverage_permil(8, 10) != 800 { t1 = 0 } 31 if rb_coverage_permil(0, 10) != 0 { t1 = 0 } 32 if rb_coverage_permil(10, 10) != 1000 { t1 = 0 } 33 if rb_gap_score(9, 0, 10) != 9000 { t1 = 0 } 34 if rb_gap_score(8, 2, 10) != 6400 { t1 = 0 } 35 if rb_gap_score(3, 10, 10) != 0 { t1 = 0 } 36 if t1 == 1 { pass = pass + 1 } else { bt_puts("T1 FAIL gap-math\n" as *u8) } 37 38 // T2: rb_next picks topic 0 (highest gap 9000) FIRST -- research where it's thin + important 39 total = total + 1 40 if rb_next(pri, st, hits, N, target) == 0 { pass = pass + 1 } else { bt_puts("T2 FAIL next=" as *u8); bt_putn(rb_next(pri,st,hits,N,target)); bt_puts("\n" as *u8) } 41 42 // T3: after topic 0 done (added 10 hits), next is topic 2 (gap 6400, the next-thinnest important one) 43 total = total + 1 44 rb_mark_done(st, hits, 0, 10) 45 var t3: i64 = 1 46 if st[0] != RB_DONE { t3 = 0 } 47 if hits[0] != 10 { t3 = 0 } 48 if rb_next(pri, st, hits, N, target) != 2 { t3 = 0 } 49 if t3 == 1 { pass = pass + 1 } else { bt_puts("T3 FAIL next2=" as *u8); bt_putn(rb_next(pri,st,hits,N,target)); bt_puts("\n" as *u8) } 50 51 // T4: progress + library coverage rise as topics are worked 52 total = total + 1 53 var t4: i64 = 1 54 if rb_progress_permil(st, N) != 250 { t4 = 0 } // 1 of 4 done 55 rb_mark_done(st, hits, 2, 8) // photoresist now 10 hits = covered 56 if rb_progress_permil(st, N) != 500 { t4 = 0 } 57 // library coverage now: topic0=1000, topic1=800, topic2=1000, topic3=1000 -> mean 950 58 if rb_library_coverage_permil(hits, N, target) != 950 { t4 = 0 } 59 if t4 == 1 { pass = pass + 1 } else { bt_puts("T4 FAIL prog=" as *u8); bt_putn(rb_progress_permil(st,N)); bt_puts(" cov=" as *u8); bt_putn(rb_library_coverage_permil(hits,N,target)); bt_puts("\n" as *u8) } 60 61 // T5: all-done + rb_next returns -1 when the backlog is cleared 62 total = total + 1 63 rb_mark_done(st, hits, 1, 5) 64 rb_mark_done(st, hits, 3, 0) 65 var t5: i64 = 1 66 if rb_all_done(st, N) != 1 { t5 = 0 } 67 if rb_next(pri, st, hits, N, target) != (0 - 1) { t5 = 0 } 68 if rb_progress_permil(st, N) != 1000 { t5 = 0 } 69 if t5 == 1 { pass = pass + 1 } else { bt_puts("T5 FAIL alldone\n" as *u8) } 70 71 bt_puts("RESEARCH-BACKLOG " as *u8); bt_putn(pass); bt_puts("/" as *u8); bt_putn(total); bt_puts("\n" as *u8) 72 if pass == total { bt_puts("RESEARCH-BACKLOG ALL-PASS\n" as *u8); sys_exit(0) } 73 sys_exit(1) 74 return 1 75}