Skip to content

Commit ed3f889

Browse files
committed
CC:T gps & command computers
1 parent 7d7bac1 commit ed3f889

9 files changed

Lines changed: 243 additions & 88 deletions

File tree

examples/test_commands.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

examples/test_gps_basic_computer.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

examples/test_gps_command_computer.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/cc_programs/commands.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from cc import commands
2+
3+
4+
class AnyInstanceOf:
5+
def __init__(self, cls):
6+
self.c = cls
7+
8+
def __eq__(self, other):
9+
return isinstance(other, self.c)
10+
11+
12+
print('Run this test on command computer')
13+
14+
xyz = commands.getBlockPosition()
15+
assert xyz == (
16+
AnyInstanceOf(int),
17+
AnyInstanceOf(int),
18+
AnyInstanceOf(int),
19+
)
20+
21+
expected_binfo = {
22+
'state': {
23+
'state': AnyInstanceOf(str),
24+
'facing': AnyInstanceOf(str),
25+
},
26+
'name': 'computercraft:computer_command',
27+
'nbt': {
28+
'x': xyz[0],
29+
'y': xyz[1],
30+
'z': xyz[2],
31+
'ForgeCaps': {},
32+
'ComputerId': AnyInstanceOf(int),
33+
'id': 'computercraft:computer_command',
34+
'On': 1,
35+
},
36+
'tags': {'computercraft:computer': True},
37+
}
38+
39+
assert commands.getBlockInfo(*xyz) == expected_binfo
40+
assert commands.getBlockInfos(*xyz, *xyz) == [expected_binfo]
41+
42+
cmdlist = commands.list()
43+
44+
assert len(cmdlist) > 0
45+
for c in cmdlist:
46+
assert isinstance(c, str)
47+
48+
assert commands.exec('say Hello!') == (True, [], AnyInstanceOf(int))
49+
50+
d = commands.exec('tp hajejndlasksdkelefsns fjeklaskslekffjslas')
51+
assert d[0] is False
52+
53+
d = commands.exec('difficulty')
54+
assert d[0] is True
55+
assert len(d[1]) == 1
56+
assert d[1][0].startswith('The difficulty is ')
57+
assert isinstance(d[2], int)
58+
59+
print('Test finished successfully')
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from cc import gps
2+
3+
4+
print('It must be impossible to gps locate on basic computer')
5+
print('for this test to complete')
6+
7+
assert gps.locate() is None
8+
9+
input('Attach wireless modem to computer [enter]')
10+
11+
assert gps.locate() is None
12+
assert gps.locate(debug=True) is None
13+
assert gps.locate(timeout=5, debug=True) is None
14+
15+
print('Test finished successfully')
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from cc import gps
2+
3+
4+
print('Run this test on command computer')
5+
pos = gps.locate()
6+
assert isinstance(pos, tuple)
7+
assert len(pos) == 3
8+
assert all(isinstance(x, int) for x in pos)
9+
print('Position is', pos)
10+
print('Test finished successfully')
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
R1381:0[5]{:[1]<11>commands.py:[0]<2>py}<11>commands.py<1326>from cc import commands
2+
3+
4+
class AnyInstanceOf:
5+
def __init__(self, cls):
6+
self.c = cls
7+
8+
def __eq__(self, other):
9+
return isinstance(other, self.c)
10+
11+
12+
print('Run this test on command computer')
13+
14+
xyz = commands.getBlockPosition()
15+
assert xyz == (
16+
AnyInstanceOf(int),
17+
AnyInstanceOf(int),
18+
AnyInstanceOf(int),
19+
)
20+
21+
expected_binfo = {
22+
'state': {
23+
'state': AnyInstanceOf(str),
24+
'facing': AnyInstanceOf(str),
25+
},
26+
'name': 'computercraft:computer_command',
27+
'nbt': {
28+
'x': xyz[0],
29+
'y': xyz[1],
30+
'z': xyz[2],
31+
'ForgeCaps': {},
32+
'ComputerId': AnyInstanceOf(int),
33+
'id': 'computercraft:computer_command',
34+
'On': 1,
35+
},
36+
'tags': {'computercraft:computer': True},
37+
}
38+
39+
assert commands.getBlockInfo(*xyz) == expected_binfo
40+
assert commands.getBlockInfos(*xyz, *xyz) == [expected_binfo]
41+
42+
cmdlist = commands.list()
43+
44+
assert len(cmdlist) > 0
45+
for c in cmdlist:
46+
assert isinstance(c, str)
47+
48+
assert commands.exec('say Hello!') == (True, [], AnyInstanceOf(int))
49+
50+
d = commands.exec('tp hajejndlasksdkelefsns fjeklaskslekffjslas')
51+
assert d[0] is False
52+
53+
d = commands.exec('difficulty')
54+
assert d[0] is True
55+
assert len(d[1]) == 1
56+
assert d[1][0].startswith('The difficulty is ')
57+
assert isinstance(d[2], int)
58+
59+
print('Test finished successfully')
60+
S65:T<1>1<13>io.write(...){:[1]<33>Run this test on command computer}
61+
R15:T<1>1<7>{:[1]T}
62+
S32:T<1>1<13>io.write(...){:[1]<1>
63+
}
64+
R15:T<1>1<7>{:[1]T}
65+
S40:T<1>1<29>G:commands:M:getBlockPosition{}
66+
R42:T<1>1<33>{:[1]T:[2][-12]:[3][70]:[4][-19]}
67+
S62:T<1>1<25>G:commands:M:getBlockInfo{:[1][-12]:[2][70]:[3][-19]}
68+
R272:T<1>1<262>{:[1]T:[2]{:<5>state{:<5>state<8>blinking:<6>facing<5>south}:<3>nbt{:<1>y[70]:<1>x[-12]:<10>ComputerId[5]:<9>ForgeCaps{}:<2>id<30>computercraft:computer_command:<2>On[1]:<1>z[-19]}:<4>name<30>computercraft:computer_command:<4>tags{:<22>computercraft:computerT}}}
69+
S89:T<1>1<26>G:commands:M:getBlockInfos{:[1][-12]:[2][70]:[3][-19]:[4][-12]:[5][70]:[6][-19]}
70+
R272:T<1>1<262>{:[1]T:[2]{:[1]{:<5>state{:<5>state<2>on:<6>facing<5>south}:<3>nbt{:<1>y[70]:<1>x[-12]:<10>ComputerId[5]:<9>ForgeCaps{}:<2>id<30>computercraft:computer_command:<2>On[1]:<1>z[-19]}:<4>name<30>computercraft:computer_command:<4>tags{:<22>computercraft:computerT}}}}
71+
S28:T<1>1<17>G:commands:M:list{}
72+
R1021:T<1>1<1010>{:[1]T:[2]{:[1]<11>advancement:[2]<9>attribute:[3]<7>execute:[4]<7>bossbar:[5]<5>clear:[6]<5>clone:[7]<6>damage:[8]<4>data:[9]<8>datapack:[10]<5>debug:[11]<15>defaultgamemode:[12]<10>difficulty:[13]<6>effect:[14]<2>me:[15]<7>enchant:[16]<10>experience:[17]<2>xp:[18]<4>fill:[19]<9>fillbiome:[20]<9>forceload:[21]<8>function:[22]<8>gamemode:[23]<8>gamerule:[24]<4>give:[25]<4>help:[26]<4>item:[27]<4>kick:[28]<4>kill:[29]<4>list:[30]<6>locate:[31]<4>loot:[32]<3>msg:[33]<4>tell:[34]<1>w:[35]<8>particle:[36]<5>place:[37]<9>playsound:[38]<6>reload:[39]<6>recipe:[40]<6>return:[41]<4>ride:[42]<3>say:[43]<8>schedule:[44]<10>scoreboard:[45]<4>seed:[46]<8>setblock:[47]<10>spawnpoint:[48]<13>setworldspawn:[49]<8>spectate:[50]<13>spreadplayers:[51]<9>stopsound:[52]<6>summon:[53]<3>tag:[54]<4>team:[55]<7>teammsg:[56]<2>tm:[57]<8>teleport:[58]<2>tp:[59]<7>tellraw:[60]<4>time:[61]<5>title:[62]<7>trigger:[63]<7>weather:[64]<11>worldborder:[65]<3>jfr:[66]<7>publish:[67]<13>computercraft:[68]<5>forge:[69]<6>config}}
73+
S46:T<1>1<17>G:commands:M:exec{:[1]<10>say Hello!}
74+
R34:T<1>1<25>{:[1]T:[2]T:[3]{}:[4][1]}
75+
S80:T<1>1<17>G:commands:M:exec{:[1]<44>tp hajejndlasksdkelefsns fjeklaskslekffjslas}
76+
R134:T<1>1<124>{:[1]T:[2]F:[3]{:[1]<30>Incorrect argument for command:[2]<53>tp hajejndlasksdkelefsns fjeklaskslekffjslas<--[HERE]}:[4][0]}
77+
S46:T<1>1<17>G:commands:M:exec{:[1]<10>difficulty}
78+
R66:T<1>1<57>{:[1]T:[2]T:[3]{:[1]<24>The difficulty is Normal}:[4][2]}
79+
S58:T<1>1<13>io.write(...){:[1]<26>Test finished successfully}
80+
R15:T<1>1<7>{:[1]T}
81+
S32:T<1>1<13>io.write(...){:[1]<1>
82+
}
83+
R15:T<1>1<7>{:[1]T}
84+
S2:CN
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
R426:0[5]{:[1]<21>gps_basic_computer.py:[0]<2>py}<21>gps_basic_computer.py<352>from cc import gps
2+
3+
4+
print('It must be impossible to gps locate on basic computer')
5+
print('for this test to complete')
6+
7+
assert gps.locate() is None
8+
9+
input('Attach wireless modem to computer [enter]')
10+
11+
assert gps.locate() is None
12+
assert gps.locate(debug=True) is None
13+
assert gps.locate(timeout=5, debug=True) is None
14+
15+
print('Test finished successfully')
16+
S85:T<1>1<13>io.write(...){:[1]<53>It must be impossible to gps locate on basic computer}
17+
R15:T<1>1<7>{:[1]T}
18+
S32:T<1>1<13>io.write(...){:[1]<1>
19+
}
20+
R15:T<1>1<7>{:[1]T}
21+
S57:T<1>1<13>io.write(...){:[1]<25>for this test to complete}
22+
R15:T<1>1<7>{:[1]T}
23+
S32:T<1>1<13>io.write(...){:[1]<1>
24+
}
25+
R15:T<1>1<7>{:[1]T}
26+
S35:T<1>1<14>G:gps:M:locate{:[1]N:[2]N}
27+
R15:T<1>1<7>{:[1]T}
28+
S73:T<1>1<13>io.write(...){:[1]<41>Attach wireless modem to computer [enter]}
29+
R15:T<1>1<7>{:[1]T}
30+
S22:T<1>1<11>G:io:M:read{}
31+
R23:T<1>1<14>{:[1]T:[2]<0>}
32+
S35:T<1>1<14>G:gps:M:locate{:[1]N:[2]N}
33+
R15:T<1>1<7>{:[1]T}
34+
S35:T<1>1<14>G:gps:M:locate{:[1]N:[2]T}
35+
R15:T<1>1<7>{:[1]T}
36+
S37:T<1>1<14>G:gps:M:locate{:[1][5]:[2]T}
37+
R15:T<1>1<7>{:[1]T}
38+
S58:T<1>1<13>io.write(...){:[1]<26>Test finished successfully}
39+
R15:T<1>1<7>{:[1]T}
40+
S32:T<1>1<13>io.write(...){:[1]<1>
41+
}
42+
R15:T<1>1<7>{:[1]T}
43+
S2:CN
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
R317:0[5]{:[1]<23>gps_command_computer.py:[0]<2>py}<23>gps_command_computer.py<239>from cc import gps
2+
3+
4+
print('Run this test on command computer')
5+
pos = gps.locate()
6+
assert isinstance(pos, tuple)
7+
assert len(pos) == 3
8+
assert all(isinstance(x, int) for x in pos)
9+
print('Position is', pos)
10+
print('Test finished successfully')
11+
S65:T<1>1<13>io.write(...){:[1]<33>Run this test on command computer}
12+
R15:T<1>1<7>{:[1]T}
13+
S32:T<1>1<13>io.write(...){:[1]<1>
14+
}
15+
R15:T<1>1<7>{:[1]T}
16+
S35:T<1>1<14>G:gps:M:locate{:[1]N:[2]N}
17+
R42:T<1>1<33>{:[1]T:[2][-12]:[3][70]:[4][-19]}
18+
S43:T<1>1<13>io.write(...){:[1]<11>Position is}
19+
R15:T<1>1<7>{:[1]T}
20+
S32:T<1>1<13>io.write(...){:[1]<1> }
21+
R15:T<1>1<7>{:[1]T}
22+
S46:T<1>1<13>io.write(...){:[1]<14>(-12, 70, -19)}
23+
R15:T<1>1<7>{:[1]T}
24+
S32:T<1>1<13>io.write(...){:[1]<1>
25+
}
26+
R15:T<1>1<7>{:[1]T}
27+
S58:T<1>1<13>io.write(...){:[1]<26>Test finished successfully}
28+
R15:T<1>1<7>{:[1]T}
29+
S32:T<1>1<13>io.write(...){:[1]<1>
30+
}
31+
R15:T<1>1<7>{:[1]T}
32+
S2:CN

0 commit comments

Comments
 (0)