Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loop in interpolationSearch #305

Open
dubzzz opened this issue Feb 14, 2019 · 0 comments
Open

Infinite loop in interpolationSearch #305

dubzzz opened this issue Feb 14, 2019 · 0 comments

Comments

@dubzzz
Copy link
Contributor

dubzzz commented Feb 14, 2019

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 - and i - integer value
interpolationSearch(arr, i) should be equivalent to arr.indexOf(i)

@dubzzz dubzzz changed the title BUG Infinite loop in interpolationSearch Infinite loop in interpolationSearch Feb 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant