Go icon indicating copy to clipboard operation
Go copied to clipboard

tests in `search`

Open vil02 opened this issue 2 years ago • 5 comments

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).

vil02 avatar Oct 16 '22 22:10 vil02

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

Nd1097 avatar Oct 19 '22 15:10 Nd1097

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

siriak avatar Oct 24 '22 18:10 siriak

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.

vil02 avatar Oct 30 '22 20:10 vil02

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.

tjgurwara99 avatar Nov 08 '22 20:11 tjgurwara99

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.

KreanXie avatar Jun 30 '23 14:06 KreanXie