code wiki / (root) / nx_seed_sort_test.nx

nx_seed_sort_test.nx source

↩ module page · 133 lines · 4197 B

1// nx_seed_sort_test.nx -- KAT for seed-pair sort by (r, q). 2// 3// Key end-to-end fixture matches the order produced by 4// nx_align_match in the G1.4 pipeline test. After sort, the seeds 5// should equal the hand-sorted arrays the G1.4 test fed manually. 6// 7// expect_exit: 0 8// 9// license_tier: ORIGINAL 10 11import "nx_syscalls.nx" 12import "nx_seed_sort.nx" 13 14func main() -> i64 { 15 16 let sq: *i64 = sys_mmap(128) as *i64 17 let sr: *i64 = sys_mmap(128) as *i64 18 19 // ============================================================ 20 // Section A -- n=0 and n=1 are no-ops. 21 // ============================================================ 22 23 if sort_seeds_by_r(sq, sr, 0) != 0 { return 1 } 24 sq[0] = 7; sr[0] = 11 25 if sort_seeds_by_r(sq, sr, 1) != 0 { return 2 } 26 if sq[0] != 7 { return 3 } 27 if sr[0] != 11 { return 4 } 28 29 // ============================================================ 30 // Section B -- already-sorted input is preserved. 31 // ============================================================ 32 33 sq[0]=0; sr[0]=0 34 sq[1]=4; sr[1]=0 35 sq[2]=1; sr[2]=1 36 sq[3]=4; sr[3]=4 37 sort_seeds_by_r(sq, sr, 4) 38 if sq[0]!=0 { return 10 } 39 if sr[0]!=0 { return 11 } 40 if sq[1]!=4 { return 12 } 41 if sr[1]!=0 { return 13 } 42 if sq[2]!=1 { return 14 } 43 if sr[2]!=1 { return 15 } 44 if sq[3]!=4 { return 16 } 45 if sr[3]!=4 { return 17 } 46 47 // ============================================================ 48 // Section C -- reverse-r becomes ascending-r. 49 // input: (q=3,r=9) (q=2,r=5) (q=1,r=2) 50 // sorted: (q=1,r=2) (q=2,r=5) (q=3,r=9) 51 // ============================================================ 52 53 sq[0]=3; sr[0]=9 54 sq[1]=2; sr[1]=5 55 sq[2]=1; sr[2]=2 56 sort_seeds_by_r(sq, sr, 3) 57 if sq[0]!=1 { return 20 } 58 if sr[0]!=2 { return 21 } 59 if sq[1]!=2 { return 22 } 60 if sr[1]!=5 { return 23 } 61 if sq[2]!=3 { return 24 } 62 if sr[2]!=9 { return 25 } 63 64 // ============================================================ 65 // Section D -- tie on r is broken by q ascending. 66 // input: (q=7,r=3) (q=2,r=3) (q=5,r=3) 67 // sorted: (q=2,r=3) (q=5,r=3) (q=7,r=3) 68 // ============================================================ 69 70 sq[0]=7; sr[0]=3 71 sq[1]=2; sr[1]=3 72 sq[2]=5; sr[2]=3 73 sort_seeds_by_r(sq, sr, 3) 74 if sq[0]!=2 { return 30 } 75 if sq[1]!=5 { return 31 } 76 if sq[2]!=7 { return 32 } 77 // all r still 3 78 if sr[0]!=3 { return 33 } 79 if sr[1]!=3 { return 34 } 80 if sr[2]!=3 { return 35 } 81 82 // ============================================================ 83 // Section E -- end-to-end fixture: the EXACT 8 seed pairs that 84 // nx_align_match produced in the G1.4 pipeline KAT, fed in the 85 // matcher's natural (outer-q, inner-r) order. After sort the 86 // arrays must equal what the G1.4 test hand-typed as "sorted". 87 // 88 // Matcher output order (outer-q, inner-r): 89 // (0,0) (0,4) (0,8) (1,1) (1,5) (4,0) (4,4) (4,8) 90 // 91 // Expected after sort by (r, q): 92 // (0,0) (4,0) (1,1) (0,4) (4,4) (1,5) (0,8) (4,8) 93 // ============================================================ 94 95 sq[0]=0; sr[0]=0 96 sq[1]=0; sr[1]=4 97 sq[2]=0; sr[2]=8 98 sq[3]=1; sr[3]=1 99 sq[4]=1; sr[4]=5 100 sq[5]=4; sr[5]=0 101 sq[6]=4; sr[6]=4 102 sq[7]=4; sr[7]=8 103 sort_seeds_by_r(sq, sr, 8) 104 105 if sq[0]!=0 { return 40 } 106 if sr[0]!=0 { return 41 } 107 if sq[1]!=4 { return 42 } 108 if sr[1]!=0 { return 43 } 109 if sq[2]!=1 { return 44 } 110 if sr[2]!=1 { return 45 } 111 if sq[3]!=0 { return 46 } 112 if sr[3]!=4 { return 47 } 113 if sq[4]!=4 { return 48 } 114 if sr[4]!=4 { return 49 } 115 if sq[5]!=1 { return 50 } 116 if sr[5]!=5 { return 51 } 117 if sq[6]!=0 { return 52 } 118 if sr[6]!=8 { return 53 } 119 if sq[7]!=4 { return 54 } 120 if sr[7]!=8 { return 55 } 121 122 // ============================================================ 123 // Section F -- sort is idempotent: sorting a sorted array is a no-op. 124 // ============================================================ 125 126 sort_seeds_by_r(sq, sr, 8) 127 if sq[0]!=0 { return 60 } 128 if sr[0]!=0 { return 61 } 129 if sq[7]!=4 { return 62 } 130 if sr[7]!=8 { return 63 } 131 132 return 0 133}