code wiki / (root) / nx_corolla_test.nx

nx_corolla_test.nx source

↩ module page · 119 lines · 6104 B

1// nx_corolla_test.nx -- smoke for nx_corolla. 2 3import "nx_syscalls.nx" 4import "nx_corolla.nx" 5 6func main() -> i64 { 7 let now: nx_size = 1000000 8 9 // 1: enum validity 10 if nx_co_axis_is_valid(NX_CO_AXIS_JOY) != 1 { return 1 } 11 if nx_co_axis_is_valid(NX_CO_AXIS_PEACE) != 1 { return 2 } 12 if nx_co_axis_is_valid(-1) != 0 { return 3 } 13 if nx_co_axis_is_valid(8) != 0 { return 4 } 14 if NX_CO_AXIS_N != 8 { return 5 } 15 16 if nx_co_src_is_valid(NX_CO_SRC_AUTOMATED_PROXY) != 1 { return 6 } 17 if nx_co_src_is_valid(NX_CO_SRC_COMMUNITY) != 1 { return 7 } 18 if nx_co_src_is_valid(-1) != 0 { return 8 } 19 if nx_co_src_is_valid(5) != 0 { return 9 } 20 21 if nx_co_v_is_valid(NX_CO_V_OK) != 1 { return 10 } 22 if nx_co_v_is_valid(NX_CO_V_DIVERGENT) != 1 { return 11 } 23 if nx_co_v_is_valid(NX_CO_V_N) != 0 { return 12 } 24 25 // 2: source human classification 26 if nx_co_src_is_human(NX_CO_SRC_AUTOMATED_PROXY) != 0 { return 13 } 27 if nx_co_src_is_human(NX_CO_SRC_OPERATOR) != 1 { return 14 } 28 if nx_co_src_is_human(NX_CO_SRC_FAMILY) != 1 { return 15 } 29 if nx_co_src_is_human(NX_CO_SRC_TRUSTED_REVIEWER) != 1 { return 16 } 30 if nx_co_src_is_human(NX_CO_SRC_COMMUNITY) != 1 { return 17 } 31 32 // 3: construction 33 let c: *NxCorolla = nx_co_new(42, 16, 700, 2, now) 34 if c.target_id != 42 { return 18 } 35 if c.capacity != 16 { return 19 } 36 if c.threshold_q10 != 700 { return 20 } 37 if c.minimum_human_readings != 2 { return 21 } 38 if c.n_readings != 0 { return 22 } 39 40 // 4: invalid construction 41 if nx_co_new(1, 0, 700, 1, now) != (0 as *NxCorolla) { return 23 } 42 if nx_co_new(1, 4, -1, 1, now) != (0 as *NxCorolla) { return 24 } 43 if nx_co_new(1, 4, 1025, 1, now) != (0 as *NxCorolla) { return 25 } 44 if nx_co_new(1, 4, 700, -1, now) != (0 as *NxCorolla) { return 26 } 45 46 // 5: THIN_EVIDENCE -- only automated readings, no humans 47 nx_co_record(c, NX_CO_AXIS_JOY, 900, NX_CO_SRC_AUTOMATED_PROXY, 1, 60000000, now) 48 nx_co_record(c, NX_CO_AXIS_JOY, 920, NX_CO_SRC_AUTOMATED_PROXY, 1, 60000000, now) 49 if nx_co_classify(c, NX_CO_AXIS_JOY) != NX_CO_V_THIN_EVIDENCE { return 27 } 50 51 // 6: still THIN with one human reading (minimum is 2) 52 nx_co_record(c, NX_CO_AXIS_JOY, 800, NX_CO_SRC_OPERATOR, 100, 120000000, now) 53 if nx_co_classify(c, NX_CO_AXIS_JOY) != NX_CO_V_THIN_EVIDENCE { return 28 } 54 55 // 7: with two humans both above threshold -- OK 56 nx_co_record(c, NX_CO_AXIS_JOY, 820, NX_CO_SRC_FAMILY, 101, 120000000, now) 57 let v_ok: nx_int = nx_co_classify(c, NX_CO_AXIS_JOY) 58 if v_ok != NX_CO_V_OK { return 29 } 59 60 // 8: BELOW_THRESHOLD -- separate corolla, humans rate low 61 let c2: *NxCorolla = nx_co_new(2, 8, 700, 2, now) 62 nx_co_record(c2, NX_CO_AXIS_JOY, 400, NX_CO_SRC_OPERATOR, 1, 60000000, now) 63 nx_co_record(c2, NX_CO_AXIS_JOY, 500, NX_CO_SRC_FAMILY, 2, 60000000, now) 64 if nx_co_classify(c2, NX_CO_AXIS_JOY) != NX_CO_V_BELOW_THRESHOLD { return 30 } 65 66 // 9: DIVERGENT -- automated says 950, humans say 720 (delta > 200, 67 // human just above threshold within +100 band) 68 // Wait: threshold=700, +100=800. human_mean=720 < 800 ok. 69 // auto two readings at 950, humans two at 720 -> overall mean 70 // = (950+950+720+720)/4 = 835. delta = 835-720 = 115 < 200. 71 // Need bigger spread: auto 1000, humans 700. 72 // overall (1000+1000+700+700)/4 = 850. delta = 150 still < 200. 73 // Try auto 1024, humans 700. overall (1024+1024+700+700)/4 = 862. 74 // delta = 162. still < 200. 75 // To force DIVERGENT: more auto readings vs few human. 76 // 1024 x3 + 750 x2 = (3072+1500)/5 = 914. human_mean=750. 77 // delta = 164. still no. 78 // 1024 x5 + 750 x2 = (5120+1500)/7 = 945. delta = 195. close. 79 // 1024 x6 + 750 x2 = (6144+1500)/8 = 955. delta = 205. >=200 OK. 80 // But human_mean (750) must be < threshold+100 = 800. 750<800 ok. 81 // Threshold check first: 750 < 700? no, so doesn't BELOW. 82 // So DIVERGENT will fire. 83 let c3: *NxCorolla = nx_co_new(3, 16, 700, 2, now) 84 nx_co_record(c3, NX_CO_AXIS_BEAUTY, 1024, NX_CO_SRC_AUTOMATED_PROXY, 1, 1000, now) 85 nx_co_record(c3, NX_CO_AXIS_BEAUTY, 1024, NX_CO_SRC_AUTOMATED_PROXY, 1, 1000, now) 86 nx_co_record(c3, NX_CO_AXIS_BEAUTY, 1024, NX_CO_SRC_AUTOMATED_PROXY, 1, 1000, now) 87 nx_co_record(c3, NX_CO_AXIS_BEAUTY, 1024, NX_CO_SRC_AUTOMATED_PROXY, 1, 1000, now) 88 nx_co_record(c3, NX_CO_AXIS_BEAUTY, 1024, NX_CO_SRC_AUTOMATED_PROXY, 1, 1000, now) 89 nx_co_record(c3, NX_CO_AXIS_BEAUTY, 1024, NX_CO_SRC_AUTOMATED_PROXY, 1, 1000, now) 90 nx_co_record(c3, NX_CO_AXIS_BEAUTY, 750, NX_CO_SRC_OPERATOR, 100, 120000000, now) 91 nx_co_record(c3, NX_CO_AXIS_BEAUTY, 750, NX_CO_SRC_FAMILY, 101, 120000000, now) 92 if nx_co_classify(c3, NX_CO_AXIS_BEAUTY) != NX_CO_V_DIVERGENT { return 31 } 93 94 // 10: aggregations 95 if nx_co_mean_q10_by_axis(c3, NX_CO_AXIS_BEAUTY) != 955 { return 32 } 96 if nx_co_mean_q10_human_only(c3, NX_CO_AXIS_BEAUTY) != 750 { return 33 } 97 if nx_co_human_reading_count(c3) != 2 { return 34 } 98 99 // 11: invalid axis 100 if nx_co_classify(c, 99) != NX_CO_V_INVALID { return 35 } 101 if nx_co_record(c, 99, 500, NX_CO_SRC_OPERATOR, 1, 1000, now) != NX_CO_V_INVALID { return 36 } 102 103 // 12: invalid score 104 if nx_co_record(c, NX_CO_AXIS_JOY, -1, NX_CO_SRC_OPERATOR, 1, 1000, now) != NX_CO_V_INVALID { return 37 } 105 if nx_co_record(c, NX_CO_AXIS_JOY, 1025, NX_CO_SRC_OPERATOR, 1, 1000, now) != NX_CO_V_INVALID { return 38 } 106 107 // 13: invalid source 108 if nx_co_record(c, NX_CO_AXIS_JOY, 500, 99, 1, 1000, now) != NX_CO_V_INVALID { return 39 } 109 110 // 14: null guard 111 let null_c: *NxCorolla = (0 as i64) as *NxCorolla 112 if nx_co_record(null_c, NX_CO_AXIS_JOY, 500, NX_CO_SRC_OPERATOR, 1, 1000, now) != NX_CO_V_NULL { return 40 } 113 if nx_co_classify(null_c, NX_CO_AXIS_JOY) != NX_CO_V_NULL { return 41 } 114 if nx_co_mean_q10_by_axis(null_c, NX_CO_AXIS_JOY) != 0 { return 42 } 115 if nx_co_mean_q10_human_only(null_c, NX_CO_AXIS_JOY) != 0 { return 43 } 116 if nx_co_human_reading_count(null_c) != 0 { return 44 } 117 118 return 0 119}