Fix binary search test

This commit is contained in:
Lars Mueller 2021-08-09 13:36:44 +02:00
parent a5e4696cd1
commit 258d9d956d

@ -123,7 +123,9 @@ do
_G.table.sort(sorted) _G.table.sort(sorted)
for i = 1, 10 do for i = 1, 10 do
local pick = _G.math.random(-100, 1100) local pick = _G.math.random(-100, 1100)
assert(linear_search(sorted, pick) == table.binary_search(sorted, pick)) local linear, binary = linear_search(sorted, pick), table.binary_search(sorted, pick)
-- If numbers appear twice (or more often), the indices may differ, as long as the number is the same.
assert(linear == binary or (linear > 0 and sorted[linear] == sorted[binary]))
end end
end end
end end