code wiki / (root) / nx_hunter_test.nx

nx_hunter_test.nx source

↩ module page · 68 lines · 2776 B

1// nx_hunter_test.nx -- smoke for nx_hunter. 2 3import "nx_syscalls.nx" 4import "nx_hunter.nx" 5 6func main() -> i64 { 7 // 1: enums sealed 8 if NX_HK_N_KINDS != 5 { return 1 } 9 if NX_HS_N_STATES != 4 { return 2 } 10 if NX_KP_N_PILLARS != 5 { return 3 } 11 if nx_hk_is_valid(NX_HK_THREAT_ACTOR) != 1 { return 4 } 12 if nx_hk_is_valid(5) != 0 { return 5 } 13 if nx_kp_is_valid(NX_KP_CARDINAL_ABSORBED) != 1 { return 6 } 14 if nx_kp_is_valid(5) != 0 { return 7 } 15 16 // 2: construction 17 let h: *NxHunter = nx_hunter_new(8) 18 if h.capacity != 8 { return 8 } 19 if h.count != 0 { return 9 } 20 if nx_hunter_session_emitted(h) != 0 { return 10 } 21 22 // 3: scout 3 targets 23 let i0: nx_int = nx_hunter_scout(h, 100, NX_HK_BUG_CLASS, 0xa1, 1000) 24 let i1: nx_int = nx_hunter_scout(h, 200, NX_HK_THREAT_ACTOR, 0xb2, 1100) 25 let i2: nx_int = nx_hunter_scout(h, 300, NX_HK_MISSING_FEATURE, 0xc3, 1200) 26 if i0 != 0 { return 11 } 27 if i1 != 1 { return 12 } 28 if i2 != 2 { return 13 } 29 if h.count != 3 { return 14 } 30 if nx_hunter_session_emitted(h) != 1 { return 15 } 31 32 // 4: duplicate / bad-kind / full rejection 33 if nx_hunter_scout(h, 100, NX_HK_BUG_CLASS, 0, 1300) != -1 { return 16 } 34 if nx_hunter_scout(h, 400, 99, 0, 1300) != -1 { return 17 } 35 36 // 5: engage transitions SCOUTED -> ACTIVE 37 if nx_hunter_engage(h, 100, 2000) != NX_HUNTER_OK { return 18 } 38 if nx_hunter_count_by_status(h, NX_HS_ACTIVE) != 1 { return 19 } 39 40 // 6: engage from non-SCOUTED state refused 41 if nx_hunter_engage(h, 100, 2100) != NX_HUNTER_ERR_BAD_TRANSITION { return 20 } 42 43 // 7: engage unknown target 44 if nx_hunter_engage(h, 9999, 2200) != NX_HUNTER_ERR_NOT_FOUND { return 21 } 45 46 // 8: kill -- with pillar 47 if nx_hunter_kill(h, 100, NX_KP_BUG_FIXED, 3000) != NX_HUNTER_OK { return 22 } 48 if nx_hunter_kill(h, 200, NX_KP_THREAT_HARDENED, 3100) != NX_HUNTER_OK { return 23 } 49 50 // 9: counts by pillar 51 if nx_hunter_count_kills_by_pillar(h, NX_KP_BUG_FIXED) != 1 { return 24 } 52 if nx_hunter_count_kills_by_pillar(h, NX_KP_THREAT_HARDENED) != 1 { return 25 } 53 if nx_hunter_count_kills_by_pillar(h, NX_KP_CARDINAL_ABSORBED) != 0 { return 26 } 54 if nx_hunter_total_kills(h) != 2 { return 27 } 55 56 // 10: bad pillar rejected 57 if nx_hunter_kill(h, 300, NX_KP_NONE, 3200) != NX_HUNTER_ERR_BAD_PILLAR { return 28 } 58 if nx_hunter_kill(h, 300, 99, 3200) != NX_HUNTER_ERR_BAD_PILLAR { return 29 } 59 60 // 11: archive uncompleted hunt 61 if nx_hunter_archive(h, 300, 4000) != NX_HUNTER_OK { return 30 } 62 if nx_hunter_count_by_status(h, NX_HS_ARCHIVED) != 1 { return 31 } 63 64 // 12: re-kill after kill refused 65 if nx_hunter_kill(h, 100, NX_KP_BUG_FIXED, 5000) != NX_HUNTER_ERR_BAD_TRANSITION { return 32 } 66 67 return 0 68}