Skip to content

tests in search #575

Open
Open

Description

@vil02

The search functions cannot be treated uniformly in tests. The issue arises when the input array contains duplicated entries.

Consider the example when we want to fund the index of 4 in the array [1, 2, 4, 4, 4, 6, 7, 8, 9, 10] (note that the array is sorted):

To summarize the functions like Linear or Interpolation return the smallest index of the searched element (if it exists in the array). While other functions like Binary or Jump2 return some index.

I think the above shows a need to change tests or/and the implementations of the search package (for example the Interpolation function could be simplified to find some index).

Activity

  1. Nd1097 commented on Oct 19, 2022

    @Nd1097

    Hello, would like to contribute to this. Can you assign the task?

  2. siriak commented on Oct 24, 2022

    @siriak
    Member

    I agree with for example the Interpolation function could be simplified to find some index. @vil02 do you want to implement this yourself?

  3. vil02 commented on Oct 30, 2022

    @vil02
    MemberAuthor

    I agree with for example the Interpolation function could be simplified to find some index. @vil02 do you want to implement this yourself?

    I think @Nd1097 wanted to do it. If there will be no other volunteer you can assign me.

  4. tjgurwara99 commented on Nov 8, 2022

    @tjgurwara99
    Member

    For the test cases that are present in the tests, they are correct. I argue that those specific test cases should be added on case by case basis rather than uniformly adding them in tests separately for each test.

  5. KreanXie commented on Jun 30, 2023

    @KreanXie

    I don`t think the Binary func is useful when the array has repeated elements, maybe we can just refer to the sort.Search func in the standard library, which has a more clear and strict definition.

  6. aminoxix commented on Jun 8, 2025

    @aminoxix
    Member

    if the binary func intends to find the smallest index, you might be referring to lower & upper bound algorithm.

    ref.: https://peng.fyi/post/binary-search-in-go-sdk

    we can segregate the concepts to attend this issue.

    also, agreed with @tjgurwara99

  7. aminoxix commented on Jun 8, 2025

    @aminoxix
    Member

    btw, any update? @Nd1097

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions