nx_mycorrhizal_test.nx source
↩ module page · 61 lines · 2696 B
1// nx_mycorrhizal_test.nx -- smoke for nx_mycorrhizal.
2
3import "nx_syscalls.nx"
4import "nx_mycorrhizal.nx"
5
6func main() -> i64 {
7 let n: *NxMycorrhizalNetwork = nx_mycorrhizal_new(8, 16)
8 if n.node_capacity != 8 { return 1 }
9 if n.edge_capacity != 16 { return 2 }
10 if n.n_nodes != 0 { return 3 }
11
12 // Join 4 peers
13 if nx_mycorrhizal_join(n, 100, 921, 1000) != NX_MYC_OK { return 4 }
14 if nx_mycorrhizal_join(n, 200, 819, 1100) != NX_MYC_OK { return 5 }
15 if nx_mycorrhizal_join(n, 300, 716, 1200) != NX_MYC_OK { return 6 }
16 if nx_mycorrhizal_join(n, 400, 410, 1300) != NX_MYC_OK { return 7 }
17 if nx_mycorrhizal_peer_count(n) != 4 { return 8 }
18
19 // Duplicate join refused
20 if nx_mycorrhizal_join(n, 100, 1024, 1400) != NX_MYC_ERR_ALREADY_LINKED { return 9 }
21
22 // Link peers -- 100<->200, 200<->300, 300<->400 (chain), plus 100<->300 (triangle)
23 if nx_mycorrhizal_link(n, 100, 200, 870, 2000) != NX_MYC_OK { return 10 }
24 if nx_mycorrhizal_link(n, 200, 300, 716, 2100) != NX_MYC_OK { return 11 }
25 if nx_mycorrhizal_link(n, 300, 400, 614, 2200) != NX_MYC_OK { return 12 }
26 if nx_mycorrhizal_link(n, 100, 300, 921, 2300) != NX_MYC_OK { return 13 }
27 if nx_mycorrhizal_edge_count(n) != 4 { return 14 }
28
29 // Link existing rejected
30 if nx_mycorrhizal_link(n, 100, 200, 870, 2400) != NX_MYC_ERR_ALREADY_LINKED { return 15 }
31 if nx_mycorrhizal_link(n, 200, 100, 870, 2400) != NX_MYC_ERR_ALREADY_LINKED { return 16 }
32
33 // Link unknown peer rejected
34 if nx_mycorrhizal_link(n, 100, 9999, 870, 2400) != NX_MYC_ERR_NOT_FOUND { return 17 }
35
36 // is_linked check (bidirectional)
37 if nx_mycorrhizal_is_linked(n, 100, 200) != 1 { return 18 }
38 if nx_mycorrhizal_is_linked(n, 200, 100) != 1 { return 19 }
39 if nx_mycorrhizal_is_linked(n, 100, 400) != 0 { return 20 }
40
41 // Degree: peer 100 has 2 edges (100-200, 100-300)
42 if nx_mycorrhizal_peer_degree(n, 100) != 2 { return 21 }
43 // peer 300 has 3 edges (300-200, 300-400, 300-100)
44 if nx_mycorrhizal_peer_degree(n, 300) != 3 { return 22 }
45 // peer 400 has 1 (leaf)
46 if nx_mycorrhizal_peer_degree(n, 400) != 1 { return 23 }
47 // unknown peer = degree 0
48 if nx_mycorrhizal_peer_degree(n, 9999) != 0 { return 24 }
49
50 // Health count: 100 (921) + 200 (819) + 300 (716) >= threshold 614; 400 (410) does NOT
51 if nx_mycorrhizal_count_healthy(n) != 3 { return 25 }
52
53 // Update health -- 400 climbs to healthy
54 nx_mycorrhizal_update_health(n, 400, 870, 3000)
55 if nx_mycorrhizal_count_healthy(n) != 4 { return 26 }
56
57 // Update unknown peer rejected
58 if nx_mycorrhizal_update_health(n, 9999, 1024, 4000) != NX_MYC_ERR_NOT_FOUND { return 27 }
59
60 return 0
61}