Skip to content

Commit 2c4c172

Browse files
authored
Merge pull request #610 from dogboy21/blockreader-tests
Add game tests for Block Reader peripheral (related to #562)
2 parents 233a194 + 7f9af5c commit 2c4c172

3 files changed

Lines changed: 199 additions & 0 deletions

File tree

src/testMod/kotlin/de/srendi/advancedperipherals/test/PeripheralTest.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ class PeripheralTest {
3232
thenComputerOk();
3333
}
3434

35+
@GameTest
36+
fun blockReader(context: GameTestHelper) = context.sequence {
37+
thenComputerOk();
38+
}
39+
3540
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
--- Advanced Peripherals Block Reader tests
3+
--- Covers `getBlockName`, `getBlockData`, `getBlockStates`, `isTileEntity`
4+
---
5+
6+
function tableLength(T)
7+
local count = 0
8+
for _ in pairs(T) do count = count + 1 end
9+
return count
10+
end
11+
12+
-- Test Block Reader functions on a simple block
13+
test.eq("blockReader", peripheral.getType("left"), "Peripheral should be blockReader")
14+
simpleReader = peripheral.wrap("left")
15+
test.assert(simpleReader, "Peripheral not found")
16+
17+
test.eq("minecraft:polished_andesite", simpleReader.getBlockName(), "Block Name should be polished_andesite")
18+
test.eq(nil, simpleReader.getBlockData(), "Block Data should be nil")
19+
test.assert(not simpleReader.isTileEntity(), "Block should not be a TileEntity")
20+
test.eq(0, tableLength(simpleReader.getBlockStates()), "Block State should be empty")
21+
22+
-- Test Block Reader functions on a stair block
23+
test.eq("blockReader", peripheral.getType("back"), "Peripheral should be blockReader")
24+
stairReader = peripheral.wrap("back")
25+
test.assert(stairReader, "Peripheral not found")
26+
27+
test.eq("minecraft:polished_andesite_stairs", stairReader.getBlockName(), "Block Name should be polished_andesite")
28+
test.eq(nil, stairReader.getBlockData(), "Block Data should be nil")
29+
test.assert(not stairReader.isTileEntity(), "Block should not be a TileEntity")
30+
test.eq(4, tableLength(stairReader.getBlockStates()), "Block State should not be empty")
31+
32+
test.eq("east", stairReader.getBlockStates()["facing"], "Stair Facing should be east")
33+
test.eq("bottom", stairReader.getBlockStates()["half"], "Stair Half should be bottom")
34+
test.eq("straight", stairReader.getBlockStates()["shape"], "Stair Shape should be straight")
35+
test.assert(not stairReader.getBlockStates()["waterlogged"], "Stair Waterlogged should be false")
36+
37+
-- Test Block Reader functions on a sign block
38+
test.eq("blockReader", peripheral.getType("right"), "Peripheral should be blockReader")
39+
signReader = peripheral.wrap("right")
40+
test.assert(signReader, "Peripheral not found")
41+
42+
test.eq("minecraft:oak_sign", signReader.getBlockName(), "Block Name should be polished_andesite")
43+
test.neq(nil, signReader.getBlockData(), "Block Data should not be nil")
44+
test.assert(signReader.isTileEntity(), "Block should be a TileEntity")
45+
test.eq(2, tableLength(signReader.getBlockStates()), "Block State should not be empty")
46+
47+
test.eq(4, signReader.getBlockStates()["rotation"], "Sign Rotation should be 4")
48+
test.assert(not signReader.getBlockStates()["waterlogged"], "Sign Waterlogged should be false")
49+
50+
test.eq("black", signReader.getBlockData()["Color"], "Sign Color should be black")
51+
test.eq("{\"text\":\"this\"}", signReader.getBlockData()["Text1"], "Sign Text1 should be 'this'")
52+
test.eq("{\"text\":\"is a\"}", signReader.getBlockData()["Text2"], "Sign Text2 should be 'is a'")
53+
test.eq("{\"text\":\"test\"}", signReader.getBlockData()["Text3"], "Sign Text3 should be 'test'")
54+
test.eq("{\"text\":\"sign\"}", signReader.getBlockData()["Text4"], "Sign Text4 should be 'sign'")
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
{
2+
DataVersion: 3120,
3+
size: [5, 5, 5],
4+
data: [
5+
{pos: [0, 0, 0], state: "minecraft:polished_andesite"},
6+
{pos: [0, 0, 1], state: "minecraft:polished_andesite"},
7+
{pos: [0, 0, 2], state: "minecraft:polished_andesite"},
8+
{pos: [0, 0, 3], state: "minecraft:polished_andesite"},
9+
{pos: [0, 0, 4], state: "minecraft:polished_andesite"},
10+
{pos: [1, 0, 0], state: "minecraft:polished_andesite"},
11+
{pos: [1, 0, 1], state: "minecraft:polished_andesite"},
12+
{pos: [1, 0, 2], state: "minecraft:polished_andesite"},
13+
{pos: [1, 0, 3], state: "minecraft:polished_andesite"},
14+
{pos: [1, 0, 4], state: "minecraft:polished_andesite"},
15+
{pos: [2, 0, 0], state: "minecraft:polished_andesite"},
16+
{pos: [2, 0, 1], state: "minecraft:polished_andesite"},
17+
{pos: [2, 0, 2], state: "minecraft:polished_andesite"},
18+
{pos: [2, 0, 3], state: "minecraft:polished_andesite"},
19+
{pos: [2, 0, 4], state: "minecraft:polished_andesite"},
20+
{pos: [3, 0, 0], state: "minecraft:polished_andesite"},
21+
{pos: [3, 0, 1], state: "minecraft:polished_andesite"},
22+
{pos: [3, 0, 2], state: "minecraft:polished_andesite"},
23+
{pos: [3, 0, 3], state: "minecraft:polished_andesite"},
24+
{pos: [3, 0, 4], state: "minecraft:polished_andesite"},
25+
{pos: [4, 0, 0], state: "minecraft:polished_andesite"},
26+
{pos: [4, 0, 1], state: "minecraft:polished_andesite"},
27+
{pos: [4, 0, 2], state: "minecraft:polished_andesite"},
28+
{pos: [4, 0, 3], state: "minecraft:polished_andesite"},
29+
{pos: [4, 0, 4], state: "minecraft:polished_andesite"},
30+
{pos: [0, 1, 0], state: "minecraft:air"},
31+
{pos: [0, 1, 1], state: "minecraft:air"},
32+
{pos: [0, 1, 2], state: "minecraft:air"},
33+
{pos: [0, 1, 3], state: "minecraft:air"},
34+
{pos: [0, 1, 4], state: "minecraft:air"},
35+
{pos: [1, 1, 0], state: "minecraft:air"},
36+
{pos: [1, 1, 1], state: "minecraft:air"},
37+
{pos: [1, 1, 2], state: "minecraft:air"},
38+
{pos: [1, 1, 3], state: "minecraft:air"},
39+
{pos: [1, 1, 4], state: "minecraft:air"},
40+
{pos: [2, 1, 0], state: "minecraft:air"},
41+
{pos: [2, 1, 1], state: "advancedperipherals:block_reader{orientation:up_east}", nbt: {ForgeCaps: {}, ForgeData: {CustomName: "[Block Reader]"}, Items: [], id: "advancedperipherals:block_reader"}},
42+
{pos: [2, 1, 2], state: "computercraft:computer_advanced{facing:west,state:off}", nbt: {ComputerId: 0, ForgeCaps: {}, Label: "peripheraltest.blockreader", On: 1b, id: "computercraft:computer_advanced"}},
43+
{pos: [2, 1, 3], state: "advancedperipherals:block_reader{orientation:up_east}", nbt: {ForgeCaps: {}, ForgeData: {CustomName: "[Block Reader]"}, Items: [], id: "advancedperipherals:block_reader"}},
44+
{pos: [2, 1, 4], state: "minecraft:air"},
45+
{pos: [3, 1, 0], state: "minecraft:air"},
46+
{pos: [3, 1, 1], state: "minecraft:air"},
47+
{pos: [3, 1, 2], state: "advancedperipherals:block_reader{orientation:up_east}", nbt: {ForgeCaps: {}, ForgeData: {CustomName: "[Block Reader]"}, Items: [], id: "advancedperipherals:block_reader"}},
48+
{pos: [3, 1, 3], state: "minecraft:air"},
49+
{pos: [3, 1, 4], state: "minecraft:air"},
50+
{pos: [4, 1, 0], state: "minecraft:air"},
51+
{pos: [4, 1, 1], state: "minecraft:air"},
52+
{pos: [4, 1, 2], state: "minecraft:air"},
53+
{pos: [4, 1, 3], state: "minecraft:air"},
54+
{pos: [4, 1, 4], state: "minecraft:air"},
55+
{pos: [0, 2, 0], state: "minecraft:air"},
56+
{pos: [0, 2, 1], state: "minecraft:air"},
57+
{pos: [0, 2, 2], state: "minecraft:air"},
58+
{pos: [0, 2, 3], state: "minecraft:air"},
59+
{pos: [0, 2, 4], state: "minecraft:air"},
60+
{pos: [1, 2, 0], state: "minecraft:air"},
61+
{pos: [1, 2, 1], state: "minecraft:air"},
62+
{pos: [1, 2, 2], state: "minecraft:air"},
63+
{pos: [1, 2, 3], state: "minecraft:air"},
64+
{pos: [1, 2, 4], state: "minecraft:air"},
65+
{pos: [2, 2, 0], state: "minecraft:air"},
66+
{pos: [2, 2, 1], state: "minecraft:polished_andesite"},
67+
{pos: [2, 2, 2], state: "minecraft:air"},
68+
{pos: [2, 2, 3], state: "minecraft:oak_sign{rotation:4,waterlogged:false}", nbt: {Color: "black", ForgeCaps: {}, GlowingText: 0b, Text1: '{"text":"this"}', Text2: '{"text":"is a"}', Text3: '{"text":"test"}', Text4: '{"text":"sign"}', id: "minecraft:sign"}},
69+
{pos: [2, 2, 4], state: "minecraft:air"},
70+
{pos: [3, 2, 0], state: "minecraft:air"},
71+
{pos: [3, 2, 1], state: "minecraft:air"},
72+
{pos: [3, 2, 2], state: "minecraft:polished_andesite_stairs{facing:east,half:bottom,shape:straight,waterlogged:false}"},
73+
{pos: [3, 2, 3], state: "minecraft:air"},
74+
{pos: [3, 2, 4], state: "minecraft:air"},
75+
{pos: [4, 2, 0], state: "minecraft:air"},
76+
{pos: [4, 2, 1], state: "minecraft:air"},
77+
{pos: [4, 2, 2], state: "minecraft:air"},
78+
{pos: [4, 2, 3], state: "minecraft:air"},
79+
{pos: [4, 2, 4], state: "minecraft:air"},
80+
{pos: [0, 3, 0], state: "minecraft:air"},
81+
{pos: [0, 3, 1], state: "minecraft:air"},
82+
{pos: [0, 3, 2], state: "minecraft:air"},
83+
{pos: [0, 3, 3], state: "minecraft:air"},
84+
{pos: [0, 3, 4], state: "minecraft:air"},
85+
{pos: [1, 3, 0], state: "minecraft:air"},
86+
{pos: [1, 3, 1], state: "minecraft:air"},
87+
{pos: [1, 3, 2], state: "minecraft:air"},
88+
{pos: [1, 3, 3], state: "minecraft:air"},
89+
{pos: [1, 3, 4], state: "minecraft:air"},
90+
{pos: [2, 3, 0], state: "minecraft:air"},
91+
{pos: [2, 3, 1], state: "minecraft:air"},
92+
{pos: [2, 3, 2], state: "minecraft:air"},
93+
{pos: [2, 3, 3], state: "minecraft:air"},
94+
{pos: [2, 3, 4], state: "minecraft:air"},
95+
{pos: [3, 3, 0], state: "minecraft:air"},
96+
{pos: [3, 3, 1], state: "minecraft:air"},
97+
{pos: [3, 3, 2], state: "minecraft:air"},
98+
{pos: [3, 3, 3], state: "minecraft:air"},
99+
{pos: [3, 3, 4], state: "minecraft:air"},
100+
{pos: [4, 3, 0], state: "minecraft:air"},
101+
{pos: [4, 3, 1], state: "minecraft:air"},
102+
{pos: [4, 3, 2], state: "minecraft:air"},
103+
{pos: [4, 3, 3], state: "minecraft:air"},
104+
{pos: [4, 3, 4], state: "minecraft:air"},
105+
{pos: [0, 4, 0], state: "minecraft:air"},
106+
{pos: [0, 4, 1], state: "minecraft:air"},
107+
{pos: [0, 4, 2], state: "minecraft:air"},
108+
{pos: [0, 4, 3], state: "minecraft:air"},
109+
{pos: [0, 4, 4], state: "minecraft:air"},
110+
{pos: [1, 4, 0], state: "minecraft:air"},
111+
{pos: [1, 4, 1], state: "minecraft:air"},
112+
{pos: [1, 4, 2], state: "minecraft:air"},
113+
{pos: [1, 4, 3], state: "minecraft:air"},
114+
{pos: [1, 4, 4], state: "minecraft:air"},
115+
{pos: [2, 4, 0], state: "minecraft:air"},
116+
{pos: [2, 4, 1], state: "minecraft:air"},
117+
{pos: [2, 4, 2], state: "minecraft:air"},
118+
{pos: [2, 4, 3], state: "minecraft:air"},
119+
{pos: [2, 4, 4], state: "minecraft:air"},
120+
{pos: [3, 4, 0], state: "minecraft:air"},
121+
{pos: [3, 4, 1], state: "minecraft:air"},
122+
{pos: [3, 4, 2], state: "minecraft:air"},
123+
{pos: [3, 4, 3], state: "minecraft:air"},
124+
{pos: [3, 4, 4], state: "minecraft:air"},
125+
{pos: [4, 4, 0], state: "minecraft:air"},
126+
{pos: [4, 4, 1], state: "minecraft:air"},
127+
{pos: [4, 4, 2], state: "minecraft:air"},
128+
{pos: [4, 4, 3], state: "minecraft:air"},
129+
{pos: [4, 4, 4], state: "minecraft:air"}
130+
],
131+
entities: [],
132+
palette: [
133+
"minecraft:polished_andesite",
134+
"minecraft:air",
135+
"minecraft:polished_andesite_stairs{facing:east,half:bottom,shape:straight,waterlogged:false}",
136+
"advancedperipherals:block_reader{orientation:up_east}",
137+
"computercraft:computer_advanced{facing:west,state:off}",
138+
"minecraft:oak_sign{rotation:4,waterlogged:false}"
139+
]
140+
}

0 commit comments

Comments
 (0)