local Direction = require("lib.direction") local TurtleController = require("controller.turtle_controller") ---@class TestingController ---@field controller TurtleController local TestingController = {} TestingController.__index = TestingController ---@return TestingController function TestingController:Create() local t = {} setmetatable(t, TestingController) t.controller = TurtleController:Create() return t end ----------------------------------------------------------------------------------------------- -- Behavior Methods ----------------------------------------------------------------------------------------------- function TestingController:TestRelativeMovementWithRelativeRotation() print("Testing relative movement with relative rotation...") -- N: BotCenter self.controller:MoveRelative(3) self.controller:TurnRelative(1) -- E: TopCenter self.controller:MoveRelative(3) self.controller:TurnRelative(2) -- W: TopRight self.controller:MoveRelative(3) self.controller:TurnRelative(10) -- E: TopCenter self.controller:MoveRelative(3) self.controller:TurnRelative(-3) -- S: TopRight self.controller:MoveRelative(3) self.controller:TurnRelative(1) -- W: BotRight self.controller:MoveRelative(3) self.controller:TurnRelative(1) -- N: BotCenter print("The turtle should be in its original location.") print("Press Enter to continue") _ = io.read() end function TestingController:TestRelativeMovementWithAbsoluteRotation() print("Testing relative movement with absolute rotation...") -- N: BotCenter self.controller:MoveRelative(3) self.controller:TurnToDirection(Direction.EAST) -- E: TopCenter self.controller:MoveRelative(3) self.controller:TurnToDirection(Direction.WEST) -- W: TopRight self.controller:MoveRelative(3) self.controller:TurnToDirection(Direction.EAST) -- E: TopCenter self.controller:MoveRelative(3) self.controller:TurnToDirection(Direction.SOUTH) -- S: TopRight self.controller:MoveRelative(3) self.controller:TurnToDirection(Direction.WEST) -- W: BotRight self.controller:MoveRelative(3) self.controller:TurnToDirection(Direction.NORTH) -- N: BotCenter print("The turtle should be in its original location.") print("Press Enter to continue") _ = io.read() end function TestingController:TestAbsoluteMovementWithoutStack() print("Testing absolute movement without stack...") -- N: BotCenter self.controller:MoveToPosition(0, 0, 3, Direction.EAST) -- E: TopCenter _ = io.read() self.controller:MoveToPosition(3, 0, 3, Direction.WEST) -- W: TopRight _ = io.read() self.controller:MoveToPosition(0, 0, 3, Direction.EAST) -- E: TopCenter _ = io.read() self.controller:MoveToPosition(3, 0, 3, Direction.SOUTH) -- S: TopRight _ = io.read() self.controller:MoveToPosition(3, 0, 0, Direction.WEST) -- W: BotRight _ = io.read() self.controller:MoveToPosition(0, 0, 0, Direction.NORTH) -- N: BotCenter print("The turtle should be in its original location.") print("Press Enter to continue") _ = io.read() end function TestingController:TestAbsoluteMovementWithStack() print("Testing absolute movement with stack...") -- N: BotCenter self.controller:MoveToPosition(0, 0, 3, Direction.EAST) -- E: TopCenter _ = io.read() self.controller:MoveBack() -- N: BotCenter _ = io.read() self.controller:MoveToPosition(3, 0, 3, Direction.WEST) -- W: TopRight _ = io.read() self.controller:MoveBack() -- N: BotCenter print("The turtle should be in its original location.") print("Press Enter to continue") _ = io.read() end function TestingController:TestUnstocking() print("Testing inventory unloading...") print("Please fill multiple inventory slots with items.") _ = io.read() self.controller:MoveToPosition(3, 0, 3, Direction.WEST) _ = io.read() self.controller:UnstockIfFull(true) _ = io.read() self.controller:MoveBack() print("The turtle should be in its original location.") print("Press Enter to continue") _ = io.read() end function TestingController:TestRefueling() print("Testing refueling...") print("Please fill multiple inventory slots with items.") _ = io.read() self.controller:MoveToPosition(3, 0, 3, Direction.WEST) _ = io.read() self.controller:RefuelIfEmpty(true) _ = io.read() self.controller:MoveBack() print("The turtle should be in its original location.") print("Press Enter to continue") _ = io.read() end ----------------------------------------------------------------------------------------------- -- Main Method ----------------------------------------------------------------------------------------------- function TestingController:Run() self.controller:Configure() self.controller:DisableMining() print("There are multiple tests available:") print("1: Relative movement with relative rotation") print("2: Relative movement with absolute rotation") print("3: Absolute movement without stack") print("4: Absolute movement with stack") print("5: All movement tests") print("6: Unloading") print("7: Refueling") print("8: All non-movement tests") print("9: All tests") local choice = 0 while choice < 1 or choice > 9 do print("Choose a test by entering its number:") choice = tonumber(io.read()) or 0 end if choice == 1 then self:TestRelativeMovementWithRelativeRotation() elseif choice == 2 then self:TestRelativeMovementWithAbsoluteRotation() elseif choice == 3 then self:TestAbsoluteMovementWithoutStack() elseif choice == 4 then self:TestAbsoluteMovementWithStack() elseif choice == 5 then self:TestRelativeMovementWithRelativeRotation() self:TestRelativeMovementWithAbsoluteRotation() self:TestAbsoluteMovementWithoutStack() self:TestAbsoluteMovementWithStack() elseif choice == 6 then self:TestUnstocking() elseif choice == 7 then self:TestRefueling() elseif choice == 8 then self:TestUnstocking() self:TestRefueling() elseif choice == 9 then self:TestRelativeMovementWithRelativeRotation() self:TestRelativeMovementWithAbsoluteRotation() self:TestAbsoluteMovementWithoutStack() self:TestAbsoluteMovementWithStack() self:TestUnstocking() self:TestRefueling() end end return TestingController