Binary search test is wrong
jcoder58 opened this issue · 4 comments
jcoder58 commented
This test from searching/ binarysearch.spec.js has two issues:
it('should find the eleent in position arr.length', function () {
expect(binarySearch([1, 2, 3, 4, 6, 8], 1)).toBe(0);
});
- There can never be an element in position arr.length
- The value found parameter should be 8 instead of 1, assuming its testing for the last element.
mgechev commented
You mean the test description is incorrect? The code looks fine to me.
jcoder58 commented
The code is testing the wrong thing. Here's the first two tests:
it('should find the element at position 0 ', function () {
expect(binarySearch([1, 2, 3, 4, 6, 8], 1)).toBe(0);
});
it('should find the eleent in position arr.length', function () {
expect(binarySearch([1, 2, 3, 4, 6, 8], 1)).toBe(0);
});
The call to binarySeach has identical parameters for both tests, even though the comments say different things. So the second test either needs to be eliminated, as it tests the same as the first, or it needs to be changed to match the comment.