interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / om / quantity / tests.om

358 lines · 7760 bytes Raw Blame History
1note Concatenate quantity.om then tests.om. Wider signed oracle has no quantity guard.
2text tadd "FAIL Q1_ADD_GUARD\n"
3text tmul "FAIL Q4_MUL_GUARD\n"
4text tedge "FAIL Q3_Q5_Q6_Q9_EDGES\n"
5text tslc "FAIL Q7_Q9_SLICE\n"
6text texh "FAIL Q2_EXACT_ORACLE\n"
7text tpass "PASS Q1-Q9 runtime; Q2 widths1..8 pairs87380 operations262140\n"
8
9fn qsent out edit bqty to void
10put out val ulong 17
11put out cap ulong 19
12end
13
14fn qcheck out view bqty rc int want int value ulong cap ulong to bool
15if ne rc want
16ret bool 0
17end
18if ne get out val value
19ret bool 0
20end
21ret eq get out cap cap
22end
23
24fn testadd to bool
25out = new bqty ulong 17 ulong 19
26a = new bqty ulong 18446744073709551608 ulong 18446744073709551615
27b = new bqty ulong 16 ulong 18446744073709551615
28if ne add get a val get b val ulong 8
29ret bool 0
30end
31rc = qadd out a b
32ret qcheck out rc int 3 ulong 17 ulong 19
33end
34
35fn testmul to bool
36out = new bqty ulong 17 ulong 19
37a = new bqty ulong 18446744073709551615 ulong 18446744073709551615
38b = new bqty ulong 2 ulong 18446744073709551615
39rc = qmul out a b
40if not qcheck out rc int 3 ulong 17 ulong 19
41ret bool 0
42end
43put a val ulong 4294967296
44put b val ulong 4294967296
45rc = qmul out a b
46if not qcheck out rc int 3 ulong 17 ulong 19
47ret bool 0
48end
49put a val ulong 4294967297
50put b val ulong 4294967297
51rc = qmul out a b
52if not qcheck out rc int 3 ulong 17 ulong 19
53ret bool 0
54end
55put a val ulong 4294967295
56put b val ulong 4294967295
57rc = qmul out a b
58if not qcheck out rc int 0 ulong 18446744065119617025 ulong 18446744073709551615
59ret bool 0
60end
61qsent out
62put a val ulong 0
63put b val ulong 18446744073709551615
64rc = qmul out a b
65ret qcheck out rc int 0 ulong 0 ulong 18446744073709551615
66end
67
68fn edges to bool
69out = new bqty ulong 17 ulong 19
70a = new bqty ulong 18446744073709551615 ulong 18446744073709551615
71b = new bqty ulong 0 ulong 18446744073709551615
72rc = qnext out a
73if not qcheck out rc int 3 ulong 17 ulong 19
74ret bool 0
75end
76rc = qsigned out long -1 ulong 18446744073709551615
77if not qcheck out rc int 2 ulong 17 ulong 19
78ret bool 0
79end
80rc = qword out ulong 1 ulong 0
81if not qcheck out rc int 3 ulong 17 ulong 19
82ret bool 0
83end
84rc = qmul out a b
85if not qcheck out rc int 0 ulong 0 ulong 18446744073709551615
86ret bool 0
87end
88qsent out
89rc = qadd out a b
90if not qcheck out rc int 0 ulong 18446744073709551615 ulong 18446744073709551615
91ret bool 0
92end
93qsent out
94rc = qsub out b a
95if not qcheck out rc int 3 ulong 17 ulong 19
96ret bool 0
97end
98rc = qsigned out long 9223372036854775807 ulong 18446744073709551615
99if not qcheck out rc int 0 ulong 9223372036854775807 ulong 18446744073709551615
100ret bool 0
101end
102qsent out
103put a val ulong 256
104rc = qnarrow out a ulong 255
105if not qcheck out rc int 3 ulong 17 ulong 19
106ret bool 0
107end
108put a val ulong 255
109rc = qnarrow out a ulong 255
110if not qcheck out rc int 0 ulong 255 ulong 255
111ret bool 0
112end
113qsent out
114put a cap ulong 255
115rc = qnarrow out a ulong 256
116if not qcheck out rc int 2 ulong 17 ulong 19
117ret bool 0
118end
119rc = qadd out a b
120if not qcheck out rc int 2 ulong 17 ulong 19
121ret bool 0
122end
123rc = qsub out a b
124if not qcheck out rc int 2 ulong 17 ulong 19
125ret bool 0
126end
127rc = qmul out a b
128if not qcheck out rc int 2 ulong 17 ulong 19
129ret bool 0
130end
131put a val ulong 256
132rc = qadd out a b
133if not qcheck out rc int 1 ulong 17 ulong 19
134ret bool 0
135end
136rc = qsub out b a
137if not qcheck out rc int 1 ulong 17 ulong 19
138ret bool 0
139end
140rc = qmul out a b
141if not qcheck out rc int 1 ulong 17 ulong 19
142ret bool 0
143end
144rc = qnarrow out a ulong 0
145if not qcheck out rc int 1 ulong 17 ulong 19
146ret bool 0
147end
148rc = qnext out a
149ret qcheck out rc int 1 ulong 17 ulong 19
150end
151
152fn sexpect out view qslic rc int want int to bool
153if ne rc want
154ret bool 0
155end
156if ne get out ident ulong 91
157ret bool 0
158end
159if ne get out ver ulong 92
160ret bool 0
161end
162if ne get out off ulong 93
163ret bool 0
164end
165ret eq get out count ulong 94
166end
167
168fn slices to bool
169out = new qslic ulong 91 ulong 92 ulong 93 ulong 94
170off = new bqty ulong 6 ulong 8
171count = new bqty ulong 3 ulong 8
172expect = new qobj ulong 5 ulong 7 ulong 8
173current = new qobj ulong 5 ulong 7 ulong 8
174rc = qtyslice out off count expect current
175if not sexpect out rc int 3
176ret bool 0
177end
178put expect ver ulong 6
179rc = qtyslice out off count expect current
180if not sexpect out rc int 4
181ret bool 0
182end
183put expect ver ulong 7
184put expect ident ulong 4
185rc = qtyslice out off count expect current
186if not sexpect out rc int 4
187ret bool 0
188end
189put expect ident ulong 5
190put expect extent ulong 7
191rc = qtyslice out off count expect current
192if not sexpect out rc int 4
193ret bool 0
194end
195put expect extent ulong 8
196put off cap ulong 9
197rc = qtyslice out off count expect current
198if not sexpect out rc int 2
199ret bool 0
200end
201put count cap ulong 9
202rc = qtyslice out off count expect current
203if not sexpect out rc int 2
204ret bool 0
205end
206put off val ulong 10
207rc = qtyslice out off count expect current
208if not sexpect out rc int 1
209ret bool 0
210end
211put off val ulong 6
212put off cap ulong 8
213put count cap ulong 8
214put count val ulong 2
215rc = qtyslice out off count expect current
216if ne rc int 0
217ret bool 0
218end
219if ne get out ident ulong 5
220ret bool 0
221end
222if ne get out ver ulong 7
223ret bool 0
224end
225if ne get out off ulong 6
226ret bool 0
227end
228if ne get out count ulong 2
229ret bool 0
230end
231put off val ulong 8
232put count val ulong 0
233rc = qtyslice out off count expect current
234if ne rc int 0
235ret bool 0
236end
237if ne get out off ulong 8
238ret bool 0
239end
240if ne get out count ulong 0
241ret bool 0
242end
243put off val ulong 0
244put off cap ulong 0
245put count cap ulong 0
246put current extent ulong 0
247put expect extent ulong 0
248rc = qtyslice out off count expect current
249ret eq rc int 0
250end
251
252note Oracle uses signed 64-bit exact arithmetic only on operands0..255.
253note Its results are at most65025; it neither uses nor repeats the guarded algorithms.
254fn oracle out view bqty rc int exact long cap ulong to bool
255if or lt exact long 0 gt exact long cap
256ret qcheck out rc int 3 ulong 17 ulong 19
257end
258ret qcheck out rc int 0 ulong exact cap
259end
260
261fn pairs cap ulong to bool
262out = new bqty ulong 17 ulong 19
263a = new bqty ulong 0 cap
264b = new bqty ulong 0 cap
265rc = int 0
266for x ulong add cap ulong 1
267put a val x
268for y ulong add cap ulong 1
269put b val y
270qsent out
271rc = qadd out a b
272if not oracle out rc add long x long y cap
273ret bool 0
274end
275qsent out
276rc = qsub out a b
277if not oracle out rc sub long x long y cap
278ret bool 0
279end
280qsent out
281rc = qmul out a b
282if not oracle out rc mul long x long y cap
283ret bool 0
284end
285end
286end
287ret bool 1
288end
289
290fn unary cap ulong to bool
291out = new bqty ulong 17 ulong 19
292a = new bqty ulong 0 cap
293rc = int 0
294for x ulong add cap ulong 1
295qsent out
296rc = qword out x cap
297if not qcheck out rc int 0 x cap
298ret bool 0
299end
300qsent out
301rc = qsigned out long x cap
302if not qcheck out rc int 0 x cap
303ret bool 0
304end
305qsent out
306put a val x
307rc = qnext out a
308if not oracle out rc add long x long 1 cap
309ret bool 0
310end
311for y ulong add cap ulong 1
312qsent out
313rc = qnarrow out a y
314if not oracle out rc long x y
315ret bool 0
316end
317end
318end
319qsent out
320rc = qword out add cap ulong 1 cap
321ret qcheck out rc int 3 ulong 17 ulong 19
322end
323
324fn main to int
325n = long 0
326if not testadd
327n = write int 1 tadd ulong 0 len tadd
328ret int sub n sub n long 1
329end
330if not testmul
331n = write int 1 tmul ulong 0 len tmul
332ret int sub n sub n long 1
333end
334if not edges
335n = write int 1 tedge ulong 0 len tedge
336ret int sub n sub n long 1
337end
338if not slices
339n = write int 1 tslc ulong 0 len tslc
340ret int sub n sub n long 1
341end
342if not unary ulong 0
343n = write int 1 texh ulong 0 len texh
344ret int sub n sub n long 1
345end
346for w ulong 8
347if not unary sub shl ulong 1 add w ulong 1 ulong 1
348n = write int 1 texh ulong 0 len texh
349ret int sub n sub n long 1
350end
351if not pairs sub shl ulong 1 add w ulong 1 ulong 1
352n = write int 1 texh ulong 0 len texh
353ret int sub n sub n long 1
354end
355end
356n = write int 1 tpass ulong 0 len tpass
357ret int sub n n
358end