|
29 | 29 | ---@field equal function |
30 | 30 | assert = assert |
31 | 31 |
|
32 | | --- functions provided by busted, only available in the global scope |
33 | | -describe = describe |
34 | | -it = it |
35 | | -setup = setup |
36 | | -before_each = before_each |
| 32 | +-- installs the other suits |
| 33 | +if not pcall(function () io.open("./suits/vector/vector.lua", "r"):close() end) then |
| 34 | + print("Downloading TestSuite-lib") |
| 35 | + local http = require("socket.http") |
| 36 | + local url = "https://raw.githubusercontent.com/mc-cc-scripts/TestSuite-lib/master/installSuit.lua" -- URL of the installer |
| 37 | + local body, statusCode = http.request(url) |
| 38 | + if statusCode == 200 then |
| 39 | + local loader |
| 40 | + if _VERSION == "Lua 5.1" then |
| 41 | + loader = loadstring |
| 42 | + else |
| 43 | + loader = load |
| 44 | + end |
| 45 | + local installScript = loader(body)().install() |
| 46 | + else |
| 47 | + error("Failed to download TestSuite-lib: " .. tostring(statusCode)) |
| 48 | + end |
| 49 | +end |
| 50 | + |
| 51 | +-- load the other suits |
| 52 | +local vector = require("./suits/vector/vector") |
| 53 | +local deepCopy = require("./suits/helperFunctions/helperFunctions").deepCopy |
| 54 | + |
| 55 | +print(deepCopy({a = 1, b = 2, c = 3})) |
37 | 56 |
|
38 | 57 | local turtleEmulator = require("../turtleEmulator") |
| 58 | +turtleEmulator:init(vector, deepCopy) |
| 59 | +local peripheral = require("../peripheral") |
39 | 60 | describe("Disabled Movement", function() |
40 | 61 | local turtle |
41 | 62 | setup(function() |
@@ -742,29 +763,72 @@ describe("Place", function() |
742 | 763 | assert.are.equal("minecraft:water", block.item.name) |
743 | 764 | end) |
744 | 765 | end) |
745 | | -describe("Chest", function() |
| 766 | +describe("peripherals", function() |
746 | 767 | local turtle |
747 | | - describe("Create Chests", function () |
748 | | - it("Create Chests", function () |
749 | | - turtleEmulator:clearBlocks() |
750 | | - turtleEmulator:clearTurtles() |
751 | | - turtleEmulator:createBlock({ item = {name = "minecraft:chest"}, position = { x = 1, y = 0, z = 0 } }) |
752 | | - local block = turtleEmulator:getBlock({ x = 1, y = 0, z = 0 }) |
753 | | - turtleEmulator:addInventoryToBlock(block.position) |
754 | | - block.inventory:addItemToInventory({ name = "minecraft:stone", count = 64, maxcount = 64 }) |
755 | | - |
756 | | - block.inventory:select(2) |
757 | | - |
758 | | - turtleEmulator:createBlock({ item = {name = "minecraft:chest"}, position = { x = 2, y = 0, z = 0 } }) |
759 | | - local block2 = turtleEmulator:getBlock({ x = 2, y = 0, z = 0 }) |
760 | | - turtleEmulator:addInventoryToBlock(block2.position) |
761 | | - block2.inventory:select(2) |
762 | | - assert.is_true(block2.inventory:addItemToInventory({ name = "minecraft:stone", count = 64, maxcount = 64 }, 2)) |
763 | | - assert.are.equal(64, block.inventory:getItemCount(1)) |
764 | | - assert.are.equal(0, block.inventory:getItemCount(2)) |
765 | | - assert.are.equal(0, block2.inventory:getItemCount(1)) |
766 | | - assert.are.equal(64, block2.inventory:getItemCount()) -- slot 2 |
767 | | - assert.are.equal(64, block2.inventory:getItemCount(2)) |
768 | | - end) |
| 768 | + before_each(function() |
| 769 | + turtleEmulator:clearBlocks() |
| 770 | + turtleEmulator:clearTurtles() |
| 771 | + turtle = turtleEmulator:createTurtle() |
| 772 | + end) |
| 773 | + it("Create Chests", function () |
| 774 | + turtleEmulator:clearBlocks() |
| 775 | + turtleEmulator:clearTurtles() |
| 776 | + local block = turtleEmulator:createBlock({ item = {name = "minecraft:chest"}, position = { x = 1, y = 0, z = 0 } }) |
| 777 | + local chest = turtleEmulator:addInventoryToBlock(block.position) |
| 778 | + chest:addItemToInventory({ name = "minecraft:stone", count = 64, maxcount = 64 }) |
| 779 | + |
| 780 | + chest:select(2) |
| 781 | + |
| 782 | + local block2 = turtleEmulator:createBlock({ item = {name = "minecraft:chest"}, position = { x = 2, y = 0, z = 0 } }) |
| 783 | + local chest2 = turtleEmulator:addInventoryToBlock({ x = 2, y = 0, z = 0 }) |
| 784 | + chest2:select(2) |
| 785 | + assert.is_true(chest2:addItemToInventory({ name = "minecraft:stone", count = 64, maxcount = 64 }, 2)) |
| 786 | + assert.are.equal(64, chest:getItemCount(1)) |
| 787 | + assert.are.equal(0, chest:getItemCount(2)) |
| 788 | + assert.are.equal(0, chest2.getItemCount(1)) |
| 789 | + assert.are.equal(64, chest2.getItemCount()) -- slot 2 |
| 790 | + assert.are.equal(64, chest2.getItemCount(2)) |
| 791 | + -- check the ORIGINAL block in the emulator |
| 792 | + -- since the return is just a proxy |
| 793 | + assert.are.equal(64, block2.peripheralActions[2].count) |
| 794 | + end) |
| 795 | + it("isPresent", function() |
| 796 | + turtle.position = { x = 5, y = 0, z = 5 } |
| 797 | + local p = peripheral.linkToTurtle(turtle) |
| 798 | + |
| 799 | + local block = turtleEmulator:createBlock({ item = {name = "minecraft:chest"}, position = { x = 5, y = 0, z = 6 } }) |
| 800 | + turtleEmulator:addInventoryToBlock(block.position) |
| 801 | + assert.is_true(p.isPresent("right")) |
| 802 | + assert.is_false(p.isPresent("front")) |
| 803 | + assert.is_false(p.isPresent("left")) |
| 804 | + assert.is_false(p.isPresent("back")) |
| 805 | + assert.is_false(p.isPresent("up")) |
| 806 | + assert.is_false(p.isPresent("down")) |
| 807 | + local block2 = turtleEmulator:createBlock({ item = {name = "minecraft:chest"}, position = { x = 6, y = 0, z = 5 } }) |
| 808 | + turtleEmulator:addInventoryToBlock(block2.position) |
| 809 | + assert.is_true(p.isPresent("front")) |
| 810 | + assert.is_true(p.isPresent("right")) |
| 811 | + assert.is_false(p.isPresent("left")) |
| 812 | + assert.is_false(p.isPresent("back")) |
| 813 | + turtle.turnRight() |
| 814 | + assert.is_true(p.isPresent("right")) |
| 815 | + assert.is_true(p.isPresent("back")) |
| 816 | + assert.is_false(p.isPresent("left")) |
| 817 | + assert.is_false(p.isPresent("front")) |
| 818 | + turtle.turnRight() |
| 819 | + assert.is_true(p.isPresent("back")) |
| 820 | + assert.is_true(p.isPresent("left")) |
| 821 | + assert.is_false(p.isPresent("front")) |
| 822 | + assert.is_false(p.isPresent("right")) |
| 823 | + turtle.turnRight() |
| 824 | + assert.is_true(p.isPresent("left")) |
| 825 | + assert.is_true(p.isPresent("front")) |
| 826 | + assert.is_false(p.isPresent("right")) |
| 827 | + assert.is_false(p.isPresent("back")) |
| 828 | + turtle.turnRight() |
| 829 | + assert.is_true(p.isPresent("front")) |
| 830 | + assert.is_true(p.isPresent("right")) |
| 831 | + assert.is_false(p.isPresent("left")) |
| 832 | + assert.is_false(p.isPresent("back")) |
769 | 833 | end) |
770 | 834 | end) |
0 commit comments