Files
cocos-engine/tests/core/algorithm/binary-search.test.ts
Leslie Leigh (李的序) 13baf8a845 binarySearch series functions: document and unit test (#8114)
* binarySearch series functions: document and unit test

* Fix lint errors

* Update

* Update

* Update
2021-01-11 11:51:16 +08:00

16 lines
552 B
TypeScript

import { binarySearch } from '../../../cocos/core/algorithm/binary-search';
describe('Binary search', () => {
test('Found', () => {
expect(binarySearch([3.14, 3.15, 3.16], 3.15)).toBe(1);
});
test('Not found: less than some', () => {
expect(binarySearch([3.14, 3.15, 3.16], 3.145)).toBe(~1);
});
test('Not found: larger than all', () => {
expect(binarySearch([3.14, 3.15, 3.16], 3.17)).toBe(~3);
});
test('Not found: empty array', () => {
expect(binarySearch([], 0.28)).toBe(~0);
});
});