code wiki / (root) / nx_ecotone_test.nx

nx_ecotone_test.nx source

↩ module page · 131 lines · 6440 B

1// nx_ecotone_test.nx -- smoke for nx_ecotone. 2 3import "nx_syscalls.nx" 4import "nx_ecotone.nx" 5 6func main() -> i64 { 7 // 1: transition enum validity 8 if nx_et_transition_is_valid(NX_ET_FOREST_MEADOW) != 1 { return 1 } 9 if nx_et_transition_is_valid(NX_ET_URBAN_GREENSPACE) != 1 { return 2 } 10 if nx_et_transition_is_valid(-1) != 0 { return 3 } 11 if nx_et_transition_is_valid(10) != 0 { return 4 } 12 if NX_ET_N_TRANSITIONS != 10 { return 5 } 13 14 // 2: species role enum validity 15 if nx_sr_role_is_valid(NX_SR_CANOPY_DOMINANT) != 1 { return 6 } 16 if nx_sr_role_is_valid(NX_SR_INVASIVE_RISK_FLAG) != 1 { return 7 } 17 if nx_sr_role_is_valid(-1) != 0 { return 8 } 18 if nx_sr_role_is_valid(12) != 0 { return 9 } 19 20 // 3: succession phase enum validity 21 if nx_su_phase_is_valid(NX_SU_PHASE_PIONEER_0_5_YR) != 1 { return 10 } 22 if nx_su_phase_is_valid(NX_SU_PHASE_OLDGROWTH_100_PLUS) != 1 { return 11 } 23 if nx_su_phase_is_valid(-1) != 0 { return 12 } 24 if nx_su_phase_is_valid(5) != 0 { return 13 } 25 26 // 4: verdict enum validity 27 if nx_et_v_is_valid(NX_ET_V_DESIGN_OK) != 1 { return 14 } 28 if nx_et_v_is_valid(NX_ET_V_INVASIVE_FLAGGED) != 1 { return 15 } 29 if nx_et_v_is_valid(-1) != 0 { return 16 } 30 if nx_et_v_is_valid(4) != 0 { return 17 } 31 32 // 5: structural role predicate 33 if nx_sr_is_structural(NX_SR_CANOPY_DOMINANT) != 1 { return 18 } 34 if nx_sr_is_structural(NX_SR_UNDERSTORY_SHRUB) != 1 { return 19 } 35 if nx_sr_is_structural(NX_SR_GROUND_COVER) != 1 { return 20 } 36 if nx_sr_is_structural(NX_SR_RIPARIAN_BANK_STABILIZER) != 1 { return 21 } 37 if nx_sr_is_structural(NX_SR_NITROGEN_FIXER) != 0 { return 22 } 38 if nx_sr_is_structural(NX_SR_POLLINATOR_NECTAR) != 0 { return 23 } 39 40 // 6: provisioning role predicate 41 if nx_sr_is_provisioning(NX_SR_NITROGEN_FIXER) != 1 { return 24 } 42 if nx_sr_is_provisioning(NX_SR_POLLINATOR_NECTAR) != 1 { return 25 } 43 if nx_sr_is_provisioning(NX_SR_WILDLIFE_FOOD) != 1 { return 26 } 44 if nx_sr_is_provisioning(NX_SR_SOIL_FUNGI_PARTNER) != 1 { return 27 } 45 if nx_sr_is_provisioning(NX_SR_CANOPY_DOMINANT) != 0 { return 28 } 46 47 // 7: role-to-bit conversion (sanity-check a few) 48 if nx_sr_role_to_bit(NX_SR_CANOPY_DOMINANT) != NX_SR_BIT_CANOPY_DOM { return 29 } 49 if nx_sr_role_to_bit(NX_SR_NITROGEN_FIXER) != NX_SR_BIT_N_FIXER { return 30 } 50 if nx_sr_role_to_bit(NX_SR_INVASIVE_RISK_FLAG) != NX_SR_BIT_INVASIVE { return 31 } 51 if nx_sr_role_to_bit(99) != 0 { return 32 } 52 53 // 8: canonical required roles -- FOREST_MEADOW needs canopy+shrub+perennial+poll 54 let fm_req: nx_int = nx_et_canonical_required_roles(NX_ET_FOREST_MEADOW) 55 if (fm_req & NX_SR_BIT_CANOPY_DOM) == 0 { return 33 } 56 if (fm_req & NX_SR_BIT_SHRUB) == 0 { return 34 } 57 if (fm_req & NX_SR_BIT_PERENNIAL) == 0 { return 35 } 58 if (fm_req & NX_SR_BIT_POLL) == 0 { return 36 } 59 60 // 9: STRIPMINE_RECLAMATION emphasizes pioneer + N-fixer + ground 61 let sm_req: nx_int = nx_et_canonical_required_roles(NX_ET_STRIPMINE_RECLAMATION) 62 if (sm_req & NX_SR_BIT_CANOPY_PIO) == 0 { return 37 } 63 if (sm_req & NX_SR_BIT_N_FIXER) == 0 { return 38 } 64 if (sm_req & NX_SR_BIT_GROUND) == 0 { return 39 } 65 66 // 10: coverage gap -- propose nothing, gap = entire required 67 let no_propose: nx_int = 0 68 let gap_fm_empty: nx_int = nx_et_role_coverage_gap(NX_ET_FOREST_MEADOW, no_propose) 69 if gap_fm_empty != fm_req { return 40 } 70 71 // 11: coverage gap -- propose canopy only, missing shrub+perennial+poll 72 let propose_canopy: nx_int = NX_SR_BIT_CANOPY_DOM 73 let gap_fm_canopy: nx_int = nx_et_role_coverage_gap( 74 NX_ET_FOREST_MEADOW, propose_canopy) 75 if (gap_fm_canopy & NX_SR_BIT_CANOPY_DOM) != 0 { return 41 } // canopy covered 76 if (gap_fm_canopy & NX_SR_BIT_SHRUB) == 0 { return 42 } // shrub gap 77 if (gap_fm_canopy & NX_SR_BIT_POLL) == 0 { return 43 } // poll gap 78 79 // 12: coverage gap -- propose ALL required, gap = 0 80 let propose_full: nx_int = NX_SR_BIT_CANOPY_DOM | NX_SR_BIT_SHRUB | 81 NX_SR_BIT_PERENNIAL | NX_SR_BIT_POLL 82 let gap_full: nx_int = nx_et_role_coverage_gap(NX_ET_FOREST_MEADOW, propose_full) 83 if gap_full != 0 { return 44 } 84 85 // 13: classify -- full role coverage + pioneer phase covered = DESIGN_OK 86 let pioneer_only_phase: nx_int = 1 // bit 0 = PIONEER_0_5_YR 87 let v_ok: nx_int = nx_et_classify_design( 88 NX_ET_FOREST_MEADOW, propose_full, pioneer_only_phase) 89 if v_ok != NX_ET_V_DESIGN_OK { return 45 } 90 91 // 14: classify -- missing pollinator nectar -> MISSING_FUNCTIONAL_ROLE 92 let propose_no_poll: nx_int = NX_SR_BIT_CANOPY_DOM | NX_SR_BIT_SHRUB | 93 NX_SR_BIT_PERENNIAL 94 let v_gap: nx_int = nx_et_classify_design( 95 NX_ET_FOREST_MEADOW, propose_no_poll, pioneer_only_phase) 96 if v_gap != NX_ET_V_MISSING_FUNCTIONAL_ROLE { return 46 } 97 98 // 15: classify -- propose invasive species -> INVASIVE_FLAGGED (highest priority) 99 let propose_with_inv: nx_int = propose_full | NX_SR_BIT_INVASIVE 100 let v_inv: nx_int = nx_et_classify_design( 101 NX_ET_FOREST_MEADOW, propose_with_inv, pioneer_only_phase) 102 if v_inv != NX_ET_V_INVASIVE_FLAGGED { return 47 } 103 104 // 16: classify -- missing pioneer phase -> SUCCESSION_GAP 105 let no_pioneer_phase: nx_int = 2 // bit 1 = EARLY only; bit 0 missing 106 let v_succ: nx_int = nx_et_classify_design( 107 NX_ET_FOREST_MEADOW, propose_full, no_pioneer_phase) 108 if v_succ != NX_ET_V_SUCCESSION_GAP { return 48 } 109 110 // 17: classify -- invalid transition 111 let v_inv2: nx_int = nx_et_classify_design(99, propose_full, pioneer_only_phase) 112 if v_inv2 != NX_ET_V_INVALID { return 49 } 113 114 // 18: classify -- negative proposed roles 115 let v_inv3: nx_int = nx_et_classify_design( 116 NX_ET_FOREST_MEADOW, -1, pioneer_only_phase) 117 if v_inv3 != NX_ET_V_INVALID { return 50 } 118 119 // 19: classify -- negative phases 120 let v_inv4: nx_int = nx_et_classify_design( 121 NX_ET_FOREST_MEADOW, propose_full, -1) 122 if v_inv4 != NX_ET_V_INVALID { return 51 } 123 124 // 20: concerning predicate 125 if nx_et_v_is_concerning(NX_ET_V_DESIGN_OK) != 0 { return 52 } 126 if nx_et_v_is_concerning(NX_ET_V_MISSING_FUNCTIONAL_ROLE) != 1 { return 53 } 127 if nx_et_v_is_concerning(NX_ET_V_INVASIVE_FLAGGED) != 1 { return 54 } 128 if nx_et_v_is_concerning(NX_ET_V_SUCCESSION_GAP) != 1 { return 55 } 129 130 return 0 131}