@@ -290,3 +290,120 @@ describe("ProxyTests", function()
290290 assert .are .equal (2 , gotCalled , " asserts did not run as expected" )
291291 end )
292292end )
293+ describe (" InventoryTests" , function ()
294+ --- @type TurtleProxy
295+ local turtle
296+ before_each (function ()
297+ end )
298+ describe (" Adding Items for Testing" , function ()
299+ before_each (function ()
300+ turtle = turtleEmulator :createTurtle ()
301+ turtle :addItemToInventory ({ name = " minecraft:coal" , count = 64 , maxcount = 64 , fuelgain = 64 }, 1 )
302+ turtle :addItemToInventory ({ name = " minecraft:wood_plank" , count = 64 , maxcount = 64 , fuelgain = 8 }, 2 )
303+ end )
304+ it (" Throw Error when adding Item to full slot" , function ()
305+ assert .has_error (function ()
306+ turtle :addItemToInventory (
307+ { name = " minecraft:Stone" , count = 64 , maxcount = 64 },
308+ 1
309+ )
310+ end )
311+ end )
312+ it (" Throw Error when adding Item to invalid slot" , function ()
313+ assert .has_error (function ()
314+ turtle :addItemToInventory (
315+ { name = " minecraft:Stone" , count = 64 , maxcount = 64 },
316+ 0 )
317+ end )
318+ end )
319+ it (" Adding two different items to the same slot" , function ()
320+ local succ = turtle :addItemToInventory (
321+ { name = " minecraft:Stone" , count = 32 , maxcount = 64 },
322+ 3 )
323+ assert .is_true (succ )
324+ assert .has_error (function ()
325+ turtle :addItemToInventory (
326+ { name = " minecraft:Woods" , count = 32 , maxcount = 64 },
327+ 3 )
328+ end )
329+ end )
330+ it (" Adding item to Slot 3" , function ()
331+ local succ = turtle :addItemToInventory (
332+ { name = " minecraft:Wood" , count = 64 , maxcount = 64 , },
333+ 3 )
334+ assert .is_true (succ )
335+ assert .are .equal (64 , turtle .inventory [3 ].count )
336+ end )
337+ it (" Adding items to slot 4 twice" , function ()
338+ local succ = turtle :addItemToInventory (
339+ { name = " minecraft:Wood" , count = 32 , maxcount = 64 },
340+ 4 )
341+ assert .is_true (succ )
342+ succ = turtle :addItemToInventory (
343+ { name = " minecraft:Wood" , count = 32 , maxcount = 64 },
344+ 4 )
345+ assert .is_true (succ )
346+ assert .are .equal (64 , turtle .inventory [4 ].count )
347+ end )
348+ it (" Adding more items than maxcount without a specific slot" , function ()
349+ turtle :addItemToInventory (
350+ { name = " minecraft:Stone" , count = 1 , maxcount = 64 }, 4 )
351+ local succ = turtle :addItemToInventory (
352+ { name = " minecraft:Wood" , count = 128 , maxcount = 64 })
353+ assert .is_true (succ )
354+ assert .are .equal (64 , turtle .inventory [3 ].count )
355+ assert .are .equal (64 , turtle .inventory [5 ].count )
356+ end )
357+ end )
358+ describe (" Remaining Inventory Tests" , function ()
359+ before_each (function ()
360+ turtle = turtleEmulator :createTurtle ()
361+ turtle :addItemToInventory ({ name = " minecraft:coal" , count = 64 , maxcount = 64 , fuelgain = 64 }, 1 )
362+ turtle :addItemToInventory ({ name = " minecraft:wood_plank" , count = 64 , maxcount = 64 , fuelgain = 8 }, 2 )
363+ turtle :getSocket ()
364+ end )
365+ it (" transferTo Slot 2" , function ()
366+ turtle :select (2 )
367+ local succ = turtle :transferTo (4 , 16 )
368+ assert .is_true (succ )
369+ assert .are .equal (16 , turtle .inventory [4 ].count )
370+ assert .are .equal (48 , turtle .inventory [2 ].count )
371+ assert .are .equal (" minecraft:wood_plank" , turtle .inventory [4 ].name )
372+ succ = turtle :transferTo (4 , 48 )
373+ assert .is_true (succ )
374+ assert .are .equal (64 , turtle .inventory [4 ].count )
375+ assert .are .equal (nil , turtle .inventory [2 ])
376+ end )
377+ it (" getItemInfos" , function ()
378+ local items = turtle :getItemDetail ()
379+ assert .are_not .equal (nil , items )
380+ assert .are .equal (" minecraft:coal" , items .name )
381+ assert .are .equal (64 , items .count )
382+ items = turtle :getItemDetail (2 )
383+ assert .are_not .equal (nil , items )
384+ assert .are .equal (" minecraft:wood_plank" , items .name )
385+ assert .are .equal (64 , items .count )
386+ end )
387+ it (" getItemCount" , function ()
388+ local count = turtle .getItemCount ()
389+ assert .are .equal (64 , count )
390+ count = turtle .getItemCount (2 )
391+ assert .are .equal (64 , count )
392+ end )
393+ it (" getitemSpace" , function ()
394+ local space = turtle .getItemSpace ()
395+ assert .are .equal (0 , space )
396+ space = turtle .getItemSpace (2 )
397+ assert .are .equal (0 , space )
398+ space = turtle .getItemSpace (3 )
399+ assert .are .equal (64 , space )
400+ end )
401+ it (" getSelectedSlot" , function ()
402+ local slot = turtle .getSelectedSlot ()
403+ assert .are .equal (1 , slot )
404+ turtle :select (2 )
405+ slot = turtle .getSelectedSlot ()
406+ assert .are .equal (2 , slot )
407+ end )
408+ end )
409+ end )
0 commit comments