Open
Description
Details:
Some entries might cause interpolationSearch
to fall into an infinite loop.
Step to reproduce: interpolationSearch([0, 3], 6)
How did I find it?
Thanks to property based testing framework fast-check.
The property was the following:
import fc from 'fast-check';
fc.assert(
fc.property(
fc.array(fc.integer()).map(arr => [...arr].sort((a, b) => a - b)),
fc.integer(),
(arr, i) => expect(interpolationSearch(arr, i)).toBe(arr.indexOf(i))
)
)
Or:
for any
arr
- sorted array of integers - andi
- integer value
interpolationSearch(arr, i)
should be equivalent toarr.indexOf(i)
Metadata
Metadata
Assignees
Labels
No labels