nx_gather_compost_test.nx source
↩ module page · 52 lines · 1952 B
1// nx_gather_compost_test.nx -- smoke for nx_gather_compost.
2
3import "nx_syscalls.nx"
4import "nx_gather_compost.nx"
5
6func main() -> i64 {
7 if NX_CS_N_SOURCES != 5 { return 1 }
8 if nx_cs_source_is_valid(NX_CS_HUNT_EVIDENCE) != 1 { return 2 }
9 if nx_cs_source_is_valid(5) != 0 { return 3 }
10
11 let p: *NxCompostPile = nx_compost_pile_new(16)
12
13 // Deposit lessons from prior arcs
14 nx_compost_deposit(p, 1, NX_CS_HUNT_EVIDENCE, 100, 0xa1, 1000) // Argon2id lesson
15 nx_compost_deposit(p, 2, NX_CS_GATHER_YIELD, 101, 0xa2, 1100) // browser CSS yield
16 nx_compost_deposit(p, 3, NX_CS_CARDINAL_TEXT, 102, 0xa3, 1200) // Captain Moroni text
17 if p.count != 3 { return 4 }
18
19 // Bad source rejected
20 if nx_compost_deposit(p, 4, 99, 103, 0xa4, 1300) != NX_GC_ERR_BAD_SOURCE { return 5 }
21
22 // Count by source
23 if nx_compost_count_by_source(p, NX_CS_HUNT_EVIDENCE) != 1 { return 6 }
24 if nx_compost_count_by_source(p, NX_CS_PR_RESEARCH) != 0 { return 7 }
25
26 // Apply the Argon2id lesson to current arc (TLS)
27 if nx_compost_apply(p, 1, 2000) != NX_GC_OK { return 8 }
28 if nx_compost_applied_count(p, 1) != 1 { return 9 }
29
30 // Apply again -- count compounds
31 nx_compost_apply(p, 1, 3000)
32 nx_compost_apply(p, 1, 4000)
33 if nx_compost_applied_count(p, 1) != 3 { return 10 }
34
35 // Apply unknown entry
36 if nx_compost_apply(p, 9999, 5000) != NX_GC_ERR_NOT_FOUND { return 11 }
37
38 // Total applications
39 if nx_compost_total_applications(p) != 3 { return 12 }
40
41 // Apply another entry
42 nx_compost_apply(p, 2, 6000)
43 if nx_compost_total_applications(p) != 4 { return 13 }
44
45 // FULL
46 let small: *NxCompostPile = nx_compost_pile_new(2)
47 nx_compost_deposit(small, 1, NX_CS_HUNT_EVIDENCE, 1, 0xaa, 1000)
48 nx_compost_deposit(small, 2, NX_CS_HUNT_EVIDENCE, 2, 0xbb, 1000)
49 if nx_compost_deposit(small, 3, NX_CS_HUNT_EVIDENCE, 3, 0xcc, 1000) != NX_GC_ERR_FULL { return 14 }
50
51 return 0
52}