1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
import { binarySearch1, binarySearch2 } from './binary-search'
describe('二分查找', () => { it('正常情况', () => { const arr = [10, 20, 30, 40, 50] const target = 40 const index = binarySearch1(arr, target) expect(index).toBe(3) })
it('空数组', () => { expect(binarySearch1([], 100)).toBe(-1) })
it('找不到 target', () => { const arr = [10, 20, 30, 40, 50] const target = 400 const index = binarySearch1(arr, target) expect(index).toBe(-1) }) })
|