1+ --- @class are
2+ --- @field same function
3+ --- @field equal function
4+ --- @field equals function
5+
6+ --- @class is
7+ --- @field truthy function
8+ --- @field falsy function
9+ --- @field not_true function
10+ --- @field not_false function
11+
12+ --- @class has
13+ --- @field error function
14+ --- @field errors function
15+
16+ --- @class assert
17+ --- @field are are
18+ --- @field is is
19+ --- @field are_not are
20+ --- @field is_not is
21+ --- @field has has
22+ --- @field has_no has
23+ --- @field True function
24+ --- @field False function
25+ --- @field has_error function
26+ --- @field is_false function
27+ --- @field is_true function
28+ --- @field equal function
29+ assert = assert
30+
31+ package.path = package.path .. " ;"
32+ .. " libs/?.lua;"
33+ .. " libs/inventory/?.lua;"
34+ .. " libs/peripherals/?.lua;"
35+
36+ --- @type TurtleEmulator
37+ local turtleEmulator = require (" turtleEmulator" )
38+
39+ --- @type HelperFunctions
40+ local helper = require (" helperFunctions" )
41+
42+ --- @type Vector
43+ _G .vector = require (" vector" )
44+
45+ --- @type TextUtils
46+ _G .textutils = require (" textutils" )
47+
48+ --- @type Builder_Lib
49+ local builder
50+
51+ local function beforeeach ()
52+ turtleEmulator :clearBlocks ()
53+ turtleEmulator :clearTurtles ()
54+ _G .turtle = turtleEmulator :createTurtle ()
55+ local peripheral = turtle .getPeripheralModule ()
56+ _G .peripheral = peripheral
57+ if builder == nil then
58+ builder = require (" builder-lib" )
59+ end
60+ builder .movementDirection .width = " right"
61+ builder .movementDirection .height = " up"
62+
63+ --- @type Item
64+ local coal = {name = " minecraft:coal" , count = 64 , fuelgain = 8 }
65+ turtle .addItemToInventory (coal , 1 )
66+ end
67+
68+ local function fillWorld ()
69+ local existingBlock = {item = {count = 1 , name = " minecraft:stone" , placeAble = true }}
70+ local tmpBlock
71+ local n = 0
72+ for y = 0 , 9 , 1 do
73+ for x = 0 , 9 , 1 do
74+ for z = 0 , 9 , 1 do
75+ if x == 0 and y == 0 and z == 0 then
76+ -- skip
77+ else
78+ n = n + 1
79+ tmpBlock = helper .copyTable (existingBlock ) --[[ @as block]]
80+ tmpBlock .position = vector .new (x , y , z )
81+ turtleEmulator :createBlock (tmpBlock )
82+ end
83+ end
84+ end
85+ end
86+ end
87+
88+ --- counts the length of a table
89+ --- @param t table
90+ --- @return number
91+ local function countTableLength (t )
92+ local length = 0
93+ for _ , _ in pairs (t ) do
94+ length = length + 1
95+ end
96+ return length
97+ end
98+
99+
100+
101+ --- @param p1 Vector
102+ --- @param p2 Vector
103+ --- @return table<string , number>
104+ local function get_bounds (p1 , p2 )
105+ return {
106+ x_min = math.min (p1 .x , p2 .x ),
107+ x_max = math.max (p1 .x , p2 .x ),
108+ y_min = math.min (p1 .y , p2 .y ),
109+ y_max = math.max (p1 .y , p2 .y ),
110+ z_min = math.min (p1 .z , p2 .z ),
111+ z_max = math.max (p1 .z , p2 .z ),
112+ }
113+ end
114+
115+ --- @param pos1 Vector
116+ --- @param pos2 Vector
117+ --- @return number
118+ --- @return table<block>
119+ local function checkEmptyFromTo (pos1 , pos2 )
120+ local tmpBlock
121+ local n = 0
122+ --- @type table<block>
123+ local blocks = {}
124+ local bounds = get_bounds (pos1 , pos2 )
125+ for x = bounds .x_min , bounds .x_max do
126+ for y = bounds .y_min , bounds .y_max do
127+ for z = bounds .z_min , bounds .z_max do
128+ tmpBlock = turtleEmulator :getBlock (vector .new (x ,y ,z )) --[[ @as block|TurtleEmulator]]
129+ if tmpBlock ~= nil and not tmpBlock .item .name :find (" turtle" ) then
130+ n = n + 1
131+ table.insert (blocks , tmpBlock )
132+ end
133+ end
134+ end
135+ end
136+ return n , blocks
137+ end
138+
139+ describe (" Testing ClearArea Function" , function ()
140+ --- @type block
141+
142+ before_each (function ()
143+ beforeeach ()
144+ fillWorld ()
145+ end )
146+ it (" testing the basic Test setup" , function ()
147+ -- pending("jup")
148+ local n , _ = checkEmptyFromTo (vector .new (0 ,0 ,0 ),vector .new (3 ,3 ,3 ))
149+ assert .are .equal (63 , n )
150+ assert (998 , countTableLength (turtleEmulator .blocks ))
151+ end )
152+ it (" Clear 4 x 4 x 4 | Moving: left up" , function ()
153+ builder .movementDirection .height = " up"
154+ builder .movementDirection .height = " left"
155+ builder :clearArea (4 ,4 ,4 )
156+ local filter = function (t )
157+ return t .position .y == 3
158+ end
159+
160+ local n = countTableLength (turtleEmulator .blocks )
161+ assert (998 - (4 * 4 * 4 ), n )
162+ local m , blocks = checkEmptyFromTo (vector .new (0 ,0 ,0 ),vector .new (3 ,3 ,3 ))
163+ assert .are .equal (0 ,m )
164+ end )
165+ end )
0 commit comments