mirror of
https://git.minetest.land/Mineclonia/Mineclonia.git
synced 2024-11-05 09:15:05 +00:00
Improve test for minetest.find_nodes_in_area()
• By emerging test areas, the test gets real map data and does not block. • The test now also ensures that any return values are compared exactly. • minetest.find_nodes_in_area() is tested with the “grouped” parameter.
This commit is contained in:
parent
526c25aa57
commit
76d2846c59
1 changed files with 118 additions and 10 deletions
|
@ -65,30 +65,138 @@ minetest.find_nodes_in_area = function(minp, maxp, ...)
|
|||
end
|
||||
end
|
||||
|
||||
deep_compare = function(a, b)
|
||||
local type_a = type(a)
|
||||
local type_b = type(b)
|
||||
if type_a ~= type_b then
|
||||
return false
|
||||
end
|
||||
if type_a ~= "table" and type_b ~= "table" then
|
||||
return a == b
|
||||
end
|
||||
for key_a, value_a in pairs(a) do
|
||||
local value_b = b[key_a]
|
||||
if not deep_compare(value_a, value_b) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
for key_b, value_b in pairs(b) do
|
||||
local value_a = a[key_b]
|
||||
if not deep_compare(value_b, value_a) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
assert(
|
||||
deep_compare(
|
||||
1,
|
||||
1.0
|
||||
) == true
|
||||
)
|
||||
|
||||
assert(
|
||||
deep_compare(
|
||||
true,
|
||||
"true"
|
||||
) == false
|
||||
)
|
||||
|
||||
assert(
|
||||
deep_compare(
|
||||
{ a=1, b=-2, c=3.4 },
|
||||
{ a=1, b=-2, c=3.4 }
|
||||
) == true
|
||||
)
|
||||
|
||||
assert(
|
||||
deep_compare(
|
||||
{ a={ 1, 2, 3 }, b="foo", c=false },
|
||||
{ a={ 1, 2, 3 }, b="foo", c=false }
|
||||
) == true
|
||||
)
|
||||
|
||||
assert(
|
||||
deep_compare(
|
||||
{ a={ 1, 2, 3 }, b="foo", c=false },
|
||||
{ a={ 4, 5, 6 }, b="foo", c=false }
|
||||
) == false
|
||||
)
|
||||
|
||||
assert(
|
||||
deep_compare(
|
||||
{ a={ 1, 2, 3 }, b={ c=false } },
|
||||
{ a={ 1, 2, 3 }, b={ c=false } }
|
||||
) == true
|
||||
)
|
||||
|
||||
assert(
|
||||
deep_compare(
|
||||
{ a={ 1, 2, 3 }, b={ } },
|
||||
{ a={ 1, 2, 3 }, b={ c=false } }
|
||||
) == false
|
||||
)
|
||||
|
||||
local test_minetest_find_nodes_in_area_implementation_equivalence = function()
|
||||
-- If any assertion in this test function fails, the wrapper
|
||||
-- for minetest.find_nodes_in_area() does not behave like the
|
||||
-- original function. If you are reading the code because your
|
||||
-- server crashed, please inform the Mineclonia developers.
|
||||
local fun_1 = minetest_find_nodes_in_area
|
||||
local fun_2 = minetest.find_nodes_in_area
|
||||
for x = -31000, 31000, 15500 do
|
||||
for y = -31000, 31000, 15500 do
|
||||
for z = -31000, 31000, 15500 do
|
||||
for d = 1, 9, 3 do
|
||||
local minp = { x=x, y=y, z=z }
|
||||
local maxp = { x=x+d, y=y+d, z=z+d }
|
||||
local npos_1, nnum_1 = minetest_find_nodes_in_area(
|
||||
minetest.emerge_area(
|
||||
minp,
|
||||
maxp,
|
||||
{ "air", "ignore" }
|
||||
function(blockpos, action, calls_remaining)
|
||||
local npos_1, nnum_1 = fun_1(
|
||||
minp,
|
||||
maxp,
|
||||
{ "air", "ignore" }
|
||||
)
|
||||
local npos_2, nnum_2 = fun_2(
|
||||
minp,
|
||||
maxp,
|
||||
{ "air", "ignore" }
|
||||
)
|
||||
assert(
|
||||
deep_compare(
|
||||
npos_1,
|
||||
npos_2
|
||||
) == true
|
||||
)
|
||||
assert(
|
||||
deep_compare(
|
||||
nnum_1,
|
||||
nnum_2
|
||||
) == true
|
||||
)
|
||||
local ntab_1 = fun_1(
|
||||
minp,
|
||||
maxp,
|
||||
{ "air", "ignore" },
|
||||
true
|
||||
)
|
||||
local ntab_2 = fun_2(
|
||||
minp,
|
||||
maxp,
|
||||
{ "air", "ignore" },
|
||||
true
|
||||
)
|
||||
assert(
|
||||
deep_compare(
|
||||
ntab_1,
|
||||
ntab_2
|
||||
) == true
|
||||
)
|
||||
end
|
||||
)
|
||||
local npos_2, nnum_2 = minetest.find_nodes_in_area(
|
||||
minp,
|
||||
maxp,
|
||||
{ "air", "ignore" }
|
||||
)
|
||||
assert(#npos_1 == #npos_2)
|
||||
assert(nnum_1["air"] == nnum_2["air"])
|
||||
assert(nnum_1["ignore"] == nnum_2["ignore"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue