mirror of
https://github.com/TangentFoxy/lume.git
synced 2024-11-19 07:04:24 +00:00
Added lume.push(), updated tests
This commit is contained in:
parent
9cdbc27b66
commit
3bec7b356d
9
lume.lua
9
lume.lua
@ -149,6 +149,15 @@ function lume.weightedchoice(t)
|
||||
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)
|
||||
local rtn = {}
|
||||
for i = 1, #t do
|
||||
|
@ -106,6 +106,17 @@ tests["lume.weightedchoice"] = function()
|
||||
tester.test.error( lume.weightedchoice, { a = 1, b = -1 } )
|
||||
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
|
||||
tests["lume.shuffle"] = function()
|
||||
local t = {1, 2, 3, 4, 5}
|
||||
|
Loading…
Reference in New Issue
Block a user