interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / exercises / all-your-base / test.om

370 lines · 6979 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/all-your-base/canonical-data.json at
47note commit 650bebeb39ad40439175288042aece982b0a90a9 (2026-10-19), MIT licence,
48note https://github.com/exercism/problem-specifications
49note 21 cases kept, 0 skipped
50fn tleq a view long * b view long * to bool
51if ne len a len b
52ret false
53end
54for i ulong len a
55if ne get a i get b i
56ret false
57end
58end
59ret true
60end
61text c0 "rebase: single bit one to decimal"
62text c1 "rebase: binary to single decimal"
63text c2 "rebase: single decimal to binary"
64text c3 "rebase: binary to multiple decimal"
65text c4 "rebase: decimal to binary"
66text c5 "rebase: trinary to hexadecimal"
67text c6 "rebase: hexadecimal to trinary"
68text c7 "rebase: 15-bit integer"
69text c8 "rebase: empty list"
70text c9 "rebase: single zero"
71text c10 "rebase: multiple zeros"
72text c11 "rebase: leading zeros"
73text c12 "rebase: input base is one"
74text c13 "rebase: input base is zero"
75text c14 "rebase: input base is negative"
76text c15 "rebase: negative digit"
77text c16 "rebase: invalid positive digit"
78text c17 "rebase: output base is one"
79text c18 "rebase: output base is zero"
80text c19 "rebase: output base is negative"
81text c20 "rebase: both bases are negative"
82note canonical case 5ce422f9-7a4b-4f44-ad29-49c67cb32d2c
83fn tc0 to bool
84a0 = new long 1 0
85put a0 0 1
86o = new long 256 0
87n = rebase 2 a0 10 o
88if lt n 0
89ret false
90end
91a1 = new long 1 0
92put a1 0 1
93ret tleq part o 0 ulong n a1
94end
95note canonical case 0cc3fea8-bb79-46ac-a2ab-5a2c93051033
96fn tc1 to bool
97a0 = new long 3 0
98put a0 0 1
99put a0 1 0
100put a0 2 1
101o = new long 256 0
102n = rebase 2 a0 10 o
103if lt n 0
104ret false
105end
106a1 = new long 1 0
107put a1 0 5
108ret tleq part o 0 ulong n a1
109end
110note canonical case f12db0f9-0d3d-42c2-b3ba-e38cb375a2b8
111fn tc2 to bool
112a0 = new long 1 0
113put a0 0 5
114o = new long 256 0
115n = rebase 10 a0 2 o
116if lt n 0
117ret false
118end
119a1 = new long 3 0
120put a1 0 1
121put a1 1 0
122put a1 2 1
123ret tleq part o 0 ulong n a1
124end
125note canonical case 2c45cf54-6da3-4748-9733-5a3c765d925b
126fn tc3 to bool
127a0 = new long 6 0
128put a0 0 1
129put a0 1 0
130put a0 2 1
131put a0 3 0
132put a0 4 1
133put a0 5 0
134o = new long 256 0
135n = rebase 2 a0 10 o
136if lt n 0
137ret false
138end
139a1 = new long 2 0
140put a1 0 4
141put a1 1 2
142ret tleq part o 0 ulong n a1
143end
144note canonical case 65ddb8b4-8899-4fcc-8618-181b2cf0002d
145fn tc4 to bool
146a0 = new long 2 0
147put a0 0 4
148put a0 1 2
149o = new long 256 0
150n = rebase 10 a0 2 o
151if lt n 0
152ret false
153end
154a1 = new long 6 0
155put a1 0 1
156put a1 1 0
157put a1 2 1
158put a1 3 0
159put a1 4 1
160put a1 5 0
161ret tleq part o 0 ulong n a1
162end
163note canonical case 8d418419-02a7-4824-8b7a-352d33c6987e
164fn tc5 to bool
165a0 = new long 4 0
166put a0 0 1
167put a0 1 1
168put a0 2 2
169put a0 3 0
170o = new long 256 0
171n = rebase 3 a0 16 o
172if lt n 0
173ret false
174end
175a1 = new long 2 0
176put a1 0 2
177put a1 1 10
178ret tleq part o 0 ulong n a1
179end
180note canonical case d3901c80-8190-41b9-bd86-38d988efa956
181fn tc6 to bool
182a0 = new long 2 0
183put a0 0 2
184put a0 1 10
185o = new long 256 0
186n = rebase 16 a0 3 o
187if lt n 0
188ret false
189end
190a1 = new long 4 0
191put a1 0 1
192put a1 1 1
193put a1 2 2
194put a1 3 0
195ret tleq part o 0 ulong n a1
196end
197note canonical case 5d42f85e-21ad-41bd-b9be-a3e8e4258bbf
198fn tc7 to bool
199a0 = new long 3 0
200put a0 0 3
201put a0 1 46
202put a0 2 60
203o = new long 256 0
204n = rebase 97 a0 73 o
205if lt n 0
206ret false
207end
208a1 = new long 3 0
209put a1 0 6
210put a1 1 10
211put a1 2 45
212ret tleq part o 0 ulong n a1
213end
214note canonical case d68788f7-66dd-43f8-a543-f15b6d233f83
215fn tc8 to bool
216a0 = new long 1 0
217o = new long 256 0
218n = rebase 2 part a0 0 0 10 o
219if lt n 0
220ret false
221end
222a1 = new long 1 0
223put a1 0 0
224ret tleq part o 0 ulong n a1
225end
226note canonical case 5e27e8da-5862-4c5f-b2a9-26c0382b6be7
227fn tc9 to bool
228a0 = new long 1 0
229put a0 0 0
230o = new long 256 0
231n = rebase 10 a0 2 o
232if lt n 0
233ret false
234end
235a1 = new long 1 0
236put a1 0 0
237ret tleq part o 0 ulong n a1
238end
239note canonical case 2e1c2573-77e4-4b9c-8517-6c56c5bcfdf2
240fn tc10 to bool
241a0 = new long 3 0
242put a0 0 0
243put a0 1 0
244put a0 2 0
245o = new long 256 0
246n = rebase 10 a0 2 o
247if lt n 0
248ret false
249end
250a1 = new long 1 0
251put a1 0 0
252ret tleq part o 0 ulong n a1
253end
254note canonical case 3530cd9f-8d6d-43f5-bc6e-b30b1db9629b
255fn tc11 to bool
256a0 = new long 3 0
257put a0 0 0
258put a0 1 6
259put a0 2 0
260o = new long 256 0
261n = rebase 7 a0 10 o
262if lt n 0
263ret false
264end
265a1 = new long 2 0
266put a1 0 4
267put a1 1 2
268ret tleq part o 0 ulong n a1
269end
270note canonical case a6b476a1-1901-4f2a-92c4-4d91917ae023
271fn tc12 to bool
272a0 = new long 1 0
273put a0 0 0
274o = new long 256 0
275ret eq rebase 1 a0 10 o -1
276end
277note canonical case e21a693a-7a69-450b-b393-27415c26a016
278fn tc13 to bool
279a0 = new long 1 0
280o = new long 256 0
281ret eq rebase 0 part a0 0 0 10 o -1
282end
283note canonical case 54a23be5-d99e-41cc-88e0-a650ffe5fcc2
284fn tc14 to bool
285a0 = new long 1 0
286put a0 0 1
287o = new long 256 0
288ret eq rebase -2 a0 10 o -1
289end
290note canonical case 9eccf60c-dcc9-407b-95d8-c37b8be56bb6
291fn tc15 to bool
292a0 = new long 6 0
293put a0 0 1
294put a0 1 -1
295put a0 2 1
296put a0 3 0
297put a0 4 1
298put a0 5 0
299o = new long 256 0
300ret eq rebase 2 a0 10 o -2
301end
302note canonical case 232fa4a5-e761-4939-ba0c-ed046cd0676a
303fn tc16 to bool
304a0 = new long 6 0
305put a0 0 1
306put a0 1 2
307put a0 2 1
308put a0 3 0
309put a0 4 1
310put a0 5 0
311o = new long 256 0
312ret eq rebase 2 a0 10 o -2
313end
314note canonical case 14238f95-45da-41dc-95ce-18f860b30ad3
315fn tc17 to bool
316a0 = new long 6 0
317put a0 0 1
318put a0 1 0
319put a0 2 1
320put a0 3 0
321put a0 4 1
322put a0 5 0
323o = new long 256 0
324ret eq rebase 2 a0 1 o -3
325end
326note canonical case 73dac367-da5c-4a37-95fe-c87fad0a4047
327fn tc18 to bool
328a0 = new long 1 0
329put a0 0 7
330o = new long 256 0
331ret eq rebase 10 a0 0 o -3
332end
333note canonical case 13f81f42-ff53-4e24-89d9-37603a48ebd9
334fn tc19 to bool
335a0 = new long 1 0
336put a0 0 1
337o = new long 256 0
338ret eq rebase 2 a0 -7 o -3
339end
340note canonical case 0e6c895d-8a5d-4868-a345-309d094cfe8d
341fn tc20 to bool
342a0 = new long 1 0
343put a0 0 1
344o = new long 256 0
345ret eq rebase -2 a0 -7 o -1
346end
347fn main to int
348tcheck tc0 c0
349tcheck tc1 c1
350tcheck tc2 c2
351tcheck tc3 c3
352tcheck tc4 c4
353tcheck tc5 c5
354tcheck tc6 c6
355tcheck tc7 c7
356tcheck tc8 c8
357tcheck tc9 c9
358tcheck tc10 c10
359tcheck tc11 c11
360tcheck tc12 c12
361tcheck tc13 c13
362tcheck tc14 c14
363tcheck tc15 c15
364tcheck tc16 c16
365tcheck tc17 c17
366tcheck tc18 c18
367tcheck tc19 c19
368tcheck tc20 c20
369ret int get tfails 0
370end