interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / exercises / luhn / test.om

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