mirror of
https://github.com/cocos/cocos-engine.git
synced 2026-09-07 00:02:53 +08:00
* binarySearch series functions: document and unit test * Fix lint errors * Update * Update * Update
16 lines
552 B
TypeScript
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);
|
|
});
|
|
}); |