code wiki / _hdl_build / nx_lineage_archive_test.nx

nx_lineage_archive_test.nx source

↩ module page · 50 lines · 2626 B

1// nx_lineage_archive_test.nx -- ACCEPTANCE GATE for the GENEALOGIST's lineage archive (DEDUP/lineage, 2// the branching-archive owner; Darwin-Godel keep-all-clones). Was untested -- now Engineer-verifiable. 3import "nx_lineage_archive.nx" 4import "nx_syscalls.nx" 5 6func lt_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 7func lt_putn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m} 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 } 8 9func main() -> i64 { 10 var pass: i64 = 0 11 var total: i64 = 0 12 13 let parents: *i64 = sys_mmap(128) as *i64 14 let scores: *i64 = sys_mmap(128) as *i64 15 // archive 4 clones: scores 30, 70, 50, 90 (la_archive returns the clone id; caller increments n) 16 var n: i64 = 0 17 la_archive(parents, scores, n, 0 - 1, 30); n = n + 1 18 la_archive(parents, scores, n, 0, 70); n = n + 1 19 la_archive(parents, scores, n, 0, 50); n = n + 1 20 la_archive(parents, scores, n, 1, 90); n = n + 1 21 22 // T1: archive grew to 4, no deletion 23 total = total + 1 24 var t1: i64 = 1 25 if n != 4 { t1 = 0 } 26 if la_no_deletion(0, n) != 1 { t1 = 0 } 27 if t1 == 1 { pass = pass + 1 } else { lt_puts("T1 FAIL archive n=" as *u8); lt_putn(n); lt_puts("\n" as *u8) } 28 29 // T2: la_best returns the index of the top score (90 at idx 3); frontier = 90 30 total = total + 1 31 var t2: i64 = 1 32 if la_best(scores, n) != 3 { t2 = 0 } 33 if la_frontier(scores, n) != 90 { t2 = 0 } 34 if t2 == 1 { pass = pass + 1 } else { lt_puts("T2 FAIL best=" as *u8); lt_putn(la_best(scores,n)); lt_puts(" front=" as *u8); lt_putn(la_frontier(scores,n)); lt_puts("\n" as *u8) } 35 36 // T3: branchability + seeded breakthrough (a LOW parent seeding a child past the frontier) 37 total = total + 1 38 var t3: i64 = 1 39 if la_can_branch_from(0, n) != 1 { t3 = 0 } 40 if la_can_branch_from(0 - 1, n) != 0 { t3 = 0 } 41 if la_can_branch_from(n, n) != 0 { t3 = 0 } 42 if la_seeded_breakthrough(30, 100, 90) != 1 { t3 = 0 } // low parent(30)->child(100)>frontier(90) 43 if la_seeded_breakthrough(70, 80, 90) != 0 { t3 = 0 } // child below frontier -> not a breakthrough 44 if t3 == 1 { pass = pass + 1 } else { lt_puts("T3 FAIL branch/seed\n" as *u8) } 45 46 lt_puts("LINEAGE-ARCHIVE " as *u8); lt_putn(pass); lt_puts("/" as *u8); lt_putn(total); lt_puts("\n" as *u8) 47 if pass == total { lt_puts("LINEAGE-ARCHIVE ALL-PASS\n" as *u8); sys_exit(0) } 48 sys_exit(1) 49 return 1 50}