code wiki / (root) / nx_content_measure_test.nx

nx_content_measure_test.nx source

↩ module page · 38 lines · 1667 B

1// nx_content_measure_test.nx -- KATs for the measured content-value kernel 2// (GATE). Construction-known HTML + text lengths -> exact Q16.16 expectations. 3import "nx_str.nx" 4import "nx_syscalls.nx" 5import "nx_content_measure.nx" 6 7func ct_p(s: *u8) -> i64 { sys_write(1, s, nx_str_len(s)); return 0 } 8 9func ct_case(name: *u8, html: *u8, textlen: i64, want: i64, acc: *i64) -> i64 { 10 let got: i64 = nx_content_measure(html, nx_str_len(html), textlen) 11 ct_p(" "); ct_p(name); ct_p(": ") 12 if got == want { ct_p("PASS\n"); acc[0] = acc[0] + 1 } else { ct_p("FAIL\n") } 13 acc[1] = acc[1] + 1 14 return 0 15} 16 17func main() -> i64 { 18 ct_p("=== nx_content_measure KAT ===\n") 19 let acc: *i64 = sys_mmap(16) as *i64 20 acc[0] = 0 21 acc[1] = 0 22 // gallery-class: 12 img tags (case-mixed) + article text -> (1.0+1.0)/2 = 1.0 23 ct_case("gallery-article", 24 "<IMG a><img b><img c><img d><img e><img f><img g><img h><img i><img j><img k><img l>", 25 4000, 65536, acc) 26 // JS shell: no media, 10 chars text -> (0.25+0)/2 = 0.125 (8192) 27 ct_case("js-shell", "<div id=app></div>", 10, 8192, acc) 28 // illustrated stub: 4 media (img+video+audio+img), 1000 chars -> (0.75+0.75)/2 = 0.75 (49152) 29 ct_case("illustrated-stub", "<img1><video x><audio y><img2>", 1000, 49152, acc) 30 // empty body -> 0 31 ct_case("empty", "", 0, 0, acc) 32 // token imagery + thin text: 1 img, 200 chars -> (0.5+0.5)/2 = 0.5 (32768) 33 ct_case("thin-token", "<p>hi</p><img z>", 200, 32768, acc) 34 if acc[0] == acc[1] { ct_p(" CONTENT-MEASURE-KAT: 5/5 PASS\n"); sys_exit(0); return 0 } 35 ct_p(" CONTENT-MEASURE-KAT: FAIL\n") 36 sys_exit(1) 37 return 1 38}