interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / exercises / prime-factors / test.om

198 lines · 4055 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/prime-factors/canonical-data.json at
47note commit 650bebeb39ad40439175288042aece982b0a90a9 (2026-10-19), MIT licence,
48note https://github.com/exercism/problem-specifications
49note 12 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 "factors: no factors"
62text c1 "factors: prime number"
63text c2 "factors: another prime number"
64text c3 "factors: square of a prime"
65text c4 "factors: product of first prime"
66text c5 "factors: cube of a prime"
67text c6 "factors: product of second prime"
68text c7 "factors: product of third prime"
69text c8 "factors: product of first and second prime"
70text c9 "factors: product of primes and non-primes"
71text c10 "factors: product of primes"
72text c11 "factors: factors include a large prime"
73note canonical case 924fc966-a8f5-4288-82f2-6b9224819ccd
74fn tc0 to bool
75o = new ulong 256 0
76n = factors 1 o
77ret eq n 0
78end
79note canonical case 17e30670-b105-4305-af53-ddde182cb6ad
80fn tc1 to bool
81o = new ulong 256 0
82n = factors 2 o
83a0 = new ulong 1 0
84put a0 0 2
85ret tueq part o 0 n a0
86end
87note canonical case 238d57c8-4c12-42ef-af34-ae4929f94789
88fn tc2 to bool
89o = new ulong 256 0
90n = factors 3 o
91a0 = new ulong 1 0
92put a0 0 3
93ret tueq part o 0 n a0
94end
95note canonical case f59b8350-a180-495a-8fb1-1712fbee1158
96fn tc3 to bool
97o = new ulong 256 0
98n = factors 9 o
99a0 = new ulong 2 0
100put a0 0 3
101put a0 1 3
102ret tueq part o 0 n a0
103end
104note canonical case 756949d3-3158-4e3d-91f2-c4f9f043ee70
105fn tc4 to bool
106o = new ulong 256 0
107n = factors 4 o
108a0 = new ulong 2 0
109put a0 0 2
110put a0 1 2
111ret tueq part o 0 n a0
112end
113note canonical case bc8c113f-9580-4516-8669-c5fc29512ceb
114fn tc5 to bool
115o = new ulong 256 0
116n = factors 8 o
117a0 = new ulong 3 0
118put a0 0 2
119put a0 1 2
120put a0 2 2
121ret tueq part o 0 n a0
122end
123note canonical case 7d6a3300-a4cb-4065-bd33-0ced1de6cb44
124fn tc6 to bool
125o = new ulong 256 0
126n = factors 27 o
127a0 = new ulong 3 0
128put a0 0 3
129put a0 1 3
130put a0 2 3
131ret tueq part o 0 n a0
132end
133note canonical case 073ac0b2-c915-4362-929d-fc45f7b9a9e4
134fn tc7 to bool
135o = new ulong 256 0
136n = factors 625 o
137a0 = new ulong 4 0
138put a0 0 5
139put a0 1 5
140put a0 2 5
141put a0 3 5
142ret tueq part o 0 n a0
143end
144note canonical case 6e0e4912-7fb6-47f3-a9ad-dbcd79340c75
145fn tc8 to bool
146o = new ulong 256 0
147n = factors 6 o
148a0 = new ulong 2 0
149put a0 0 2
150put a0 1 3
151ret tueq part o 0 n a0
152end
153note canonical case 00485cd3-a3fe-4fbe-a64a-a4308fc1f870
154fn tc9 to bool
155o = new ulong 256 0
156n = factors 12 o
157a0 = new ulong 3 0
158put a0 0 2
159put a0 1 2
160put a0 2 3
161ret tueq part o 0 n a0
162end
163note canonical case 02251d54-3ca1-4a9b-85e1-b38f4b0ccb91
164fn tc10 to bool
165o = new ulong 256 0
166n = factors 901255 o
167a0 = new ulong 4 0
168put a0 0 5
169put a0 1 17
170put a0 2 23
171put a0 3 461
172ret tueq part o 0 n a0
173end
174note canonical case 070cf8dc-e202-4285-aa37-8d775c9cd473
175fn tc11 to bool
176o = new ulong 256 0
177n = factors 93819012551 o
178a0 = new ulong 3 0
179put a0 0 11
180put a0 1 9539
181put a0 2 894119
182ret tueq part o 0 n a0
183end
184fn main to int
185tcheck tc0 c0
186tcheck tc1 c1
187tcheck tc2 c2
188tcheck tc3 c3
189tcheck tc4 c4
190tcheck tc5 c5
191tcheck tc6 c6
192tcheck tc7 c7
193tcheck tc8 c8
194tcheck tc9 c9
195tcheck tc10 c10
196tcheck tc11 c11
197ret int get tfails 0
198end