feat: Initial clean release of CHM
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
这个提交包含在:
91
packages/lib/ArrayUtils.test.ts
普通文件
91
packages/lib/ArrayUtils.test.ts
普通文件
@@ -0,0 +1,91 @@
|
||||
import * as ArrayUtils from './ArrayUtils';
|
||||
|
||||
describe('ArrayUtils', () => {
|
||||
|
||||
|
||||
|
||||
it('should return unique elements', (async () => {
|
||||
expect(ArrayUtils.unique(['un', 'deux', 'un', 'trois', 'deux'])).toEqual(['un', 'deux', 'trois']);
|
||||
expect(ArrayUtils.unique([1, 2, 1, 3, 2])).toEqual([1, 2, 3]);
|
||||
expect(ArrayUtils.unique([])).toEqual([]);
|
||||
}));
|
||||
|
||||
it('should remove array elements', (async () => {
|
||||
let a = ['un', 'deux', 'trois'];
|
||||
a = ArrayUtils.removeElement(a, 'deux');
|
||||
|
||||
expect(a[0]).toBe('un');
|
||||
expect(a[1]).toBe('trois');
|
||||
expect(a.length).toBe(2);
|
||||
|
||||
a = ['un', 'deux', 'trois'];
|
||||
a = ArrayUtils.removeElement(a, 'not in there');
|
||||
expect(a.length).toBe(3);
|
||||
}));
|
||||
|
||||
it('should pull array elements', (async () => {
|
||||
expect(ArrayUtils.pull(['a', 'b', 'c', 'a', 'b', 'c'], 'a')).toEqual(['b', 'c', 'b', 'c']);
|
||||
expect(ArrayUtils.pull(['b', 'c', 'b', 'c'], 'a')).toEqual(['b', 'c', 'b', 'c']);
|
||||
expect(ArrayUtils.pull(['a', 'b', 'c', 'a', 'b', 'c'], 'a', 'c')).toEqual(['b', 'b']);
|
||||
expect(ArrayUtils.pull([], 'a')).toEqual([]);
|
||||
}));
|
||||
|
||||
it('should find items using binary search', (async () => {
|
||||
let items = ['aaa', 'ccc', 'bbb'];
|
||||
expect(ArrayUtils.binarySearch(items, 'bbb')).toBe(-1); // Array not sorted!
|
||||
items.sort();
|
||||
expect(ArrayUtils.binarySearch(items, 'bbb')).toBe(1);
|
||||
expect(ArrayUtils.binarySearch(items, 'ccc')).toBe(2);
|
||||
expect(ArrayUtils.binarySearch(items, 'oops')).toBe(-1);
|
||||
expect(ArrayUtils.binarySearch(items, 'aaa')).toBe(0);
|
||||
|
||||
items = [];
|
||||
expect(ArrayUtils.binarySearch(items, 'aaa')).toBe(-1);
|
||||
}));
|
||||
|
||||
it('should compare arrays', (async () => {
|
||||
expect(ArrayUtils.contentEquals([], [])).toBe(true);
|
||||
expect(ArrayUtils.contentEquals(['a'], ['a'])).toBe(true);
|
||||
expect(ArrayUtils.contentEquals(['b', 'a'], ['a', 'b'])).toBe(true);
|
||||
expect(ArrayUtils.contentEquals(['b'], ['a', 'b'])).toBe(false);
|
||||
}));
|
||||
|
||||
it('should merge overlapping intervals', (async () => {
|
||||
const testCases: [[number, number][], [number, number][]][] = [
|
||||
[
|
||||
[],
|
||||
[],
|
||||
],
|
||||
[
|
||||
[[0, 50]],
|
||||
[[0, 50]],
|
||||
],
|
||||
[
|
||||
[[0, 20], [20, 30]],
|
||||
[[0, 30]],
|
||||
],
|
||||
[
|
||||
[[0, 10], [10, 50], [15, 30], [20, 80], [80, 95]],
|
||||
[[0, 95]],
|
||||
],
|
||||
[
|
||||
[[0, 5], [0, 10], [25, 35], [30, 60], [50, 60], [85, 100]],
|
||||
[[0, 10], [25, 60], [85, 100]],
|
||||
],
|
||||
[
|
||||
[[0, 5], [10, 40], [35, 50], [35, 75], [50, 60], [80, 85], [80, 90]],
|
||||
[[0, 5], [10, 75], [80, 90]],
|
||||
],
|
||||
];
|
||||
|
||||
// eslint-disable-next-line github/array-foreach -- Old code before rule was applied
|
||||
testCases.forEach((t) => {
|
||||
const intervals = t[0];
|
||||
const expected = t[1];
|
||||
|
||||
const actual = ArrayUtils.mergeOverlappingIntervals(intervals, intervals.length);
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
}));
|
||||
|
||||
});
|
||||
在新工单中引用
屏蔽一个用户