mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-23 04:38:12 +08:00
934cc5c69b
* Added TS. Updated build and linting config. Added types. * [ts-migrate][.] Rename files from JS/JSX to TS/TSX Co-authored-by: ts-migrate <> * [ts-migrate][.] Run TS Migrate Co-authored-by: ts-migrate <> * Corrected files mangled by ts-migrate. * Updated lint config, minor linting. * Re-enabled Husky. * Updated tests and config. * Reverted webpack devtool config. * Removed obsolete snapshots. * Added annotations snap. * Updated tsconfig includes wrt linting. * Removed ts-migrate. Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>
64 lines
2.0 KiB
TypeScript
64 lines
2.0 KiB
TypeScript
import { rangeEncodeIndices } from "../../src/util/actionHelpers";
|
|
|
|
describe("rangeEncodeIndices", () => {
|
|
test("small array edge cases", () => {
|
|
expect(rangeEncodeIndices([])).toMatchObject([]);
|
|
expect(rangeEncodeIndices([1])).toMatchObject([1]);
|
|
expect(rangeEncodeIndices([1, 99])).toMatchObject([1, 99]);
|
|
expect(rangeEncodeIndices([99, 1])).toMatchObject([1, 99]);
|
|
expect(rangeEncodeIndices([1, 100, 4])).toMatchObject([1, 4, 100]);
|
|
});
|
|
|
|
test("sorted flag", () => {
|
|
expect(rangeEncodeIndices([1, 9, 432], 10, true)).toMatchObject([
|
|
1,
|
|
9,
|
|
432,
|
|
]);
|
|
expect(rangeEncodeIndices([1, 9, 432], 10, false)).toMatchObject([
|
|
1,
|
|
9,
|
|
432,
|
|
]);
|
|
expect(
|
|
rangeEncodeIndices([0, 1, 2, 3, 9, 10, 432], 2, true)
|
|
).toMatchObject([[0, 3], [9, 10], 432]);
|
|
expect(
|
|
rangeEncodeIndices([0, 1, 2, 3, 9, 10, 432], 2, false)
|
|
).toMatchObject([[0, 3], [9, 10], 432]);
|
|
});
|
|
|
|
test("begin or end edge cases", () => {
|
|
expect(
|
|
rangeEncodeIndices([3, 4, 5, 6, 7, 10, 11, 12, 99], 3, false)
|
|
).toMatchObject([[3, 7], [10, 12], 99]);
|
|
expect(
|
|
rangeEncodeIndices([3, 4, 5, 6, 7, 10, 11, 12], 3, false)
|
|
).toMatchObject([
|
|
[3, 7],
|
|
[10, 12],
|
|
]);
|
|
expect(
|
|
rangeEncodeIndices([0, 3, 4, 5, 6, 7, 10, 11, 12], 3, false)
|
|
).toMatchObject([0, [3, 7], [10, 12]]);
|
|
expect(
|
|
rangeEncodeIndices([0, 3, 4, 5, 6, 7, 10, 11, 12, 99], 3, false)
|
|
).toMatchObject([0, [3, 7], [10, 12], 99]);
|
|
});
|
|
|
|
test("minRangeLength", () => {
|
|
expect(
|
|
rangeEncodeIndices([3, 4, 5, 6, 7, 10, 11, 12, 99], 4, false)
|
|
).toMatchObject([[3, 7], 10, 11, 12, 99]);
|
|
expect(
|
|
rangeEncodeIndices([3, 4, 5, 6, 7, 10, 11, 12], 4, false)
|
|
).toMatchObject([[3, 7], 10, 11, 12]);
|
|
expect(
|
|
rangeEncodeIndices([0, 3, 4, 5, 6, 7, 10, 11, 12], 4, false)
|
|
).toMatchObject([0, [3, 7], 10, 11, 12]);
|
|
expect(
|
|
rangeEncodeIndices([0, 3, 4, 5, 6, 7, 10, 11, 12, 99], 4, false)
|
|
).toMatchObject([0, [3, 7], 10, 11, 12, 99]);
|
|
});
|
|
});
|