omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / exercises / luhn / test.om
| 1 | note ---- test harness (appended after the solution by exercise.sh) ---- |
| 2 | text tok "ok " |
| 3 | text tnok "not ok " |
| 4 | text tsep " - " |
| 5 | text tnl "\n" |
| 6 | global tfails ulong 1 |
| 7 | global tnum ulong 1 |
| 8 | fn temit a view uchar * to void |
| 9 | o = ulong 0 |
| 10 | while lt o len a bound 4096 |
| 11 | k = write 1 a o sub len a o |
| 12 | if le k 0 |
| 13 | exit 2 |
| 14 | end |
| 15 | o = add o ulong k |
| 16 | end |
| 17 | end |
| 18 | fn temitu n ulong to void |
| 19 | d = new uchar 20 0 |
| 20 | i = ulong 20 |
| 21 | v = n |
| 22 | while true bound 20 |
| 23 | i = sub i 1 |
| 24 | put d i uchar add rem v 10 48 |
| 25 | v = div v 10 |
| 26 | if eq v 0 |
| 27 | break |
| 28 | end |
| 29 | end |
| 30 | temit part d i sub 20 i |
| 31 | end |
| 32 | note one TAP-style line per case; main returns the number of failed cases |
| 33 | fn tcheck c bool what view uchar * to void |
| 34 | put tnum 0 add get tnum 0 1 |
| 35 | if c |
| 36 | temit tok |
| 37 | else |
| 38 | temit tnok |
| 39 | put tfails 0 add get tfails 0 1 |
| 40 | end |
| 41 | temitu get tnum 0 |
| 42 | temit tsep |
| 43 | temit what |
| 44 | temit tnl |
| 45 | end |
| 46 | note cases: exercism/problem-specifications exercises/luhn/canonical-data.json at |
| 47 | note commit 650bebeb39ad40439175288042aece982b0a90a9 (2026-10-19), MIT licence, |
| 48 | note https://github.com/exercism/problem-specifications |
| 49 | note 22 cases kept, 0 skipped |
| 50 | text s0 "1" |
| 51 | text c1 "valid: single digit strings can not be valid" |
| 52 | text s2 "0" |
| 53 | text c3 "valid: a single zero is invalid" |
| 54 | text s4 "059" |
| 55 | text c5 "valid: a simple valid SIN that remains valid if reversed" |
| 56 | text s6 "59" |
| 57 | text c7 "valid: a simple valid SIN that becomes invalid if reversed" |
| 58 | text s8 "055 444 285" |
| 59 | text c9 "valid: a valid Canadian SIN" |
| 60 | text s10 "055 444 286" |
| 61 | text c11 "valid: invalid Canadian SIN" |
| 62 | text s12 "8273 1232 7352 0569" |
| 63 | text c13 "valid: invalid credit card" |
| 64 | text s14 "1 2345 6789 1234 5678 9012" |
| 65 | text c15 "valid: invalid long number with an even remainder" |
| 66 | text s16 "1 2345 6789 1234 5678 9013" |
| 67 | text c17 "valid: invalid long number with a remainder divisible by 5" |
| 68 | text s18 "095 245 88" |
| 69 | text c19 "valid: valid number with an even number of digits" |
| 70 | text s20 "234 567 891 234" |
| 71 | text c21 "valid: valid number with an odd number of spaces" |
| 72 | text s22 "059a" |
| 73 | text c23 "valid: valid strings with a non-digit added at the end become invalid" |
| 74 | text s24 "055-444-285" |
| 75 | text c25 "valid: valid strings with punctuation included become invalid" |
| 76 | text s26 "055# 444$ 285" |
| 77 | text c27 "valid: valid strings with symbols included become invalid" |
| 78 | text s28 " 0" |
| 79 | text c29 "valid: single zero with space is invalid" |
| 80 | text s30 "0000 0" |
| 81 | text c31 "valid: more than a single zero is valid" |
| 82 | text s32 "091" |
| 83 | text c33 "valid: input digit 9 is correctly converted to output digit 9" |
| 84 | text s34 "9999999999 9999999999 9999999999 9999999999" |
| 85 | text c35 "valid: very long input is valid" |
| 86 | text s36 "109" |
| 87 | text c37 "valid: valid luhn with an odd number of digits and non zero first digit" |
| 88 | text s38 "055b 444 285" |
| 89 | text c39 "valid: using ascii value for non-doubled non-digit isn't allowed" |
| 90 | text s40 ":9" |
| 91 | text c41 "valid: using ascii value for doubled non-digit isn't allowed" |
| 92 | text s42 "59%59" |
| 93 | text c43 "valid: non-numeric, non-space char in the middle with a sum that's divisible by 10 isn't allowed" |
| 94 | note canonical case 792a7082-feb7-48c7-b88b-bbfec160865e |
| 95 | fn tc0 to bool |
| 96 | ret eq valid s0 false |
| 97 | end |
| 98 | note canonical case 698a7924-64d4-4d89-8daa-32e1aadc271e |
| 99 | fn tc1 to bool |
| 100 | ret eq valid s2 false |
| 101 | end |
| 102 | note canonical case 73c2f62b-9b10-4c9f-9a04-83cee7367965 |
| 103 | fn tc2 to bool |
| 104 | ret eq valid s4 true |
| 105 | end |
| 106 | note canonical case 9369092e-b095-439f-948d-498bd076be11 |
| 107 | fn tc3 to bool |
| 108 | ret eq valid s6 true |
| 109 | end |
| 110 | note canonical case 8f9f2350-1faf-4008-ba84-85cbb93ffeca |
| 111 | fn tc4 to bool |
| 112 | ret eq valid s8 true |
| 113 | end |
| 114 | note canonical case 1cdcf269-6560-44fc-91f6-5819a7548737 |
| 115 | fn tc5 to bool |
| 116 | ret eq valid s10 false |
| 117 | end |
| 118 | note canonical case 656c48c1-34e8-4e60-9a5a-aad8a367810a |
| 119 | fn tc6 to bool |
| 120 | ret eq valid s12 false |
| 121 | end |
| 122 | note canonical case 20e67fad-2121-43ed-99a8-14b5b856adb9 |
| 123 | fn tc7 to bool |
| 124 | ret eq valid s14 false |
| 125 | end |
| 126 | note canonical case 7e7c9fc1-d994-457c-811e-d390d52fba5e |
| 127 | fn tc8 to bool |
| 128 | ret eq valid s16 false |
| 129 | end |
| 130 | note canonical case ad2a0c5f-84ed-4e5b-95da-6011d6f4f0aa |
| 131 | fn tc9 to bool |
| 132 | ret eq valid s18 true |
| 133 | end |
| 134 | note canonical case ef081c06-a41f-4761-8492-385e13c8202d |
| 135 | fn tc10 to bool |
| 136 | ret eq valid s20 true |
| 137 | end |
| 138 | note canonical case bef66f64-6100-4cbb-8f94-4c9713c5e5b2 |
| 139 | fn tc11 to bool |
| 140 | ret eq valid s22 false |
| 141 | end |
| 142 | note canonical case 2177e225-9ce7-40f6-b55d-fa420e62938e |
| 143 | fn tc12 to bool |
| 144 | ret eq valid s24 false |
| 145 | end |
| 146 | note canonical case ebf04f27-9698-45e1-9afe-7e0851d0fe8d |
| 147 | fn tc13 to bool |
| 148 | ret eq valid s26 false |
| 149 | end |
| 150 | note canonical case 08195c5e-ce7f-422c-a5eb-3e45fece68ba |
| 151 | fn tc14 to bool |
| 152 | ret eq valid s28 false |
| 153 | end |
| 154 | note canonical case 12e63a3c-f866-4a79-8c14-b359fc386091 |
| 155 | fn tc15 to bool |
| 156 | ret eq valid s30 true |
| 157 | end |
| 158 | note canonical case ab56fa80-5de8-4735-8a4a-14dae588663e |
| 159 | fn tc16 to bool |
| 160 | ret eq valid s32 true |
| 161 | end |
| 162 | note canonical case b9887ee8-8337-46c5-bc45-3bcab51bc36f |
| 163 | fn tc17 to bool |
| 164 | ret eq valid s34 true |
| 165 | end |
| 166 | note canonical case 8a7c0e24-85ea-4154-9cf1-c2db90eabc08 |
| 167 | fn tc18 to bool |
| 168 | ret eq valid s36 true |
| 169 | end |
| 170 | note canonical case 39a06a5a-5bad-4e0f-b215-b042d46209b1 |
| 171 | fn tc19 to bool |
| 172 | ret eq valid s38 false |
| 173 | end |
| 174 | note canonical case f94cf191-a62f-4868-bc72-7253114aa157 |
| 175 | fn tc20 to bool |
| 176 | ret eq valid s40 false |
| 177 | end |
| 178 | note canonical case 8b72ad26-c8be-49a2-b99c-bcc3bf631b33 |
| 179 | fn tc21 to bool |
| 180 | ret eq valid s42 false |
| 181 | end |
| 182 | fn main to int |
| 183 | tcheck tc0 c1 |
| 184 | tcheck tc1 c3 |
| 185 | tcheck tc2 c5 |
| 186 | tcheck tc3 c7 |
| 187 | tcheck tc4 c9 |
| 188 | tcheck tc5 c11 |
| 189 | tcheck tc6 c13 |
| 190 | tcheck tc7 c15 |
| 191 | tcheck tc8 c17 |
| 192 | tcheck tc9 c19 |
| 193 | tcheck tc10 c21 |
| 194 | tcheck tc11 c23 |
| 195 | tcheck tc12 c25 |
| 196 | tcheck tc13 c27 |
| 197 | tcheck tc14 c29 |
| 198 | tcheck tc15 c31 |
| 199 | tcheck tc16 c33 |
| 200 | tcheck tc17 c35 |
| 201 | tcheck tc18 c37 |
| 202 | tcheck tc19 c39 |
| 203 | tcheck tc20 c41 |
| 204 | tcheck tc21 c43 |
| 205 | ret int get tfails 0 |
| 206 | end |