Added lume.push(), updated tests

This commit is contained in:
rxi 2015-02-07 22:38:08 +00:00
parent 9cdbc27b66
commit 3bec7b356d
2 changed files with 20 additions and 0 deletions

View File

@ -149,6 +149,15 @@ function lume.weightedchoice(t)
end end
function lume.push(t, ...)
local n = select("#", ...)
for i = 1, n do
t[#t + 1] = select(i, ...)
end
return ...
end
function lume.shuffle(t) function lume.shuffle(t)
local rtn = {} local rtn = {}
for i = 1, #t do for i = 1, #t do

View File

@ -106,6 +106,17 @@ tests["lume.weightedchoice"] = function()
tester.test.error( lume.weightedchoice, { a = 1, b = -1 } ) tester.test.error( lume.weightedchoice, { a = 1, b = -1 } )
end end
-- lume.push
tests["lume.push"] = function()
local t = { 1, 2 }
lume.push(t, 3, 4)
testeq(t, { 1, 2, 3, 4 })
lume.push(t, 5, nil, 6, nil, 7)
testeq(t, { 1, 2, 3, 4, 5, 6, 7 })
lume.push(t)
testeq(t, { 1, 2, 3, 4, 5, 6, 7 })
end
-- lume.shuffle -- lume.shuffle
tests["lume.shuffle"] = function() tests["lume.shuffle"] = function()
local t = {1, 2, 3, 4, 5} local t = {1, 2, 3, 4, 5}