nx_meristem_test.nx source
↩ module page · 116 lines · 4904 B
1// nx_meristem_test.nx -- smoke for nx_meristem.
2
3import "nx_syscalls.nx"
4import "nx_meristem.nx"
5
6func main() -> i64 {
7 let now: nx_size = 1000000
8
9 // 1: enum validity
10 if nx_me_role_is_valid(NX_ME_ROLE_UNDIFFERENTIATED) != 1 { return 1 }
11 if nx_me_role_is_valid(NX_ME_ROLE_AUDIT_SCAN) != 1 { return 2 }
12 if nx_me_role_is_valid(-1) != 0 { return 3 }
13 if nx_me_role_is_valid(10) != 0 { return 4 }
14 if NX_ME_ROLE_N != 10 { return 5 }
15
16 if nx_me_v_is_valid(NX_ME_V_OK) != 1 { return 6 }
17 if nx_me_v_is_valid(NX_ME_V_NULL) != 1 { return 7 }
18 if nx_me_v_is_valid(NX_ME_V_N) != 0 { return 8 }
19
20 // 2: compute-heavy classification
21 if nx_me_role_is_compute_heavy(NX_ME_ROLE_LLM_INFERENCE) != 1 { return 9 }
22 if nx_me_role_is_compute_heavy(NX_ME_ROLE_IMAGE_GEN) != 1 { return 10 }
23 if nx_me_role_is_compute_heavy(NX_ME_ROLE_VIDEO_GEN) != 1 { return 11 }
24 if nx_me_role_is_compute_heavy(NX_ME_ROLE_PHYSICS_SIM) != 1 { return 12 }
25 if nx_me_role_is_compute_heavy(NX_ME_ROLE_AUDIO_TTS) != 0 { return 13 }
26 if nx_me_role_is_compute_heavy(NX_ME_ROLE_STORAGE_TIER) != 0 { return 14 }
27 if nx_me_role_is_compute_heavy(NX_ME_ROLE_NETWORK_PEER) != 0 { return 15 }
28
29 // 3: construction
30 let m: *NxMeristem = nx_me_new(42, 16, 100, now)
31 if m.meristem_id != 42 { return 16 }
32 if m.capacity != 16 { return 17 }
33 if m.parent_seed_id != 100 { return 18 }
34 if m.n_cells != 0 { return 19 }
35 if m.next_cell_id != 1 { return 20 }
36
37 // 4: invalid construction
38 if nx_me_new(0, 16, 100, now) != (0 as *NxMeristem) { return 21 }
39 if nx_me_new(42, 0, 100, now) != (0 as *NxMeristem) { return 22 }
40
41 // 5: spawn undifferentiated cells
42 let c1: nx_int = nx_me_spawn(m, 0, now)
43 if c1 != 1 { return 23 }
44 let c2: nx_int = nx_me_spawn(m, 1, now)
45 if c2 != 2 { return 24 }
46 let c3: nx_int = nx_me_spawn(m, 1, now)
47 if c3 != 3 { return 25 }
48 if m.n_cells != 3 { return 26 }
49 if m.next_cell_id != 4 { return 27 }
50
51 // 6: all spawned cells are undifferentiated
52 if nx_me_undifferentiated_count(m) != 3 { return 28 }
53 if nx_me_count_by_role(m, NX_ME_ROLE_LLM_INFERENCE) != 0 { return 29 }
54
55 // 7: find cells
56 let cell1: *NxCell = nx_me_find_cell(m, 1)
57 if cell1.cell_id != 1 { return 30 }
58 if cell1.role != NX_ME_ROLE_UNDIFFERENTIATED { return 31 }
59 if cell1.parent_meristem_id != 42 { return 32 }
60 if cell1.lineage_depth != 0 { return 33 }
61 if cell1.committed_at_us != 0 { return 34 }
62
63 let cell_missing: *NxCell = nx_me_find_cell(m, 9999)
64 if (cell_missing as i64) != 0 { return 35 }
65
66 // 8: differentiate cell 1 into LLM_INFERENCE
67 if nx_me_differentiate(m, 1, NX_ME_ROLE_LLM_INFERENCE, now + 100) != NX_ME_V_OK { return 36 }
68 let cell1_after: *NxCell = nx_me_find_cell(m, 1)
69 if cell1_after.role != NX_ME_ROLE_LLM_INFERENCE { return 37 }
70 if cell1_after.committed_at_us != (now + 100) { return 38 }
71
72 // 9: counts shift
73 if nx_me_undifferentiated_count(m) != 2 { return 39 }
74 if nx_me_count_by_role(m, NX_ME_ROLE_LLM_INFERENCE) != 1 { return 40 }
75
76 // 10: re-differentiate refused
77 if nx_me_differentiate(m, 1, NX_ME_ROLE_IMAGE_GEN, now + 200) != NX_ME_V_ALREADY_DIFFERENTIATED { return 41 }
78
79 // 11: differentiate to UNDIFFERENTIATED refused
80 if nx_me_differentiate(m, 2, NX_ME_ROLE_UNDIFFERENTIATED, now) != NX_ME_V_INVALID { return 42 }
81
82 // 12: invalid role refused
83 if nx_me_differentiate(m, 2, 99, now) != NX_ME_V_INVALID { return 43 }
84 if nx_me_differentiate(m, 2, -1, now) != NX_ME_V_INVALID { return 44 }
85
86 // 13: differentiate unknown cell refused
87 if nx_me_differentiate(m, 9999, NX_ME_ROLE_GAME_LOGIC, now) != NX_ME_V_INVALID { return 45 }
88
89 // 14: differentiate two more into different roles
90 nx_me_differentiate(m, 2, NX_ME_ROLE_IMAGE_GEN, now)
91 nx_me_differentiate(m, 3, NX_ME_ROLE_GAME_LOGIC, now)
92 if nx_me_count_by_role(m, NX_ME_ROLE_IMAGE_GEN) != 1 { return 46 }
93 if nx_me_count_by_role(m, NX_ME_ROLE_GAME_LOGIC) != 1 { return 47 }
94 if nx_me_undifferentiated_count(m) != 0 { return 48 }
95
96 // 15: max lineage depth
97 if nx_me_max_lineage_depth(m) != 1 { return 49 }
98 nx_me_spawn(m, 5, now)
99 if nx_me_max_lineage_depth(m) != 5 { return 50 }
100
101 // 16: capacity exceeded
102 let m_full: *NxMeristem = nx_me_new(1, 2, 0, now)
103 nx_me_spawn(m_full, 0, now)
104 nx_me_spawn(m_full, 0, now)
105 if nx_me_spawn(m_full, 0, now) != 0 { return 51 }
106
107 // 17: null handling
108 let null_m: *NxMeristem = (0 as i64) as *NxMeristem
109 if nx_me_spawn(null_m, 0, now) != 0 { return 52 }
110 if (nx_me_find_cell(null_m, 1) as i64) != 0 { return 53 }
111 if nx_me_differentiate(null_m, 1, NX_ME_ROLE_LLM_INFERENCE, now) != NX_ME_V_NULL { return 54 }
112 if nx_me_count_by_role(null_m, NX_ME_ROLE_LLM_INFERENCE) != 0 { return 55 }
113 if nx_me_max_lineage_depth(null_m) != 0 { return 56 }
114
115 return 0
116}