Skip to content

Commit 233a194

Browse files
committed
Added me transfer tests to test the integrity of our item export and import tests
1 parent 578ccd8 commit 233a194

5 files changed

Lines changed: 376 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
@@ -27,4 +27,9 @@ class PeripheralTest {
2727
thenComputerOk();
2828
}
2929

30+
@GameTest(timeoutTicks = 300)
31+
fun meTransfer(context: GameTestHelper) = context.sequence {
32+
thenComputerOk();
33+
}
34+
3035
}

src/testMod/resources/data/advancedperipheralstest/computer/tests/peripheraltest.mecrafting.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
---
2+
--- Advanced Peripherals ME Bridge crafting tests
3+
--- Covers `isConnected`, `getEnergyUsage`, `isItemCrafting`, `isItemCraftable`,
4+
--- `getItem`, `craftItem`, `listCraftableFluid`, `craftFluid`, `getCraftingCPUs`,
5+
---
6+
17
sleep(4)
28
bridge = peripheral.wrap("bottom")
39
test.assert(bridge, "Peripheral not found")

src/testMod/resources/data/advancedperipheralstest/computer/tests/peripheraltest.mestorage.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
---
2+
--- Advanced Peripherals ME Bridge storage tests
3+
--- Covers `isConnected`, `getEnergyUsage`, `getMaxEnergyStorage`, `getEnergyStorage`,
4+
--- `getTotalItemStorage`, `getTotalFluidStorage`, `getUsedItemStorage`, `getUsedFluidStorage`,
5+
--- `getAvailableItemStorage`, `getAvailableFluidStorage`, `listCells`,
6+
---
7+
18
sleep(4)
29
bridge = peripheral.wrap("bottom")
310
test.assert(bridge, "Peripheral not found")
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
--- Advanced Peripherals ME Bridge transfer tests
3+
--- Covers `isConnected`, `getEnergyUsage`, `getItem`, `exportItemToPeripheral`, `exportItem`,
4+
--- `importItem`, `importItemFromPeripheral`
5+
---
6+
7+
sleep(4)
8+
bridge = peripheral.wrap("meBridge_3")
9+
chest = peripheral.wrap("minecraft:chest_2")
10+
test.assert(bridge, "Peripheral not found")
11+
test.assert(chest, "Chest not found")
12+
13+
isOnline = bridge.isConnected()
14+
test.assert(isOnline, "Bridge is not connected/system is not online")
15+
16+
energyUsage = bridge.getEnergyUsage()
17+
test.assert(energyUsage > 17, tostring(energyUsage) .. " Consumption does not seem right")
18+
19+
planksFilter = {name="minecraft:oak_planks", count=5}
20+
logFilter = {name="minecraft:oak_log", count=8}
21+
22+
exported, err = bridge.exportItemToPeripheral(planksFilter, peripheral.getName(chest))
23+
test.assert(exported == 5, "Export failed ".. (err or ""))
24+
25+
planksItem = bridge.getItem(planksFilter)
26+
test.assert(planksItem.amount == 251, "We should have 251 planks")
27+
28+
chestPlanks = nil
29+
for slot, item in pairs(chest.list()) do
30+
if item.name == "minecraft:oak_planks" then
31+
chestPlanks = item
32+
end
33+
end
34+
35+
test.assert(chestPlanks, "Planks not found in chest")
36+
test.assert(chestPlanks.count == 5, "We should have 5 planks in the chest")
37+
38+
exported, err = bridge.exportItem(planksFilter, "front")
39+
test.assert(exported == 5, "Export failed ".. (err or ""))
40+
41+
planksItem = bridge.getItem(planksFilter)
42+
test.assert(planksItem.amount == 246, "We should have 246 planks")
43+
44+
for slot, item in pairs(chest.list()) do
45+
if item.name == "minecraft:oak_planks" then
46+
chestPlanks = item
47+
end
48+
end
49+
50+
test.assert(chestPlanks, "Planks not found in chest")
51+
test.assert(chestPlanks.count == 10, "We should have 5 planks in the chest")
52+
53+
imported, err = bridge.importItemFromPeripheral(logFilter, peripheral.getName(chest))
54+
test.assert(imported == 8, "import failed ".. (err or ""))
55+
56+
logsItem = bridge.getItem(logFilter)
57+
test.assert(logsItem.amount == 264, "We should have 264 logs")
58+
59+
chestLogs = nil
60+
for slot, item in pairs(chest.list()) do
61+
if item.name == "minecraft:oak_log" then
62+
chestLogs = item
63+
end
64+
end
65+
66+
test.assert(chestLogs, "Logs not found in chest")
67+
test.assert(chestLogs.count == 56, "We should have 56 logs in the chest")
68+
69+
imported, err = bridge.importItem(logFilter, "south")
70+
test.assert(imported == 8, "import failed ".. (err or ""))
71+
72+
logsItem = bridge.getItem(logFilter)
73+
test.assert(logsItem.amount == 272, "We should have 272 logs")
74+
75+
chestLogs = nil
76+
for slot, item in pairs(chest.list()) do
77+
if item.name == "minecraft:oak_log" then
78+
chestLogs = item
79+
end
80+
end
81+
82+
test.assert(chestLogs, "Logs not found in chest")
83+
test.assert(chestLogs.count == 48, "We should have 48 logs in the chest")

0 commit comments

Comments
 (0)