God knows what's modified
This commit is contained in:
@@ -3,7 +3,10 @@
|
||||
# in the order that they're supposed to be loaded.
|
||||
#
|
||||
|
||||
utils.lua
|
||||
inspect.lua
|
||||
|
||||
|
||||
ut-table.lua
|
||||
ut-idalloc.lua
|
||||
ut-globaldb.lua
|
||||
ut-cellgrid.lua
|
||||
|
||||
|
||||
@@ -341,4 +341,4 @@ function inspect.pprint(...)
|
||||
end
|
||||
end
|
||||
|
||||
_G.pprint = inspect.pprint
|
||||
pprint = inspect.pprint
|
||||
|
||||
12
luprex/syslua/ut-cellgrid.lua
Normal file
12
luprex/syslua/ut-cellgrid.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
local ut = {}
|
||||
|
||||
function ut.cellid()
|
||||
local sc = cellgrid.scale()
|
||||
local cid = cellgrid.cellid(0,0,0)
|
||||
assert(cellgrid.cellid(0,0,0) == 0x0001000000000000)
|
||||
assert(cellgrid.cellid( 1*sc, 2*sc, 3*sc) == 0x0001000100020003)
|
||||
assert(cellgrid.cellid(-1*sc, -2*sc, -3*sc) == 0x0001FFFFFFFEFFFD)
|
||||
assert(cellgrid.cellid(10000000, 0, 0) == 0)
|
||||
end
|
||||
|
||||
rununittests(ut)
|
||||
15
luprex/syslua/ut-globaldb.lua
Normal file
15
luprex/syslua/ut-globaldb.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
local ut = {}
|
||||
|
||||
function ut.globaldb()
|
||||
local g1a = global("unittest-g1")
|
||||
local g2a = global("unittest-g2")
|
||||
local g1b = global("unittest-g1")
|
||||
local g2b = global("unittest-g2")
|
||||
assert(g1a == g1b)
|
||||
assert(g2a == g2b)
|
||||
assert(g1a.__global == "unittest-g1")
|
||||
assert(g2a.__global == "unittest-g2")
|
||||
end
|
||||
|
||||
rununittests(ut)
|
||||
95
luprex/syslua/ut-idalloc.lua
Normal file
95
luprex/syslua/ut-idalloc.lua
Normal file
@@ -0,0 +1,95 @@
|
||||
|
||||
local ut = {}
|
||||
|
||||
local function nthbatch(i)
|
||||
return 0x0001000000000000 + 256 * (i - 1)
|
||||
end
|
||||
|
||||
local function equalbatches(q, batches)
|
||||
if queue.size(q) ~= #batches then
|
||||
return false
|
||||
end
|
||||
for i = 1, #batches do
|
||||
if queue.nth(q, i) ~= nthbatch(batches[i]) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function ut.idalloc_synch()
|
||||
local allocator = {}
|
||||
idalloc.initsynch(allocator, 10)
|
||||
assert(allocator.id_salvaged == nil)
|
||||
assert(allocator.id_nextbatch == nil)
|
||||
assert(allocator.id_nextid == 0x001E000000000000)
|
||||
assert(allocator.id_queuefill == 10)
|
||||
|
||||
local q1 = queue.create()
|
||||
idalloc.refill(allocator, q1)
|
||||
assert(queue.size(q1) == 0)
|
||||
end
|
||||
|
||||
function ut.idalloc_master()
|
||||
local allocator = {}
|
||||
idalloc.initmaster(allocator, 3)
|
||||
assert(queue.size(allocator.id_salvaged) == 0)
|
||||
assert(allocator.id_nextbatch == nthbatch(1))
|
||||
assert(allocator.id_nextid == 0x0010000000000000)
|
||||
assert(allocator.id_queuefill == 3)
|
||||
|
||||
local q1 = queue.create()
|
||||
local q2 = queue.create()
|
||||
local q3 = queue.create()
|
||||
local salv = allocator.id_salvaged
|
||||
|
||||
idalloc.refill(allocator, q1)
|
||||
idalloc.refill(allocator, q2)
|
||||
assert(equalbatches(q1, { 1, 2, 3 }))
|
||||
assert(equalbatches(q2, { 4, 5, 6 }))
|
||||
idalloc.unqueue(allocator, q1)
|
||||
assert(equalbatches(salv, { 1, 2, 3 }))
|
||||
queue.pop(q2)
|
||||
assert(equalbatches(q2, { 5, 6 }))
|
||||
idalloc.refill(allocator, q2)
|
||||
assert(equalbatches(q2, { 5, 6, 1 }))
|
||||
assert(equalbatches(salv, { 2, 3 }))
|
||||
idalloc.refill(allocator, q3)
|
||||
assert(equalbatches(q3, { 2, 3, 7 }))
|
||||
end
|
||||
|
||||
function ut.idalloc_thread()
|
||||
local allocator = {}
|
||||
idalloc.initmaster(allocator, 3)
|
||||
local salv = allocator.id_salvaged
|
||||
local q = queue.create()
|
||||
idalloc.refill(allocator, q)
|
||||
|
||||
local id = 0
|
||||
local function useids()
|
||||
for i = 1,10000 do
|
||||
id = idalloc.allocid(allocator)
|
||||
coroutine.yield()
|
||||
end
|
||||
end
|
||||
|
||||
local co = coroutine.create(useids)
|
||||
coroutine.resume(co)
|
||||
assert(id == 0x0010000000000000)
|
||||
coroutine.resume(co)
|
||||
assert(id == 0x0010000000000001)
|
||||
idalloc.preparethread(q, co)
|
||||
coroutine.resume(co)
|
||||
assert(id == nthbatch(1) + 0)
|
||||
coroutine.resume(co)
|
||||
assert(id == nthbatch(1) + 1)
|
||||
idalloc.salvagethread(allocator, co)
|
||||
coroutine.resume(co)
|
||||
assert(id == 0x0010000000000002)
|
||||
|
||||
assert(queue.size(salv) == 1)
|
||||
assert(queue.nth(salv, 1) == nthbatch(1) + 2)
|
||||
end
|
||||
|
||||
rununittests(ut)
|
||||
|
||||
96
luprex/syslua/ut-table.lua
Normal file
96
luprex/syslua/ut-table.lua
Normal file
@@ -0,0 +1,96 @@
|
||||
|
||||
local ut = {}
|
||||
|
||||
function ut.table_count()
|
||||
assert(table.count({}) == 0)
|
||||
assert(table.count({a=1,b=2}) == 2)
|
||||
assert(table.count({[2]=5,[5]=3}) == 2)
|
||||
end
|
||||
|
||||
function ut.table_coerce()
|
||||
local t = {}
|
||||
local t1 = table.coerce(t)
|
||||
assert(t1==t)
|
||||
t1 = table.coerce(0)
|
||||
assert(type(t1) == "table")
|
||||
t1 = table.coerce(nil)
|
||||
assert(type(t1) == "table")
|
||||
end
|
||||
|
||||
function ut.table_clear()
|
||||
local t = { a = 1, b = 2 }
|
||||
table.clear(t)
|
||||
assert(t.a == nil)
|
||||
assert(t.b == nil)
|
||||
assert(table.count(t) == 0)
|
||||
setmetatable(t, t)
|
||||
table.clear(t)
|
||||
assert(getmetatable(t) == nil)
|
||||
end
|
||||
|
||||
function ut.table_empty()
|
||||
assert(table.empty({}) == true)
|
||||
assert(table.empty({1}) == false)
|
||||
assert(table.empty({a=1}) == false)
|
||||
end
|
||||
|
||||
function ut.table_equal()
|
||||
assert(table.equal({},{}))
|
||||
assert(not table.equal({}, {1}))
|
||||
assert(not table.equal({1}, {}))
|
||||
assert(table.equal({1,2,3}, {1,2,3}))
|
||||
assert(not table.equal({1,2,3}, {1,5,3}))
|
||||
assert(not table.equal({1,2}, {1,2,3}))
|
||||
assert(not table.equal({1,2,3}, {1,2}))
|
||||
assert(table.equal({a=1,b=2},{a=1,b=2}))
|
||||
assert(not table.equal({a=1,b=3},{a=1,b=2}))
|
||||
end
|
||||
|
||||
function ut.table_append()
|
||||
t = {}
|
||||
table.append(t, 1)
|
||||
assert(table.equal(t, {1}))
|
||||
table.append(t, 2)
|
||||
assert(table.equal(t, {1,2}))
|
||||
table.append(t, 3)
|
||||
assert(table.equal(t, {1,2,3}))
|
||||
end
|
||||
|
||||
function ut.table_findremove()
|
||||
t = {1,2,3,4,5,1,2,3,4,5}
|
||||
table.findremove(t, 2)
|
||||
assert(table.equal(t, {1,3,4,5,1,3,4,5}))
|
||||
table.findremove(t, 5)
|
||||
assert(table.equal(t, {1,3,4,1,3,4}))
|
||||
table.findremove(t, 1)
|
||||
assert(table.equal(t, {3,4,3,4}))
|
||||
end
|
||||
|
||||
function ut.queues()
|
||||
local q = queue.create()
|
||||
assert(q.head == 1000000)
|
||||
assert(q.tail == 1000000)
|
||||
assert(queue.size(q) == 0)
|
||||
assert(table.count(q) == 2)
|
||||
queue.push(q, 27)
|
||||
assert(queue.size(q) == 1)
|
||||
queue.push(q, 45)
|
||||
assert(queue.nth(q, 1) == 27)
|
||||
assert(queue.nth(q, 2) == 45)
|
||||
assert(queue.size(q) == 2)
|
||||
assert(table.count(q) == 4)
|
||||
assert(queue.pop(q) == 27)
|
||||
assert(queue.size(q) == 1)
|
||||
assert(table.count(q) == 3)
|
||||
assert(queue.pop(q) == 45)
|
||||
assert(queue.size(q) == 0)
|
||||
assert(table.count(q) == 2)
|
||||
assert(queue.pop(q) == nil)
|
||||
assert(table.count(q) == 2)
|
||||
assert(q.head == 1000002)
|
||||
assert(q.tail == 1000002)
|
||||
assert(queue.size(q) == 0)
|
||||
end
|
||||
|
||||
rununittests(ut)
|
||||
|
||||
20
luprex/syslua/utils.lua
Normal file
20
luprex/syslua/utils.lua
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
|
||||
function rununittests(tab)
|
||||
for k, v in pairs(tab) do
|
||||
v()
|
||||
end
|
||||
end
|
||||
|
||||
function crash2()
|
||||
local tab = nil
|
||||
tab[3] = 1
|
||||
end
|
||||
|
||||
function crash1()
|
||||
crash2()
|
||||
end
|
||||
|
||||
function doyield()
|
||||
coroutine.yield()
|
||||
end
|
||||
Reference in New Issue
Block a user