|
24 | 24 | ---@field True function |
25 | 25 | ---@field False function |
26 | 26 | ---@field has_error function |
| 27 | +---@field is_false function |
27 | 28 | ---@field is_true function |
28 | 29 | ---@field equal function |
29 | 30 | assert = assert |
@@ -217,6 +218,7 @@ describe("multiple Turtles", function() |
217 | 218 | local turtle1 |
218 | 219 | local turtle2 |
219 | 220 | setup(function() |
| 221 | + turtleEmulator:clearTurtles() |
220 | 222 | turtle1 = turtleEmulator:createTurtle() |
221 | 223 | turtle2 = turtleEmulator:createTurtle() |
222 | 224 | turtle1["canMoveToCheck"] = function() |
@@ -297,7 +299,7 @@ describe("InventoryTests", function() |
297 | 299 | describe("Adding Items for Testing", function() |
298 | 300 | before_each(function() |
299 | 301 | turtle = turtleEmulator:createTurtle() |
300 | | - turtle:addItemToInventory({ name = "minecraft:coal", count = 64, maxcount = 64, fuelgain = 64 }, 1) |
| 302 | + turtle:addItemToInventory({ name = "minecraft:coal", count = 64, maxcount = 64, fuelgain = 16 }, 1) |
301 | 303 | turtle:addItemToInventory({ name = "minecraft:wood_plank", count = 64, maxcount = 64, fuelgain = 8 }, 2) |
302 | 304 | end) |
303 | 305 | it("Throw Error when adding Item to full slot", function() |
@@ -357,10 +359,36 @@ describe("InventoryTests", function() |
357 | 359 | assert.are.equal(0, turtle.getItemCount(6)) |
358 | 360 | end) |
359 | 361 | end) |
| 362 | + describe("Refueling", function () |
| 363 | + local fuelGainPerCoal = 16 |
| 364 | + before_each(function() |
| 365 | + turtle = turtleEmulator:createTurtle() |
| 366 | + turtle:addItemToInventory({ name = "minecraft:coal", count = 64, maxcount = 64, fuelgain = fuelGainPerCoal }, 1) |
| 367 | + turtle:addItemToInventory({ name = "minecraft:wood_plank", count = 64, maxcount = 64, fuelgain = 8 }, 2) |
| 368 | + end) |
| 369 | + it("Refuel with coal", function() |
| 370 | + turtle.select(1) |
| 371 | + local succ = turtle.refuel() |
| 372 | + assert.is_true(succ) |
| 373 | + assert.are.equal(fuelGainPerCoal, turtle.getFuelLevel()) |
| 374 | + assert.are.equal(63, turtle.getItemCount()) |
| 375 | + succ = turtle.refuel(63) |
| 376 | + assert.is_true(succ) |
| 377 | + assert.are.equal(fuelGainPerCoal * 64, turtle.getFuelLevel()) |
| 378 | + assert.are.equal(0, turtle.getItemCount()) |
| 379 | + local succ = turtle.refuel() |
| 380 | + assert.is_false(succ) |
| 381 | + turtle.select(3) |
| 382 | + turtle:addItemToInventory({ name = "minecraft:stone", count = 64, maxcount = 64 }, 3) |
| 383 | + succ = turtle.refuel() |
| 384 | + assert.is_false(succ) |
| 385 | + assert.are.equal(fuelGainPerCoal * 64, turtle.getFuelLevel()) |
| 386 | + end) |
| 387 | + end) |
360 | 388 | describe("Remaining Inventory Tests", function() |
361 | 389 | before_each(function() |
362 | 390 | turtle = turtleEmulator:createTurtle() |
363 | | - turtle:addItemToInventory({ name = "minecraft:coal", count = 64, maxcount = 64, fuelgain = 64 }, 1) |
| 391 | + turtle:addItemToInventory({ name = "minecraft:coal", count = 64, maxcount = 64, fuelgain = 16 }, 1) |
364 | 392 | turtle:addItemToInventory({ name = "minecraft:wood_plank", count = 64, maxcount = 64, fuelgain = 8 }, 2) |
365 | 393 | turtle:getSocket() |
366 | 394 | end) |
@@ -409,3 +437,111 @@ describe("InventoryTests", function() |
409 | 437 | end) |
410 | 438 | end) |
411 | 439 | end) |
| 440 | +describe("Equipment", function () |
| 441 | + ---@type TurtleProxy |
| 442 | + local turtle |
| 443 | + before_each(function() |
| 444 | + turtle = turtleEmulator:createTurtle() |
| 445 | + turtle:addItemToInventory({ name = "minecraft:coal", count = 64, maxcount = 64, fuelgain = 16 }, 1) |
| 446 | + turtle:addItemToInventory({ name = "minecraft:wood_plank", count = 64, maxcount = 64, fuelgain = 8 }, 2) |
| 447 | + end) |
| 448 | + it("Equip non Equipment", function() |
| 449 | + local succ = turtle.equipLeft() |
| 450 | + assert.is_false(succ) |
| 451 | + end) |
| 452 | + it("Equip Equipment", function() |
| 453 | + turtle:addItemToInventory({ name = "CCTweaked:chat_box", count = 2, maxcount = 2, equipable = true}, 3) |
| 454 | + turtle:select(3) |
| 455 | + local succ = turtle.equipLeft() |
| 456 | + assert.is_true(succ) |
| 457 | + assert.are.equal( turtle.equipslots.left.name, "CCTweaked:chat_box") |
| 458 | + assert.are.equal(turtle.equipslots.left.count, 1) |
| 459 | + end) |
| 460 | + it("Upgrade Equipment", function() |
| 461 | + turtle:addItemToInventory({ name = "CCTweaked:chat_box", count = 2, maxcount = 2, equipable = true}, 3) |
| 462 | + turtle:select(3) |
| 463 | + local succ = turtle.equipLeft() |
| 464 | + assert.is_true(succ) |
| 465 | + assert.are.equal(turtle.equipslots.left.name, "CCTweaked:chat_box") |
| 466 | + assert.are.equal(turtle.equipslots.left.count, 1) |
| 467 | + end) |
| 468 | + |
| 469 | + it("Upgrade Equipment and Replace in inventory", function() |
| 470 | + turtle:addItemToInventory({ name = "CCTweaked:chat_box", count = 2, maxcount = 2, equipable = true}, 3) |
| 471 | + turtle:addItemToInventory({ name = "CCTweaked:chunk_loader", count = 1, maxcount = 1, equipable = true }, 4) |
| 472 | + turtle:select(3) |
| 473 | + local succ = turtle.equipLeft() |
| 474 | + assert.is_true(succ) |
| 475 | + assert.are.equal(turtle.equipslots.left.name, "CCTweaked:chat_box") |
| 476 | + assert.are.equal(turtle.equipslots.left.count, 1) |
| 477 | + turtle:select(4) |
| 478 | + succ = turtle.equipLeft() |
| 479 | + assert.is_true(succ) |
| 480 | + assert.are.equal(turtle.equipslots.left.name, "CCTweaked:chunk_loader") |
| 481 | + assert.are.equal(turtle.equipslots.left.count, 1) |
| 482 | + assert.are.equal(turtle.inventory[4].count, 1) |
| 483 | + assert.are.equal(turtle.inventory[4].name, "CCTweaked:chat_box") |
| 484 | + assert.are.equal(turtle.inventory[3].count, 1) |
| 485 | + assert.are.equal(turtle.inventory[3].name, "CCTweaked:chat_box") |
| 486 | + end) |
| 487 | + |
| 488 | + it("Equip Left and RightSlot", function() |
| 489 | + turtle:addItemToInventory({ name = "CCTweaked:chat_box", count = 2, maxcount = 2, equipable = true}, 3) |
| 490 | + turtle.select(3) |
| 491 | + local succ = turtle.equipRight() |
| 492 | + assert.is_true(succ) |
| 493 | + assert.are.equal(turtle.equipslots.right.name, "CCTweaked:chat_box") |
| 494 | + assert.are.equal(turtle.equipslots.right.count, 1) |
| 495 | + assert.are.equal(turtle.inventory[3].name, "CCTweaked:chat_box") |
| 496 | + assert.are.equal(turtle.inventory[3].count, 1) |
| 497 | + end) |
| 498 | + |
| 499 | + |
| 500 | + |
| 501 | +end) |
| 502 | + |
| 503 | +describe("EmulatorTesting", function() |
| 504 | + setup(function() |
| 505 | + turtleEmulator:clearTurtles(); |
| 506 | + end) |
| 507 | + describe("Adding Blocks", function() |
| 508 | + it("Add Block", function() |
| 509 | + turtleEmulator:createBlock({ item = {name = "minecraft:stone", maxcount = 64}, position = { x = 0, y = 0, z = 1 } }) |
| 510 | + assert.are_not.equal(nil, turtleEmulator.blocks["0,0,1"]) |
| 511 | + assert.are.equal("minecraft:stone", turtleEmulator.blocks["0,0,1"].item.name) |
| 512 | + assert.are.equal(nil, turtleEmulator.blocks["0,0,2"]) |
| 513 | + end) |
| 514 | + it("Add Block and remove it", function() |
| 515 | + local block = { item = {name = "minecraft:stone", maxcount = 64}, position = { x = 1, y = 0, z = 0 } } |
| 516 | + turtleEmulator:createBlock(block) |
| 517 | + assert.are_not.equal(nil, turtleEmulator.blocks["1,0,0"]) |
| 518 | + assert.are.equal("minecraft:stone", turtleEmulator.blocks["1,0,0"].item.name) |
| 519 | + turtleEmulator:removeBlock(block.position) |
| 520 | + assert.are.equal(nil, turtleEmulator.blocks["1,0,0"]) |
| 521 | + end) |
| 522 | + end) |
| 523 | + describe("Read Blocks", function() |
| 524 | + ---TODO: Implement |
| 525 | + end) |
| 526 | + describe("Return Block", function() |
| 527 | + local block = { |
| 528 | + item = {name = "minecraft:stone", maxcount = 64}, |
| 529 | + position = { x = 1, y = 0, z = 0 } |
| 530 | + } |
| 531 | + turtleEmulator:createBlock(block) |
| 532 | + assert.are_not.equal(nil, turtleEmulator.blocks["1,0,0"]) |
| 533 | + assert.are_not.equal(nil, turtleEmulator:getBlock(block.position)) |
| 534 | + local b = turtleEmulator:getBlock(block.position) |
| 535 | + assert.is.falsy(b.emulator) |
| 536 | + assert.are.equal(block.item.name, b.item.name) |
| 537 | + end) |
| 538 | +end) |
| 539 | + |
| 540 | +describe("ActionAccepted", function () |
| 541 | + --- TODO: Implement |
| 542 | + local turtle1 |
| 543 | + local turtle2 |
| 544 | + setup(function() |
| 545 | + turtleEmulator:clearTurtles() |
| 546 | + end) |
| 547 | +end) |
0 commit comments