Skip to content

Test cases for interpolation_search - #10690

Open
RaymondDashWu wants to merge 19 commits into
TheAlgorithms:masterfrom
RaymondDashWu:interpolation_search_tests
Open

RaymondDashWu wants to merge 19 commits into
TheAlgorithms:masterfrom
RaymondDashWu:interpolation_search_tests

Conversation

@RaymondDashWu

Copy link
Copy Markdown
Contributor

Describe your change:

Contributes to #9943

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?
  • Add test cases

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@algorithms-keeper algorithms-keeper Bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass labels Oct 19, 2023
Comment thread searches/interpolation_search.py
@algorithms-keeper algorithms-keeper Bot removed the tests are failing Do not merge until tests pass label Oct 20, 2023
@algorithms-keeper algorithms-keeper Bot added tests are failing Do not merge until tests pass and removed tests are failing Do not merge until tests pass labels Oct 20, 2023
@algorithms-keeper algorithms-keeper Bot added tests are failing Do not merge until tests pass and removed tests are failing Do not merge until tests pass labels Oct 20, 2023
def interpolation_search(sorted_collection, item):
def interpolation_search(sorted_collection: list[int], item: int) -> int | None:
"""Pure implementation of interpolation search algorithm in Python
Be careful collection must be ascending sorted, otherwise result will be

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please test for this condition. Give it an unsorted input and lets see if it fails or not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An unsorted input doesn't work with this implementation unfortunately. For example >>> interpolation_search([5, 0, 1], 2) == None will return True despite 2 not being in the array. I wasn't sure how to handle this as there is a helper function called __assert_sorted. I considered adding that code at the beginning of each function but that changes the time complexity of the functions from logn to nlogn. If something is done to sanitize the input I assume it should be done in a separate PR.

Comment thread searches/interpolation_search.py Outdated
@algorithms-keeper algorithms-keeper Bot added the tests are failing Do not merge until tests pass label Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files git merge conflict

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants