Improve tests

This commit is contained in:
Lars Mueller
2021-01-19 13:24:10 +01:00
parent 15ce314e8c
commit 2711e1333a

View File

@ -1,24 +1,24 @@
-- string
assert(modlib.string.escape_magic_chars"%" == "%%")
-- table -- table
local t = {} do
t[t] = t local table = {}
local t2 = modlib.table.deepcopy(t) table[table] = table
assert(t2[t2] == t2) local table_copy = modlib.table.deepcopy(table)
assert(table_copy[table_copy] == table_copy)
assert(modlib.table.is_circular(table))
assert(not modlib.table.is_circular{a = 1})
assert(modlib.table.equals_noncircular({[{}]={}}, {[{}]={}})) assert(modlib.table.equals_noncircular({[{}]={}}, {[{}]={}}))
assert(modlib.table.equals_content(t, t2)) assert(modlib.table.equals_content(table, table_copy))
assert(modlib.table.is_circular(t))
local equals_references = modlib.table.equals_references local equals_references = modlib.table.equals_references
assert(equals_references(table, table_copy))
assert(equals_references({}, {})) assert(equals_references({}, {}))
assert(not equals_references({a = 1, b = 2}, {a = 1, b = 3})) assert(not equals_references({a = 1, b = 2}, {a = 1, b = 3}))
t = {} table = {}
t.a, t.b = t, t table.a, table.b = table, table
t2 = {} table_copy = modlib.table.deepcopy(table)
t2.a, t2.b = t2, t2 assert(equals_references(table, table_copy))
assert(equals_references(t, t2))
t = {}
t[t] = t
t2 = {}
t2[t2] = t2
assert(equals_references(t, t2))
local x, y = {}, {} local x, y = {}, {}
assert(not equals_references({[x] = x, [y] = y}, {[x] = y, [y] = x})) assert(not equals_references({[x] = x, [y] = y}, {[x] = y, [y] = x}))
assert(equals_references({[x] = x, [y] = y}, {[x] = x, [y] = y})) assert(equals_references({[x] = x, [y] = y}, {[x] = x, [y] = y}))
@ -27,7 +27,27 @@ assert(nilget({a = {b = {c = 42}}}, "a", "b", "c") == 42)
assert(nilget({a = {}}, "a", "b", "c") == nil) assert(nilget({a = {}}, "a", "b", "c") == nil)
assert(nilget(nil, "a", "b", "c") == nil) assert(nilget(nil, "a", "b", "c") == nil)
assert(nilget(nil, "a", nil, "c") == nil) assert(nilget(nil, "a", nil, "c") == nil)
assert(modlib.string.escape_magic_chars("%") == "%%") end
-- heap
do
local n = 100
local list = {}
for index = 1, n do
list[index] = index
end
modlib.table.shuffle(list)
local heap = modlib.heap.new()
for index = 1, #list do
heap:push(list[index])
end
for index = 1, #list do
local popped = heap:pop()
assert(popped == index)
end
end
-- in-game tests
local tests = { local tests = {
liquid_dir = false, liquid_dir = false,
liquid_raycast = false liquid_raycast = false
@ -78,18 +98,3 @@ if tests.liquid_raycast then
end end
end) end)
end end
local n = 100
local list = {}
for index = 1, n do
list[index] = index
end
modlib.table.shuffle(list)
local heap = modlib.heap.new()
for index = 1, #list do
heap:push(list[index])
end
for index = 1, #list do
local popped = heap:pop()
assert(popped == index)
end