mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2026-03-13 15:21:15 +08:00
merge: Add test cases, optamization of code, and Add description of function (#848)
* Add test cases, optamization of code, and Add description of function * update testcase
This commit is contained in:
32
Recursive/test/BinarySearch.test.js
Normal file
32
Recursive/test/BinarySearch.test.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import { binarySearch } from '../BinarySearch'
|
||||
|
||||
describe('BinarySearch', () => {
|
||||
const arr = [2, 3, 4, 10, 25, 40, 45, 60, 100, 501, 700, 755, 800, 999]
|
||||
const low = 0
|
||||
const high = arr.length - 1
|
||||
|
||||
it('should return index 3 for searchValue 10', () => {
|
||||
const searchValue = 10
|
||||
expect(binarySearch(arr, low, high, searchValue)).toBe(3)
|
||||
})
|
||||
|
||||
it('should return index 0 for searchValue 2', () => {
|
||||
const searchValue = 2
|
||||
expect(binarySearch(arr, low, high, searchValue)).toBe(0)
|
||||
})
|
||||
|
||||
it('should return index 13 for searchValue 999', () => {
|
||||
const searchValue = 999
|
||||
expect(binarySearch(arr, low, high, searchValue)).toBe(13)
|
||||
})
|
||||
|
||||
it('should return -1 for searchValue 1', () => {
|
||||
const searchValue = 1
|
||||
expect(binarySearch(arr, low, high, searchValue)).toBe(-1)
|
||||
})
|
||||
|
||||
it('should return -1 for searchValue 1000', () => {
|
||||
const searchValue = 1000
|
||||
expect(binarySearch(arr, low, high, searchValue)).toBe(-1)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user