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 / core / hive / test.om

557 lines · 11846 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note core/hive/test.om: Comprehensive pure-Omega test suite for Sovereign Agent Hive Engine.
3note Covers axial/cube coordinate identities, hex distance properties, pixel round-trip,
4note all 6 canonical neighbors, ring sizes (6*k) and spiral enumeration, auto-placement,
5note multi-hop shortest-path routing around obstacles, task lease/capacity/reclaim,
6note nearest-agent assignment, and fail-closed negative controls.
7note Compose with: si/directives/om2.om core/hive/lib.om core/hive/test.om
8
9text s_pass "PASS "
10text s_fail "FAIL "
11text s_nl "\n"
12
13text s_t1 "axial_cube_zero_sum_and_dist_identities"
14text s_t2 "pixel_roundtrip_and_detail_tiers"
15text s_t3 "all_six_canonical_neighbors"
16text s_t4 "ring_sizes_6k_and_spiral_uniqueness"
17text s_t5 "auto_placement_ring_expansion_and_bounds"
18text s_t6 "multihop_routing_open_and_around_obstacles"
19text s_t7 "task_leases_capacity_and_reclaim"
20text s_t8 "assign_nearest_reachable_agent"
21text s_t9 "refuse_oob_collision_dup_blocked_capacity"
22text s_t10 "refuse_unreachable_blocked_oob_routes"
23text s_sum "HIVE_TEST_PASS total=10 failed=0\n"
24text s_fsum "HIVE_TEST_FAIL\n"
25
26fn h_report name view uchar * ok bool to uint
27if ok
28w1 = hive_write_all 1 s_pass
29w2 = hive_write_all 1 name
30w3 = hive_write_all 1 s_nl
31if and w1 and w2 w3
32ret 0
33end
34ret 1
35end
36w1 = hive_write_all 1 s_fail
37w2 = hive_write_all 1 name
38w3 = hive_write_all 1 s_nl
39if and w1 and w2 w3
40ret 1
41end
42ret 1
43end
44
45fn test_axial_cube_dist to bool
46ca = new CubeCoord 0 0 0
47cb = new CubeCoord 0 0 0
48cc = new CubeCoord 0 0 0
49hive_axial_to_cube 0 0 ca
50if not hive_cube_valid ca
51ret false
52end
53hive_axial_to_cube -3 2 ca
54hive_axial_to_cube 4 -1 cb
55hive_axial_to_cube 1 3 cc
56if not and hive_cube_valid ca and hive_cube_valid cb hive_cube_valid cc
57ret false
58end
59if ne hive_hex_dist 0 0 0 0 0
60ret false
61end
62if ne hive_hex_dist 0 0 1 0 1
63ret false
64end
65if ne hive_hex_dist 0 0 1 -1 1
66ret false
67end
68if ne hive_hex_dist 0 0 2 2 4
69ret false
70end
71dab = hive_hex_dist -3 2 4 -1
72dba = hive_hex_dist 4 -1 -3 2
73if ne dab 7
74ret false
75end
76if ne dab dba
77ret false
78end
79if ne dab hive_cube_dist ca cb
80ret false
81end
82dac = hive_hex_dist -3 2 1 3
83dbc = hive_hex_dist 4 -1 1 3
84if ne dac hive_cube_dist ca cc
85ret false
86end
87if ne dbc hive_cube_dist cb cc
88ret false
89end
90ret le dac add dab dbc
91end
92
93fn check_px_rt q int r int to bool
94pt = new HexCoord 0 0
95px = hive_axial_to_pixel_x q r HIVE_DEFAULT_RADIUS
96py = hive_axial_to_pixel_y r HIVE_DEFAULT_RADIUS
97if not hive_pixel_to_axial px py HIVE_DEFAULT_RADIUS pt
98ret false
99end
100if ne get pt q q
101ret false
102end
103ret eq get pt r r
104end
105
106fn test_pixel_and_tiers to bool
107pt = new HexCoord 0 0
108if not check_px_rt 0 0
109ret false
110end
111if not check_px_rt 1 0
112ret false
113end
114if not check_px_rt 1 -1
115ret false
116end
117if not check_px_rt -4 3
118ret false
119end
120if not check_px_rt 7 -2
121ret false
122end
123if hive_pixel_to_axial 0.0f64 0.0f64 0.0f64 pt
124ret false
125end
126if hive_pixel_to_axial 0.0f64 0.0f64 -10.0f64 pt
127ret false
128end
129if ne hive_detail_tier 1.0f64 HIVE_TIER_FULL
130ret false
131end
132if ne hive_detail_tier 0.62f64 HIVE_TIER_FULL
133ret false
134end
135if ne hive_detail_tier 0.61f64 HIVE_TIER_COMPACT
136ret false
137end
138if ne hive_detail_tier 0.34f64 HIVE_TIER_COMPACT
139ret false
140end
141if ne hive_detail_tier 0.33f64 HIVE_TIER_DOT
142ret false
143end
144ret eq hive_detail_tier 0.10f64 HIVE_TIER_DOT
145end
146
147fn test_six_neighbors to bool
148qs = new int 6 0
149rs = new int 6 0
150bad = new HexCoord 0 0
151hive_neighbors 3 -2 qs rs
152if or ne get qs 0 4 ne get rs 0 -2
153ret false
154end
155if or ne get qs 1 4 ne get rs 1 -3
156ret false
157end
158if or ne get qs 2 3 ne get rs 2 -3
159ret false
160end
161if or ne get qs 3 2 ne get rs 3 -2
162ret false
163end
164if or ne get qs 4 2 ne get rs 4 -1
165ret false
166end
167if or ne get qs 5 3 ne get rs 5 -1
168ret false
169end
170for i ulong 6
171if ne hive_hex_dist 3 -2 get qs i get rs i 1
172ret false
173end
174j = add i 1
175while lt j 6 bound 6
176if and eq get qs i get qs j eq get rs i get rs j
177ret false
178end
179j = add j 1
180end
181end
182ret not hive_neighbor 3 -2 6 bad
183end
184
185fn check_unique_pairs qs view int * rs view int * n ulong to bool
186i = ulong 0
187while lt i n bound 64
188j = add i 1
189while lt j n bound 64
190if and eq get qs i get qs j eq get rs i get rs j
191ret false
192end
193j = add j 1
194end
195i = add i 1
196end
197ret true
198end
199
200fn test_rings_and_spiral to bool
201ctr = new HexCoord 1 -1
202qs = new int 64 0
203rs = new int 64 0
204c0 = hive_ring ctr 0 qs rs
205if ne c0 1
206ret false
207end
208if or ne get qs 0 1 ne get rs 0 -1
209ret false
210end
211k = uint 1
212while le k 4 bound 4
213cnt = hive_ring ctr k qs rs
214if ne cnt mul k 6
215ret false
216end
217i = ulong 0
218while lt i ulong cnt bound 32
219if ne hive_hex_dist 1 -1 get qs i get rs i int k
220ret false
221end
222i = add i 1
223end
224if not check_unique_pairs qs rs ulong cnt
225ret false
226end
227k = add k 1
228end
229sp = hive_spiral ctr 3 qs rs
230if ne sp 37
231ret false
232end
233ret check_unique_pairs qs rs 37
234end
235
236fn test_auto_placement to bool
237pt = new HexCoord 0 0
238bd = new HiveBounds 0 0 0 0 0 0
239if ne hive_init 6 32 32 HIVE_OK
240ret false
241end
242if ne hive_place_auto 1 0 HIVE_ROLE_COORD 2 pt HIVE_OK
243ret false
244end
245if or ne get pt q 0 ne get pt r 0
246ret false
247end
248aid = uint 2
249while le aid 7 bound 6
250if ne hive_place_auto aid 1 HIVE_ROLE_WORKER 2 pt HIVE_OK
251ret false
252end
253if ne hive_hex_dist 0 0 get pt q get pt r 1
254ret false
255end
256aid = add aid 1
257end
258if ne hive_place_auto 8 1 HIVE_ROLE_RESEARCH 2 pt HIVE_OK
259ret false
260end
261if ne hive_hex_dist 0 0 get pt q get pt r 2
262ret false
263end
264hive_compute_bounds bd
265if ne get bd cnt 8
266ret false
267end
268ret eq get bd max_dist 2
269end
270
271fn check_valid_path pq view int 289 pr view int 289 hops int src view HexCoord dst view HexCoord to bool
272if lt hops 0
273ret false
274end
275n = add ulong hops 1
276if ne get pq 0 get src q
277ret false
278end
279if ne get pr 0 get src r
280ret false
281end
282last = sub n 1
283if ne get pq last get dst q
284ret false
285end
286if ne get pr last get dst r
287ret false
288end
289i = ulong 0
290while lt i n bound 289
291if eq hive_cell_state get pq i get pr i HIVE_CELL_BLOCKED
292ret false
293end
294if gt i 0
295prv = sub i 1
296if ne hive_hex_dist get pq prv get pr prv get pq i get pr i 1
297ret false
298end
299end
300i = add i 1
301end
302ret true
303end
304
305fn test_routing_obstacles to bool
306src = new HexCoord -3 0
307dst = new HexCoord 3 0
308pq = new int 289 0
309pr = new int 289 0
310if ne hive_init 6 32 32 HIVE_OK
311ret false
312end
313h0 = hive_route src dst pq pr
314if ne h0 6
315ret false
316end
317if not check_valid_path pq pr h0 src dst
318ret false
319end
320note Build an obstacle wall across q = 0 for r in -2..2
321if ne hive_block_cell 0 -2 HIVE_OK
322ret false
323end
324if ne hive_block_cell 0 -1 HIVE_OK
325ret false
326end
327if ne hive_block_cell 0 0 HIVE_OK
328ret false
329end
330if ne hive_block_cell 0 1 HIVE_OK
331ret false
332end
333if ne hive_block_cell 0 2 HIVE_OK
334ret false
335end
336put src q -2
337put src r 0
338put dst q 2
339put dst r 0
340h1 = hive_route src dst pq pr
341if le h1 4
342ret false
343end
344if not check_valid_path pq pr h1 src dst
345ret false
346end
347note Direct distance is 4; shortest detour around wall through (0,-3) or (0,3) takes 3 + 5 = 8 hops
348ret eq h1 8
349end
350
351fn test_task_lifecycle to bool
352if ne hive_init 6 16 16 HIVE_OK
353ret false
354end
355if ne hive_place_agent 1 0 0 HIVE_ROLE_WORKER 1 HIVE_OK
356ret false
357end
358if ne hive_place_agent 2 1 0 HIVE_ROLE_WORKER 2 HIVE_OK
359ret false
360end
361if ne hive_task_create 1 1 -1 1 HIVE_OK
362ret false
363end
364if ne hive_task_create 2 -1 1 1 HIVE_OK
365ret false
366end
367if ne hive_task_claim 1 1 10 HIVE_OK
368ret false
369end
370note Agent 1 has cap=1, claiming second task must fail with CAPACITY
371if ne hive_task_claim 2 1 10 HIVE_ERR_CAPACITY
372ret false
373end
374note Agent 2 trying to steal active lease on task 1 must fail with CLAIMED
375if ne hive_task_claim 1 2 10 HIVE_ERR_CLAIMED
376ret false
377end
378note Agent 2 trying to heartbeat or submit task 1 must fail with UNAUTH
379if ne hive_task_heartbeat 1 2 20 HIVE_ERR_UNAUTH
380ret false
381end
382if ne hive_task_submit 1 2 HIVE_ERR_UNAUTH
383ret false
384end
385note Agent 1 heartbeats, submits, and task is verified -> releases load
386if ne hive_task_heartbeat 1 1 20 HIVE_OK
387ret false
388end
389if ne hive_task_submit 1 1 HIVE_OK
390ret false
391end
392if ne hive_task_verify 1 true HIVE_OK
393ret false
394end
395note Now agent 1 load is 0 and can claim task 2 with ttl=5
396if ne hive_task_claim 2 1 5 HIVE_OK
397ret false
398end
399note Advance clock by 5 -> lease expires and is reclaimed
400rec = hive_tick 5
401if ne rec 1
402ret false
403end
404note Agent 2 can now claim reclaimed task 2
405ret eq hive_task_claim 2 2 10 HIVE_OK
406end
407
408fn test_assign_nearest to bool
409asg = new uint 1 0
410if ne hive_init 6 16 16 HIVE_OK
411ret false
412end
413note Agent 1 at (1, 0) but cap=1 and already busy with task 1
414if ne hive_place_agent 1 1 0 HIVE_ROLE_WORKER 1 HIVE_OK
415ret false
416end
417note Agent 2 at (-2, 0), free
418if ne hive_place_agent 2 -2 0 HIVE_ROLE_WORKER 2 HIVE_OK
419ret false
420end
421note Agent 3 at (4, 0), free (only 2 hops from task 2 at (2, 0)!)
422if ne hive_place_agent 3 4 0 HIVE_ROLE_WORKER 2 HIVE_OK
423ret false
424end
425if ne hive_task_create 1 1 0 1 HIVE_OK
426ret false
427end
428if ne hive_task_claim 1 1 50 HIVE_OK
429ret false
430end
431if ne hive_task_create 2 2 0 2 HIVE_OK
432ret false
433end
434if ne hive_assign_nearest 2 30 asg HIVE_OK
435ret false
436end
437ret eq get asg 0 3
438end
439
440fn test_refusals_grid to bool
441if ne hive_init 4 2 4 HIVE_OK
442ret false
443end
444note OOB placement (dist=5 > radius=4)
445if ne hive_place_agent 1 5 0 HIVE_ROLE_WORKER 1 HIVE_ERR_OOB
446ret false
447end
448note Valid placement at (0, 0)
449if ne hive_place_agent 1 0 0 HIVE_ROLE_COORD 1 HIVE_OK
450ret false
451end
452note Collision on occupied cell (0, 0)
453if ne hive_place_agent 2 0 0 HIVE_ROLE_WORKER 1 HIVE_ERR_COLLISION
454ret false
455end
456note Duplicate agent ID 1 at free cell (1, 0)
457if ne hive_place_agent 1 1 0 HIVE_ROLE_WORKER 1 HIVE_ERR_DUP_AGENT
458ret false
459end
460note Blocking occupied cell refused with COLLISION
461if ne hive_block_cell 0 0 HIVE_ERR_COLLISION
462ret false
463end
464note Block (1, 0), double-block refused, placing on blocked refused
465if ne hive_block_cell 1 0 HIVE_OK
466ret false
467end
468if ne hive_block_cell 1 0 HIVE_ERR_BLOCKED
469ret false
470end
471if ne hive_place_agent 2 1 0 HIVE_ROLE_WORKER 1 HIVE_ERR_BLOCKED
472ret false
473end
474note Place 2nd agent at (-1, 0), then 3rd exceeds max_agents=2 -> CAPACITY
475if ne hive_place_agent 2 -1 0 HIVE_ROLE_WORKER 1 HIVE_OK
476ret false
477end
478if ne hive_place_agent 3 0 1 HIVE_ROLE_WORKER 1 HIVE_ERR_CAPACITY
479ret false
480end
481note Removing agent holding claimed task refused with CLAIMED
482if ne hive_task_create 1 -1 0 1 HIVE_OK
483ret false
484end
485if ne hive_task_claim 1 2 10 HIVE_OK
486ret false
487end
488ret eq hive_remove_agent 2 HIVE_ERR_CLAIMED
489end
490
491fn test_refusals_routes to bool
492src = new HexCoord 0 0
493dst = new HexCoord 2 0
494pq = new int 289 0
495pr = new int 289 0
496tiny_q = new int 2 0
497tiny_r = new int 2 0
498nqs = new int 6 0
499nrs = new int 6 0
500if ne hive_init 5 16 16 HIVE_OK
501ret false
502end
503note Route to OOB cell refused (-HIVE_ERR_OOB)
504put dst q 6
505put dst r 0
506if ne hive_route src dst pq pr neg int HIVE_ERR_OOB
507ret false
508end
509note Surround (2, 0) with all 6 blocked neighbors
510hive_neighbors 2 0 nqs nrs
511for i ulong 6
512if ne hive_block_cell get nqs i get nrs i HIVE_OK
513ret false
514end
515end
516put dst q 2
517put dst r 0
518if ne hive_route src dst pq pr neg int HIVE_ERR_NO_ROUTE
519ret false
520end
521note Route to a blocked cell refused (-HIVE_ERR_BLOCKED)
522put dst q 3
523put dst r 0
524if ne hive_route src dst pq pr neg int HIVE_ERR_BLOCKED
525ret false
526end
527note Undersized path buffer refused (-HIVE_ERR_CAPACITY)
528put dst q -3
529put dst r 0
530ret eq hive_route src dst tiny_q tiny_r neg int HIVE_ERR_CAPACITY
531end
532
533fn main to int
534fails = uint 0
535fails = add fails h_report s_t1 test_axial_cube_dist
536fails = add fails h_report s_t2 test_pixel_and_tiers
537fails = add fails h_report s_t3 test_six_neighbors
538fails = add fails h_report s_t4 test_rings_and_spiral
539fails = add fails h_report s_t5 test_auto_placement
540fails = add fails h_report s_t6 test_routing_obstacles
541fails = add fails h_report s_t7 test_task_lifecycle
542fails = add fails h_report s_t8 test_assign_nearest
543fails = add fails h_report s_t9 test_refusals_grid
544fails = add fails h_report s_t10 test_refusals_routes
545if eq fails 0
546ok = hive_write_all 1 s_sum
547if ok
548ret 0
549end
550ret 2
551end
552ok = hive_write_all 1 s_fsum
553if ok
554ret 1
555end
556ret 1
557end