Fix usage of bit32.arshift
added unit-test
This commit is contained in:
parent
1d817779df
commit
2e8a26df5c
@ -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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user