code wiki / (root) / nx_lysosome_test.nx

nx_lysosome_test.nx source

↩ module page · 42 lines · 1417 B

1// nx_lysosome_test.nx -- smoke for nx_lysosome. 2 3import "nx_syscalls.nx" 4import "nx_lysosome.nx" 5 6func main() -> i64 { 7 let l: *NxLysosome = nx_lysosome_new(4) 8 if l.capacity != 4 { return 1 } 9 if l.count != 0 { return 2 } 10 if nx_lysosome_is_empty(l) != 1 { return 3 } 11 12 // Enqueue 3 13 nx_lysosome_enqueue(l, 100, 1, 1000) 14 nx_lysosome_enqueue(l, 200, 2, 2000) 15 nx_lysosome_enqueue(l, 300, 3, 3000) 16 if l.count != 3 { return 4 } 17 if nx_lysosome_count(l) != 3 { return 5 } 18 if nx_lysosome_is_empty(l) != 0 { return 6 } 19 20 // Drain in FIFO order 21 if nx_lysosome_drain_one(l) != 100 { return 7 } 22 if nx_lysosome_drain_one(l) != 200 { return 8 } 23 if l.count != 1 { return 9 } 24 if nx_lysosome_total_drained(l) != 2 { return 10 } 25 26 // FULL when at capacity (4) 27 nx_lysosome_enqueue(l, 400, 1, 4000) 28 nx_lysosome_enqueue(l, 500, 1, 5000) 29 nx_lysosome_enqueue(l, 600, 1, 6000) 30 if l.count != 4 { return 11 } 31 if nx_lysosome_enqueue(l, 700, 1, 7000) != NX_LYSO_ERR_FULL { return 12 } 32 33 // Drain wraps correctly 34 if nx_lysosome_drain_one(l) != 300 { return 13 } 35 if nx_lysosome_drain_one(l) != 400 { return 14 } 36 if nx_lysosome_drain_one(l) != 500 { return 15 } 37 if nx_lysosome_drain_one(l) != 600 { return 16 } 38 if nx_lysosome_drain_one(l) != -1 { return 17 } // empty 39 if nx_lysosome_total_drained(l) != 6 { return 18 } 40 41 return 0 42}