mirror of
https://github.com/appgurueu/modlib.git
synced 2024-09-12 00:06:49 +02:00
Improve tests
This commit is contained in:
parent
15ce314e8c
commit
2711e1333a
93
test.lua
93
test.lua
@ -1,33 +1,53 @@
|
|||||||
|
-- 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(modlib.table.equals_noncircular({[{}]={}}, {[{}]={}}))
|
assert(table_copy[table_copy] == table_copy)
|
||||||
assert(modlib.table.equals_content(t, t2))
|
assert(modlib.table.is_circular(table))
|
||||||
assert(modlib.table.is_circular(t))
|
assert(not modlib.table.is_circular{a = 1})
|
||||||
local equals_references = modlib.table.equals_references
|
assert(modlib.table.equals_noncircular({[{}]={}}, {[{}]={}}))
|
||||||
assert(equals_references({}, {}))
|
assert(modlib.table.equals_content(table, table_copy))
|
||||||
assert(not equals_references({a = 1, b = 2}, {a = 1, b = 3}))
|
local equals_references = modlib.table.equals_references
|
||||||
t = {}
|
assert(equals_references(table, table_copy))
|
||||||
t.a, t.b = t, t
|
assert(equals_references({}, {}))
|
||||||
t2 = {}
|
assert(not equals_references({a = 1, b = 2}, {a = 1, b = 3}))
|
||||||
t2.a, t2.b = t2, t2
|
table = {}
|
||||||
assert(equals_references(t, t2))
|
table.a, table.b = table, table
|
||||||
t = {}
|
table_copy = modlib.table.deepcopy(table)
|
||||||
t[t] = t
|
assert(equals_references(table, table_copy))
|
||||||
t2 = {}
|
local x, y = {}, {}
|
||||||
t2[t2] = t2
|
assert(not equals_references({[x] = x, [y] = y}, {[x] = y, [y] = x}))
|
||||||
assert(equals_references(t, t2))
|
assert(equals_references({[x] = x, [y] = y}, {[x] = x, [y] = y}))
|
||||||
local x, y = {}, {}
|
local nilget = modlib.table.nilget
|
||||||
assert(not equals_references({[x] = x, [y] = y}, {[x] = y, [y] = x}))
|
assert(nilget({a = {b = {c = 42}}}, "a", "b", "c") == 42)
|
||||||
assert(equals_references({[x] = x, [y] = y}, {[x] = x, [y] = y}))
|
assert(nilget({a = {}}, "a", "b", "c") == nil)
|
||||||
local nilget = modlib.table.nilget
|
assert(nilget(nil, "a", "b", "c") == nil)
|
||||||
assert(nilget({a = {b = {c = 42}}}, "a", "b", "c") == 42)
|
assert(nilget(nil, "a", nil, "c") == nil)
|
||||||
assert(nilget({a = {}}, "a", "b", "c") == nil)
|
end
|
||||||
assert(nilget(nil, "a", "b", "c") == nil)
|
|
||||||
assert(nilget(nil, "a", nil, "c") == nil)
|
-- heap
|
||||||
assert(modlib.string.escape_magic_chars("%") == "%%")
|
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
|
||||||
@ -77,19 +97,4 @@ if tests.liquid_raycast then
|
|||||||
end
|
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
|
end
|
Loading…
Reference in New Issue
Block a user