Fix usage of bit32.arshift

added unit-test
This commit is contained in:
Tom van Dijck 2016-06-09 18:12:06 -07:00
parent 1d817779df
commit 2e8a26df5c
2 changed files with 23 additions and 2 deletions

View File

@ -270,7 +270,7 @@
local minindex = 1
local maxindex = #tbl + 1
while minindex < maxindex do
local index = minindex + bit32.arshift(maxindex - minindex, 1)
local index = minindex + math.floor((maxindex - minindex) / 2)
local test = tbl[index]
if fn(value, test) then
maxindex = index

View File

@ -74,3 +74,24 @@
function suite.isempty_ReturnsFalseOnNotEmptyMapWithFalseKey()
test.isfalse(table.isempty({ [false] = 0 }))
end
--
-- table.insertsorted() tests
--
function suite.insertsorted()
local t = {}
table.insertsorted(t, 5)
table.insertsorted(t, 2)
table.insertsorted(t, 8)
table.insertsorted(t, 4)
table.insertsorted(t, 1)
test.istrue(#t == 5)
test.istrue(t[1] == 1)
test.istrue(t[2] == 2)
test.istrue(t[3] == 4)
test.istrue(t[4] == 5)
test.istrue(t[5] == 8)
end