interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / exercises / change / test.om

307 lines · 5834 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/change/canonical-data.json at
47note commit 650bebeb39ad40439175288042aece982b0a90a9 (2026-10-19), MIT licence,
48note https://github.com/exercism/problem-specifications
49note 13 cases kept, 0 skipped
50fn tueq a view ulong * b view ulong * 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 "findFewestCoins: change for 1 cent"
62text c1 "findFewestCoins: single coin change"
63text c2 "findFewestCoins: multiple coin change"
64text c3 "findFewestCoins: change with Lilliputian Coins"
65text c4 "findFewestCoins: change with Lower Elbonia Coins"
66text c5 "findFewestCoins: large target values"
67text c6 "findFewestCoins: possible change without unit coins available"
68text c7 "findFewestCoins: another possible change without unit coins available"
69text c8 "findFewestCoins: a greedy approach is not optimal"
70text c9 "findFewestCoins: no coins make 0 change"
71text c10 "findFewestCoins: error testing for change smaller than the smallest of coins"
72text c11 "findFewestCoins: error if no combination can add up to target"
73text c12 "findFewestCoins: cannot find negative change values"
74note canonical case d0ebd0e1-9d27-4609-a654-df5c0ba1d83a
75fn tc0 to bool
76a0 = new ulong 4 0
77put a0 0 1
78put a0 1 5
79put a0 2 10
80put a0 3 25
81o = new ulong 256 0
82n = findfewestcoins a0 1 o
83if lt n 0
84ret false
85end
86a1 = new ulong 1 0
87put a1 0 1
88ret tueq part o 0 ulong n a1
89end
90note canonical case 36887bea-7f92-4a9c-b0cc-c0e886b3ecc8
91fn tc1 to bool
92a0 = new ulong 5 0
93put a0 0 1
94put a0 1 5
95put a0 2 10
96put a0 3 25
97put a0 4 100
98o = new ulong 256 0
99n = findfewestcoins a0 25 o
100if lt n 0
101ret false
102end
103a1 = new ulong 1 0
104put a1 0 25
105ret tueq part o 0 ulong n a1
106end
107note canonical case cef21ccc-0811-4e6e-af44-f011e7eab6c6
108fn tc2 to bool
109a0 = new ulong 5 0
110put a0 0 1
111put a0 1 5
112put a0 2 10
113put a0 3 25
114put a0 4 100
115o = new ulong 256 0
116n = findfewestcoins a0 15 o
117if lt n 0
118ret false
119end
120a1 = new ulong 2 0
121put a1 0 5
122put a1 1 10
123ret tueq part o 0 ulong n a1
124end
125note canonical case d60952bc-0c1a-4571-bf0c-41be72690cb3
126fn tc3 to bool
127a0 = new ulong 5 0
128put a0 0 1
129put a0 1 4
130put a0 2 15
131put a0 3 20
132put a0 4 50
133o = new ulong 256 0
134n = findfewestcoins a0 23 o
135if lt n 0
136ret false
137end
138a1 = new ulong 3 0
139put a1 0 4
140put a1 1 4
141put a1 2 15
142ret tueq part o 0 ulong n a1
143end
144note canonical case 408390b9-fafa-4bb9-b608-ffe6036edb6c
145fn tc4 to bool
146a0 = new ulong 5 0
147put a0 0 1
148put a0 1 5
149put a0 2 10
150put a0 3 21
151put a0 4 25
152o = new ulong 256 0
153n = findfewestcoins a0 63 o
154if lt n 0
155ret false
156end
157a1 = new ulong 3 0
158put a1 0 21
159put a1 1 21
160put a1 2 21
161ret tueq part o 0 ulong n a1
162end
163note canonical case 7421a4cb-1c48-4bf9-99c7-7f049689132f
164fn tc5 to bool
165a0 = new ulong 7 0
166put a0 0 1
167put a0 1 2
168put a0 2 5
169put a0 3 10
170put a0 4 20
171put a0 5 50
172put a0 6 100
173o = new ulong 256 0
174n = findfewestcoins a0 999 o
175if lt n 0
176ret false
177end
178a1 = new ulong 15 0
179put a1 0 2
180put a1 1 2
181put a1 2 5
182put a1 3 20
183put a1 4 20
184put a1 5 50
185put a1 6 100
186put a1 7 100
187put a1 8 100
188put a1 9 100
189put a1 10 100
190put a1 11 100
191put a1 12 100
192put a1 13 100
193put a1 14 100
194ret tueq part o 0 ulong n a1
195end
196note canonical case f79d2e9b-0ae3-4d6a-bb58-dc978b0dba28
197fn tc6 to bool
198a0 = new ulong 5 0
199put a0 0 2
200put a0 1 5
201put a0 2 10
202put a0 3 20
203put a0 4 50
204o = new ulong 256 0
205n = findfewestcoins a0 21 o
206if lt n 0
207ret false
208end
209a1 = new ulong 5 0
210put a1 0 2
211put a1 1 2
212put a1 2 2
213put a1 3 5
214put a1 4 10
215ret tueq part o 0 ulong n a1
216end
217note canonical case 9a166411-d35d-4f7f-a007-6724ac266178
218fn tc7 to bool
219a0 = new ulong 2 0
220put a0 0 4
221put a0 1 5
222o = new ulong 256 0
223n = findfewestcoins a0 27 o
224if lt n 0
225ret false
226end
227a1 = new ulong 6 0
228put a1 0 4
229put a1 1 4
230put a1 2 4
231put a1 3 5
232put a1 4 5
233put a1 5 5
234ret tueq part o 0 ulong n a1
235end
236note canonical case ce0f80d5-51c3-469d-818c-3e69dbd25f75
237fn tc8 to bool
238a0 = new ulong 3 0
239put a0 0 1
240put a0 1 10
241put a0 2 11
242o = new ulong 256 0
243n = findfewestcoins a0 20 o
244if lt n 0
245ret false
246end
247a1 = new ulong 2 0
248put a1 0 10
249put a1 1 10
250ret tueq part o 0 ulong n a1
251end
252note canonical case bbbcc154-e9e9-4209-a4db-dd6d81ec26bb
253fn tc9 to bool
254a0 = new ulong 5 0
255put a0 0 1
256put a0 1 5
257put a0 2 10
258put a0 3 21
259put a0 4 25
260o = new ulong 256 0
261n = findfewestcoins a0 0 o
262if lt n 0
263ret false
264end
265ret eq ulong n 0
266end
267note canonical case c8b81d5a-49bd-4b61-af73-8ee5383a2ce1
268fn tc10 to bool
269a0 = new ulong 2 0
270put a0 0 5
271put a0 1 10
272o = new ulong 256 0
273ret eq findfewestcoins a0 3 o -1
274end
275note canonical case 3c43e3e4-63f9-46ac-9476-a67516e98f68
276fn tc11 to bool
277a0 = new ulong 2 0
278put a0 0 5
279put a0 1 10
280o = new ulong 256 0
281ret eq findfewestcoins a0 94 o -1
282end
283note canonical case 8fe1f076-9b2d-4f44-89fe-8a6ccd63c8f3
284fn tc12 to bool
285a0 = new ulong 3 0
286put a0 0 1
287put a0 1 2
288put a0 2 5
289o = new ulong 256 0
290ret eq findfewestcoins a0 -5 o -2
291end
292fn main to int
293tcheck tc0 c0
294tcheck tc1 c1
295tcheck tc2 c2
296tcheck tc3 c3
297tcheck tc4 c4
298tcheck tc5 c5
299tcheck tc6 c6
300tcheck tc7 c7
301tcheck tc8 c8
302tcheck tc9 c9
303tcheck tc10 c10
304tcheck tc11 c11
305tcheck tc12 c12
306ret int get tfails 0
307end