nx_question_genealogy_test.nx source
↩ module page · 69 lines · 2625 B
1// nx_question_genealogy_test.nx -- smoke for the why-chain primitive.
2
3import "syscalls.nx"
4import "nx_question_genealogy.nx"
5
6func main() -> i64 {
7 let t: *QuestionTree = nx_qg_tree_alloc()
8 let n: i64 = nx_qg_seed_corpus(t)
9 // 3 roots + 8 pi-chain + 6 pyth-chain + 7 primes-chain = 24? let's count:
10 // pi: 1 root + 7 refinements = 8 nodes
11 // pyth: 1 root + 5 refinements = 6 nodes
12 // primes: 1 root + 6 refinements = 7 nodes
13 // Total = 21 nodes
14 if n != 21 { return 1 }
15 if t.n_nodes != 21 { return 2 }
16
17 // === Roots ===
18 let n_roots: i64 = nx_qg_count_by_tier(t, NX_QG_TIER_ROOT)
19 if n_roots != 3 { return 10 }
20
21 // === Refinements ===
22 // pi has 4 refinements as REFINEMENT tier (L1..L4)
23 // pyth has 4 refinements as REFINEMENT (L1..L4)
24 // primes has 4 refinements as REFINEMENT (L1..L4)
25 // Total = 12 (L5+ are NICHE / OPEN)
26 let n_refines: i64 = nx_qg_count_by_tier(t, NX_QG_TIER_REFINEMENT)
27 if n_refines != 12 { return 11 }
28
29 // === Niche ===
30 // pi: L5, L6 = 2
31 // pyth: L5 = 1
32 // primes: L5 = 1
33 // Total = 4
34 let n_niche: i64 = nx_qg_count_by_tier(t, NX_QG_TIER_NICHE)
35 if n_niche != 4 { return 12 }
36
37 // === Open research ===
38 // pi: L7
39 // primes: L6
40 // Total = 2
41 let n_open: i64 = nx_qg_count_by_tier(t, NX_QG_TIER_OPEN_RESEARCH)
42 if n_open != 2 { return 13 }
43
44 // === Trace check: pi research node back to root ===
45 // pi_root is node 0; pi_l7 is node 7.
46 let chain: *i64 = (sys_mmap(64 * 8)) as *i64
47 let depth: i64 = nx_qg_trace_from_root(t, 7, chain, 64)
48 if depth != 8 { return 20 }
49 if chain[0] != 0 { return 21 } // root
50 if chain[7] != 7 { return 22 } // target
51
52 // === Each node's depth_from_root is correctly computed ===
53 let root_n: *QuestionNode = nx_qg_node_at(t, 0)
54 if root_n.depth_from_root != 0 { return 30 }
55 let l7_n: *QuestionNode = nx_qg_node_at(t, 7)
56 if l7_n.depth_from_root != 7 { return 31 }
57
58 // === Emit a narrative for the pi chain to stderr ===
59 sys_write(2, "PI question-genealogy chain:\n" as *u8, 29)
60 nx_qg_emit_narrative(2, t, 7)
61 sys_write(2, "\nPYTHAGORAS question-genealogy chain:\n" as *u8, 38)
62 // Pythagoras chain: root is node 8 (after pi's 8 nodes), niche is node 13.
63 nx_qg_emit_narrative(2, t, 13)
64 sys_write(2, "\nPRIMES question-genealogy chain:\n" as *u8, 34)
65 // Primes root is node 14, open frontier is node 20.
66 nx_qg_emit_narrative(2, t, 20)
67
68 return 0
69}