-
Notifications
You must be signed in to change notification settings - Fork 9
/
test_all.py
1174 lines (989 loc) · 23.7 KB
/
test_all.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import functools
import inspect
import pathlib
import pyndustric
import pytest
import re
import sys
import tempfile
_REG_TMP_RE = re.compile(r"\b" + pyndustric.REG_TMP_FMT.replace("{}", r"(\w+)") + r"\b")
def as_masm(source):
# Dedent expected mlog source by removing all leading whitespace
return "set __pyc_sp 0\n" + re.sub(r"^\s+", "", source.strip(), flags=re.MULTILINE) + "\nend\n"
def masm_test(source_func):
"""
Marks the function as a "masm test".
The body of the wrapped function will be compiled, and this masm output will be compared
against the function's docstring, which should contain the *expected* masm output.
The special value `%tmpD`, where D is an integer, will be replaced by the matching `REG_TMP_FMT`.
The temporary names are ordered by time of appearance (meaning `__pyc_tmp_2` can be `%tmp0` and
`__pyc_tmp_1` be `%tmp1` if they appear in this order in the generated masm).
"""
dbg_name = f"{source_func.__name__}:{inspect.currentframe().f_back.f_lineno}"
@functools.wraps(source_func)
def wrapped():
assert source_func.__doc__ is not None, "bad `masm_test` usage; def should have docstring"
expected = as_masm(source_func.__doc__)
masm = pyndustric.Compiler().compile(source_func)
tmp = 0
while True:
match = _REG_TMP_RE.search(masm)
if not match:
break
masm = re.sub(rf"\b{match[0]}\b", f"%tmp{tmp}", masm)
tmp += 1
assert masm == expected, f"bad masm for {dbg_name}\n{masm}"
return wrapped
def expect_err(err, source):
"""
Expect the error to be raised, and fail if it's not.
"""
with pytest.raises(pyndustric.CompilerError, match=err):
pyndustric.Compiler().compile(source)
def test_all_err_have_desc_and_tests():
error_names = [name for name in dir(pyndustric) if name.startswith("ERR_")]
error_values = {getattr(pyndustric, name) for name in error_names}
assert len(error_values) == len(error_names), "some error constants have duplicate values"
assert len(error_values) + 1 == len(pyndustric.ERROR_DESCRIPTIONS), "not all errors are documented"
with open(__file__, encoding="utf-8") as fd:
source = fd.read()
for name in error_names:
assert name in source, "error is missing a test"
def test_err_complex_assign():
expect_err(pyndustric.ERR_COMPLEX_ASSIGN, "a, b = c = 1, 2")
expect_err(pyndustric.ERR_COMPLEX_ASSIGN, "a.b = 1")
def test_err_complex_value():
expect_err(pyndustric.ERR_COMPLEX_VALUE, "a = 1 + 2j")
def test_err_unsupported_op():
expect_err(pyndustric.ERR_UNSUPPORTED_OP, "a = m0 @ m1")
expect_err(pyndustric.ERR_UNSUPPORTED_OP, "a @= m")
def test_err_unsupported_iter():
expect_err(pyndustric.ERR_UNSUPPORTED_ITER, "for x in obj: pass")
def test_err_bad_iter_args():
expect_err(pyndustric.ERR_BAD_ITER_ARGS, "for x in range(): pass")
expect_err(pyndustric.ERR_BAD_ITER_ARGS, "for x in range(1, 2, 3, 4): pass")
def test_err_unsupported_import():
expect_err(pyndustric.ERR_UNSUPPORTED_IMPORT, "from math import log")
expect_err(pyndustric.ERR_UNSUPPORTED_IMPORT, "import pyndustri")
def test_err_unsupported_expr():
expect_err(pyndustric.ERR_UNSUPPORTED_EXPR, "1 + (2 + 3)")
def test_err_unsupported_syscall():
expect_err(pyndustric.ERR_UNSUPPORTED_SYSCALL, "Missing.method()")
expect_err(pyndustric.ERR_UNSUPPORTED_SYSCALL, "Screen.missing()")
expect_err(pyndustric.ERR_UNSUPPORTED_SYSCALL, "unit.unknown_control()")
def test_err_bad_syscall_args():
expect_err(pyndustric.ERR_BAD_SYSCALL_ARGS, "Screen.clear(1)")
expect_err(pyndustric.ERR_BAD_SYSCALL_ARGS, "Screen.clear(1, 2, 3, 4)")
def test_err_nested_def():
expect_err(pyndustric.ERR_NESTED_DEF, "def foo():\n def bar():\n pass")
def test_err_invalid_def():
expect_err(pyndustric.ERR_INVALID_DEF, "def foo(a=None): pass")
expect_err(pyndustric.ERR_INVALID_DEF, "def foo(*, a): pass")
if sys.version_info >= (3, 8):
expect_err(pyndustric.ERR_INVALID_DEF, "def foo(a, /, b): pass")
def test_err_redef():
expect_err(pyndustric.ERR_REDEF, "def foo(): pass\ndef foo(): pass")
expect_err(pyndustric.ERR_REDEF, "def print(): pass")
def test_err_no_def():
expect_err(pyndustric.ERR_NO_DEF, "x = foo()")
def test_err_argc_mismatch():
expect_err(pyndustric.ERR_ARGC_MISMATCH, "def foo(n): pass\nx = foo()")
expect_err(pyndustric.ERR_ARGC_MISMATCH, "def foo(n): pass\nx = foo(1, 2)")
expect_err(pyndustric.ERR_ARGC_MISMATCH, "u = Unit.radar(enemy, flying, ally, any)")
def test_err_too_long():
expect_err(pyndustric.ERR_TOO_LONG, "x = 1\n" * (1 + pyndustric.MAX_INSTRUCTIONS))
def test_err_bad_tuple():
expect_err(pyndustric.ERR_UNSUPPORTED_EXPR, "x = 1, 2")
expect_err(pyndustric.ERR_BAD_TUPLE_ASSIGN, "x, y = 1")
expect_err(pyndustric.ERR_UNSUPPORTED_SYSCALL, "x, y = foo()")
expect_err(pyndustric.ERR_BAD_TUPLE_ASSIGN, "x, y = a, b, c")
def test_no_compile_method():
class Foo:
def bar(self):
pass
foo = Foo()
with pytest.raises(pyndustric.CompilerError, match=pyndustric.ERR_INVALID_SOURCE):
pyndustric.Compiler().compile(foo.bar)
def test_compile_string():
masm = pyndustric.Compiler().compile(
"""\
from pyndustri import *
x = 1
"""
)
def test_compile_path():
expected = as_masm(
"""\
set x 1
"""
)
with tempfile.TemporaryDirectory() as folder:
file = pathlib.Path(folder) / "test_compile_path.py"
with file.open("w") as fd:
fd.write("x = 1\n")
masm = pyndustric.Compiler().compile(file)
assert masm == expected
def test_compile_function():
def source():
"""Skip me!"""
x = 1
def source2():
x = 1
expected = as_masm(
"""\
set x 1
"""
)
masm = pyndustric.Compiler().compile(source)
assert masm == expected
masm = pyndustric.Compiler().compile(source2)
assert masm == expected
@masm_test
def test_assignments():
"""
set x -1
op add y x 2
op equal z x y
op equal a 0 z
"""
x = -1
y = x + 2
z = x == y
a = not z
@masm_test
def test_multi_assignment():
"""
set x 0
set y x
set z x
set a 1
set b 2
"""
x = y = z = 0
a, b = 1, 2
@masm_test
def test_types():
"""
set x true
set y 1
set z 0.1
set a "string"
"""
x = True
y = 1
z = 0.1
a = "string"
@masm_test
def test_builtin_defs():
"""
op abs a 1
op min lo 1 2
"""
a = abs(1)
lo = min(1, 2)
@masm_test
def test_complex_assign():
"""
op mul %tmp0 2 x
op add a %tmp0 1
op mul %tmp1 x x
op mul %tmp2 y y
op add %tmp3 %tmp1 %tmp2
op sqrt d %tmp3
"""
a = 2 * x + 1
d = sqrt(x * x + y * y)
@masm_test
def test_aug_assignments():
"""
set x 1
op add x x 1
"""
x = 1
x += 1
@masm_test
def test_complex_aug_assig():
"""
set x 1
op add %tmp0 1 2
op mul %tmp1 %tmp0 3
op add x x %tmp1
"""
x = 1
x += (1 + 2) * 3
@masm_test
def test_if():
"""
set x 1
jump 4 equal x 0
set y 1
set z 1
"""
x = 1
if x:
y = 1
z = 1
@masm_test
def test_ternary():
"""
op mod %tmp0 5 1
jump 5 notEqual %tmp0 0
set %tmp1 true
jump 6 always
set %tmp1 false
jump 9 equal %tmp1 0
set a @titanium
jump 10 always
set a @thorium
"""
a = Env.titanium if (True if 5 % 1 == 0 else False) else Env.thorium
@masm_test
def test_complex_if():
"""
set x 1
jump 4 greaterThanEq x 10
set y 1
"""
x = 1
if x < 10:
y = 1
@masm_test
def test_if_else():
"""
set x 1
jump 5 equal x 0
set y 1
jump 6 always
set y 0
set z 1
"""
x = 1
if x:
y = 1
else:
y = 0
z = 1
@masm_test
def test_if_elif_else():
"""
set x 1
jump 5 notEqual x 0
set y 1
jump 9 always
jump 8 notEqual x 1
set y 2
jump 9 always
set y 3
"""
x = 1
if x == 0:
y = 1
elif x == 1:
y = 2
else:
y = 3
@masm_test
def test_while():
"""
set x 10
jump 5 equal x 0
op sub x x 1
jump 3 notEqual x 0
set z 1
"""
x = 10
while x:
x = x - 1
z = 1
@masm_test
def test_for_end():
"""
set x 0
jump 6 greaterThanEq x 10
op add y x x
op add x x 1
jump 2 always
set z 1
"""
for x in range(10):
y = x + x
z = 1
@masm_test
def test_for_start_end():
"""
set x 5
jump 6 greaterThanEq x 10
op add y x x
op add x x 1
jump 2 always
"""
for x in range(5, 10):
y = x + x
@masm_test
def test_for_start_end_step():
"""
set x 0
jump 6 greaterThanEq x 10
op add y x x
op add x x 3
jump 2 always
"""
for x in range(0, 10, 3):
y = x + x
@masm_test
def test_for_negative():
"""
set x 10
jump 6 lessThanEq x 0
op add y x x
op add x x -1
jump 2 always
"""
for x in range(10, 0, -1):
y = x + x
@masm_test
def test_break():
"""
set x 10
jump 7 equal x 0
op sub x x 1
jump 6 notEqual x 5
jump 7 always
jump 3 notEqual x 0
set z 1
set x 0
jump 14 greaterThanEq x 10
jump 12 notEqual x 5
jump 14 always
op add x x 1
jump 9 always
set z 1
"""
x = 10
while x:
x = x - 1
if x == 5:
break
z = 1
for x in range(10):
if x == 5:
break
z = 1
@masm_test
def test_nested_break():
"""
set a 0
set b 0
set i 10
jump 17 equal i 0
op sub i i 1
set j 10
jump 13 equal j 0
op sub j j 1
jump 11 notEqual j 5
jump 13 always
op add b b 1
jump 8 notEqual j 0
jump 15 notEqual i 5
jump 17 always
op add a a 1
jump 5 notEqual i 0
"""
a = 0
b = 0
i = 10
while i:
i -= 1
j = 10
while j:
j -= 1
if j == 5:
break
b += 1
if i == 5:
break
a += 1
@masm_test
def test_continue():
"""
set a 0
set x 10
jump 9 equal x 0
op sub x x 1
jump 7 notEqual x 5
jump 4 always
op add a a 1
jump 4 notEqual x 0
set b 0
set x 0
jump 17 greaterThanEq x 10
jump 14 notEqual x 5
jump 15 always
op add b b 1
op add x x 1
jump 11 always
"""
a = 0
x = 10
while x:
x = x - 1
if x == 5:
continue
a += 1
b = 0
for x in range(10):
if x == 5:
continue
b += 1
@masm_test
def test_nested_continue():
"""
set a 0
set b 0
set i 10
jump 17 equal i 0
op sub i i 1
set j 10
jump 13 equal j 0
op sub j j 1
jump 11 notEqual j 5
jump 8 always
op add b b 1
jump 8 notEqual j 0
jump 15 notEqual i 5
jump 5 always
op add a a 1
jump 5 notEqual i 0
"""
a = 0
b = 0
i = 10
while i:
i -= 1
j = 10
while j:
j -= 1
if j == 5:
continue
b += 1
if i == 5:
continue
a += 1
@masm_test
def test_def():
# TODO cells can't store strings, test that no fn args are
"""
jump 12 always
read __pyc_rc_0 cell1 __pyc_sp
op sub __pyc_sp __pyc_sp 1
read n cell1 __pyc_sp
jump 9 greaterThanEq n 10
set __pyc_ret true
jump 11 always
jump 11 always
set __pyc_ret false
jump 11 always
op add @counter __pyc_rc_0 1
write 5 cell1 __pyc_sp
op add __pyc_sp __pyc_sp 1
write @counter cell1 __pyc_sp
jump 2 always
set a __pyc_ret
write 15 cell1 __pyc_sp
op add __pyc_sp __pyc_sp 1
write @counter cell1 __pyc_sp
jump 2 always
set b __pyc_ret
print "5 small? "
print a
print ", 15 small? "
print b
printflush message1
"""
def small(n):
if n < 10:
return True
else:
return False
a = small(5)
b = small(15)
print(f"5 small? {a}, 15 small? {b}")
@masm_test
def test_multi_call():
"""
jump 8 always
read __pyc_rc_0 cell1 __pyc_sp
op sub __pyc_sp __pyc_sp 1
read i cell1 __pyc_sp
set __pyc_ret i
jump 7 always
op add @counter __pyc_rc_0 1
write 1 cell1 __pyc_sp
op add __pyc_sp __pyc_sp 1
write @counter cell1 __pyc_sp
jump 2 always
set %tmp0 __pyc_ret
write 2 cell1 __pyc_sp
op add __pyc_sp __pyc_sp 1
write @counter cell1 __pyc_sp
jump 2 always
set %tmp1 __pyc_ret
op add x %tmp0 %tmp1
"""
def f(i):
return i
x = f(1) + f(2)
@masm_test
def test_multiarg_call():
"""
jump 10 always
read __pyc_rc_0 cell1 __pyc_sp
op sub __pyc_sp __pyc_sp 1
read y cell1 __pyc_sp
op sub __pyc_sp __pyc_sp 1
read x cell1 __pyc_sp
set __pyc_ret y
jump 9 always
op add @counter __pyc_rc_0 1
write 4 cell1 __pyc_sp
op add __pyc_sp __pyc_sp 1
write 2 cell1 __pyc_sp
op add __pyc_sp __pyc_sp 1
write @counter cell1 __pyc_sp
jump 2 always
set %tmp0 __pyc_ret
"""
def dot(x, y):
return y
dot(4, 2)
@masm_test
def test_complex_call():
"""
jump 8 always
read __pyc_rc_0 cell1 __pyc_sp
op sub __pyc_sp __pyc_sp 1
read i cell1 __pyc_sp
set __pyc_ret i
jump 7 always
op add @counter __pyc_rc_0 1
op add %tmp0 2 3
write %tmp0 cell1 __pyc_sp
op add __pyc_sp __pyc_sp 1
write @counter cell1 __pyc_sp
jump 2 always
set %tmp1 __pyc_ret
op mul %tmp2 1 %tmp1
op add x %tmp2 4
"""
def f(i):
return i
x = 1 * f(2 + 3) + 4
@masm_test
def test_def_sideeffects():
# TODO detect this unnecessary use of %tmp0 and optimize it away
"""
jump 6 always
read __pyc_rc_0 cell1 __pyc_sp
print "bar"
printflush message1
op add @counter __pyc_rc_0 1
write @counter cell1 __pyc_sp
jump 2 always
set %tmp0 __pyc_ret
"""
def foo():
print("bar")
foo()
@masm_test
def test_def_call_as_call_arg():
# TODO detect this unnecessary use of %tmp0 and optimize it away
"""
jump 9 always
read __pyc_rc_0 cell1 __pyc_sp
op sub __pyc_sp __pyc_sp 1
read n cell1 __pyc_sp
op pow n n 2
set __pyc_ret n
jump 8 always
op add @counter __pyc_rc_0 1
write 2 cell1 __pyc_sp
op add __pyc_sp __pyc_sp 1
write @counter cell1 __pyc_sp
jump 2 always
set %tmp0 __pyc_ret
write %tmp0 cell1 __pyc_sp
op add __pyc_sp __pyc_sp 1
write @counter cell1 __pyc_sp
jump 2 always
set r __pyc_ret
"""
def square(n):
n **= 2
return n
r = square(square(2))
@masm_test
def test_print():
"""
set x 1
set y 2
print "showing variables:"
printflush message1
print "x = "
print x
print ", y = "
print y
printflush message1
"""
x = 1
y = 2
print("showing variables:")
print(f"x = {x}, y = ", flush=False)
print(y, flush=message1)
@masm_test
def test_sleep():
"""
wait 0.5
"""
sleep(0.5)
@masm_test
def test_env():
"""
set cop @copper
set this @this
set x @thisx
set y @thisy
set pc @counter
set links @links
set time @time
set width @mapw
set height @maph
op mul ips @ipt 60
set __pyc_it_30_16 0
jump 16 greaterThanEq __pyc_it_30_16 @links
getlink link __pyc_it_30_16
op add __pyc_it_30_16 __pyc_it_30_16 1
jump 12 always
"""
cop = Env.copper
this = Env.this
x = Env.x
y = Env.y
pc = Env.counter
links = Env.link_count
time = Env.time
width = Env.width
height = Env.height
ips = Env.ips
for link in Env.links():
pass
@masm_test
def test_sensor():
"""
sensor pf container1 @phase-fabric
"""
pf = container1.phase_fabric
@masm_test
def test_sensor_subscript():
"""
set dyn @copper
sensor co container2 dyn
sensor ab a_b @lead
sensor cd container3 @c_d
sensor ef e_f @g_h
"""
dyn = Env.copper
co = container2[dyn]
ab = "a_b"[Env.lead]
cd = container3["c_d"]
ef = "e_f"["g_h"]
@masm_test
def test_sensor_special_names():
"""
sensor %tmp0 duo1 @health
sensor %tmp1 duo1 @maxHealth
op div health %tmp0 %tmp1
"""
health = duo1.health / duo1.max_health
@masm_test
def test_world_setblock():
"""
setrate 6000
set x 0
jump 11 greaterThanEq x @mapw
set y 0
jump 9 greaterThanEq y @maph
setblock block @router x y @sharded 0
op add y y 1
jump 5 always
op add x x 1
jump 3 always
"""
World.set_rate(6000)
for x in range(Env.width):
for y in range(Env.height):
World.blocks[x][y].set(block=Env.router, block_team=Env.sharded)
@masm_test
def test_radar():
"""
uradar enemy flying any distance @unit 0 u1
radar ally any any health ripple1 1 u2
"""
u1 = Unit.radar(enemy, flying, order=max, key=distance)
u2 = ripple1.radar(ally, key=health)
@masm_test
def test_draw():
"""
draw clear 255 0 0
draw color 0 255 255 255
draw stroke 2
draw line 0 0 80 80
draw rect 0 0 20 20
draw lineRect 0 0 40 40
draw poly 60 60 3 10 0
draw linePoly 60 60 5 20 0
draw triangle 70 80 80 80 80 70
drawflush display1
"""
Screen.clear(255, 0, 0)
Screen.color(0, 255, 255)
Screen.stroke(2)
Screen.line(0, 0, 80, 80)
Screen.rect(0, 0, 20, 20)
Screen.hollow_rect(0, 0, 40, 40)
Screen.poly(60, 60, 10, 3)
Screen.hollow_poly(60, 60, 20, 5)
Screen.triangle(70, 80, 80, 80, 80, 70)
Screen.flush()
@masm_test
def test_control():
"""
control enabled reactor false
control shoot duo1 10 20 1
control shoot scatter1 0 0 0
"""
reactor.enabled(False)
duo1.shoot(10, 20)
scatter1.ceasefire()
@masm_test
def test_ubind():
"""
ubind @alpha
sensor %tmp0 @unit @x
print %tmp0
printflush message1
"""
Unit.bind("alpha")
print(Unit.x)
def test_bad_ubind():
expect_err(pyndustric.ERR_BAD_SYSCALL_ARGS, "Unit.bind(42)")
expect_err(pyndustric.ERR_BAD_SYSCALL_ARGS, "Unit.bind('alpha', 'beta')")
@masm_test
def test_unit_actions():
"""
ucontrol idle 0 0 0 0 0
ucontrol stop 0 0 0 0 0
ucontrol move 1 2 0 0 0
ucontrol approach 3 4 5 0 0
ucontrol within 6 7 8 w 0
ucontrol boost 1 0 0 0 0
ucontrol boost 0 0 0 0 0
ucontrol pathfind 5 5
ucontrol targetp @unit 1 0 0 0
ucontrol target 9 10 1 0 0
ucontrol target 0 0 0 0 0
ucontrol itemTake container1 @copper 1 0 0
ucontrol itemTake container1 @copper 11 0 0
ucontrol itemDrop container1 1 0 0 0
ucontrol itemDrop container1 12 0 0 0
ucontrol payTake takeUnits 0 0 0 0
ucontrol payTake takeUnits 0 0 0 0
ucontrol payDrop 0 0 0 0 0
ucontrol mine 13 14 0 0 0
ucontrol target 15 16 0 0 0
ucontrol target 17 18 true 0 0
ucontrol targetp @unit 1 0 0 0
ucontrol targetp @unit false 0 0 0
ucontrol build 19 20 @router 0 0
ucontrol build 21 22 @conveyor 3 0
ucontrol build 23 24 @sorter 0 @titanium
ucontrol getBlock 25 26 bt building1 0
ucontrol getBlock 27 28 0 building2 0
ucontrol unbind
"""
Unit.idle()
Unit.stop()
Unit.move(1, 2)
Unit.approach(3, 4, 5)
w = Unit.within(6, 7, 8)
Unit.boost(1)
Unit.boost(0)
Unit.pathfind(5, 5)
Unit.shoot()
Unit.shoot(9, 10)
Unit.ceasefire()
Unit.fetch(container1, Env.copper)
Unit.fetch(container1, Env.copper, 11)
Unit.store(container1)
Unit.store(container1, 12)
Unit.lift()
Unit.carry()
Unit.drop()
Unit.mine(13, 14)
Unit.target(15, 16)
Unit.target(17, 18, True)
Unit.target_unit(Env.unit)
Unit.target_unit(Env.unit, False)
Unit.build(19, 20, Env.router)
Unit.build(21, 22, Env.conveyor, 3)