@genome-spy/core 0.64.0 → 0.66.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle/{index-CCJIjehY.js → AbortablePromiseCache-CcuMrnn7.js} +22 -91
- package/dist/bundle/browser-BRemItdO.js +138 -0
- package/dist/bundle/index-BatuyGAI.js +271 -0
- package/dist/bundle/index-ByuE8dvu.js +332 -0
- package/dist/bundle/index-Cq3QFUxX.js +1781 -0
- package/dist/bundle/{index-C08YCM2T.js → index-D-w7Mmt9.js} +246 -126
- package/dist/bundle/index-D28m8tSW.js +1607 -0
- package/dist/bundle/index-D74H8TTz.js +508 -0
- package/dist/bundle/index-DbJ0oeYM.js +631 -0
- package/dist/bundle/index.es.js +15034 -13842
- package/dist/bundle/index.js +223 -237
- package/dist/bundle/inflate-GtwLkvSP.js +1048 -0
- package/dist/bundle/unzip-NywezaRR.js +1492 -0
- package/dist/schema.json +22 -4
- package/dist/src/config/scaleDefaults.d.ts +8 -0
- package/dist/src/config/scaleDefaults.d.ts.map +1 -0
- package/dist/src/config/scaleDefaults.js +45 -0
- package/dist/src/data/collector.d.ts +7 -2
- package/dist/src/data/collector.d.ts.map +1 -1
- package/dist/src/data/collector.js +13 -2
- package/dist/src/data/dataFlow.d.ts +20 -42
- package/dist/src/data/dataFlow.d.ts.map +1 -1
- package/dist/src/data/dataFlow.js +57 -80
- package/dist/src/data/flowHandle.d.ts +15 -0
- package/dist/src/data/flowHandle.d.ts.map +1 -0
- package/dist/src/data/flowHandle.js +13 -0
- package/dist/src/data/flowInit.d.ts +85 -0
- package/dist/src/data/flowInit.d.ts.map +1 -0
- package/dist/src/data/flowInit.js +238 -0
- package/dist/src/data/flowInit.test.d.ts +2 -0
- package/dist/src/data/flowInit.test.d.ts.map +1 -0
- package/dist/src/data/flowOptimizer.d.ts +6 -4
- package/dist/src/data/flowOptimizer.d.ts.map +1 -1
- package/dist/src/data/flowOptimizer.js +29 -14
- package/dist/src/data/sources/lazy/axisTickSource.js +1 -1
- package/dist/src/data/sources/lazy/bamSource.js +1 -1
- package/dist/src/data/sources/lazy/bigBedSource.js +1 -1
- package/dist/src/data/sources/lazy/bigWigSource.js +1 -1
- package/dist/src/data/sources/lazy/gff3Source.d.ts +2 -6
- package/dist/src/data/sources/lazy/gff3Source.d.ts.map +1 -1
- package/dist/src/data/sources/lazy/gff3Source.js +4 -8
- package/dist/src/data/sources/lazy/indexedFastaSource.d.ts.map +1 -1
- package/dist/src/data/sources/lazy/indexedFastaSource.js +17 -17
- package/dist/src/data/sources/lazy/singleAxisLazySource.d.ts +1 -1
- package/dist/src/data/sources/lazy/singleAxisLazySource.d.ts.map +1 -1
- package/dist/src/data/sources/lazy/singleAxisLazySource.js +10 -3
- package/dist/src/data/sources/lazy/singleAxisWindowedSource.d.ts.map +1 -1
- package/dist/src/data/sources/lazy/singleAxisWindowedSource.js +5 -1
- package/dist/src/data/sources/lazy/tabixSource.js +1 -1
- package/dist/src/data/transforms/filterScoredLabels.d.ts +1 -1
- package/dist/src/data/transforms/filterScoredLabels.d.ts.map +1 -1
- package/dist/src/data/transforms/filterScoredLabels.js +1 -1
- package/dist/src/data/transforms/linearizeGenomicCoordinate.d.ts.map +1 -1
- package/dist/src/data/transforms/linearizeGenomicCoordinate.js +2 -1
- package/dist/src/encoder/encoder.d.ts +1 -1
- package/dist/src/encoder/encoder.d.ts.map +1 -1
- package/dist/src/encoder/encoder.js +1 -1
- package/dist/src/genome/scaleLocus.d.ts +39 -0
- package/dist/src/genome/scaleLocus.d.ts.map +1 -1
- package/dist/src/genome/scaleLocus.js +76 -0
- package/dist/src/genomeSpy/canvasExport.d.ts +19 -0
- package/dist/src/genomeSpy/canvasExport.d.ts.map +1 -0
- package/dist/src/genomeSpy/canvasExport.js +66 -0
- package/dist/src/genomeSpy/containerUi.d.ts +17 -0
- package/dist/src/genomeSpy/containerUi.d.ts.map +1 -0
- package/dist/src/genomeSpy/containerUi.js +78 -0
- package/dist/src/genomeSpy/eventListenerRegistry.d.ts +19 -0
- package/dist/src/genomeSpy/eventListenerRegistry.d.ts.map +1 -0
- package/dist/src/genomeSpy/eventListenerRegistry.js +38 -0
- package/dist/src/genomeSpy/inputBindingManager.d.ts +14 -0
- package/dist/src/genomeSpy/inputBindingManager.d.ts.map +1 -0
- package/dist/src/genomeSpy/inputBindingManager.js +63 -0
- package/dist/src/genomeSpy/interactionController.d.ts +40 -0
- package/dist/src/genomeSpy/interactionController.d.ts.map +1 -0
- package/dist/src/genomeSpy/interactionController.js +371 -0
- package/dist/src/genomeSpy/keyboardListenerManager.d.ts +10 -0
- package/dist/src/genomeSpy/keyboardListenerManager.d.ts.map +1 -0
- package/dist/src/genomeSpy/keyboardListenerManager.js +31 -0
- package/dist/src/genomeSpy/loadingIndicatorManager.d.ts +15 -0
- package/dist/src/genomeSpy/loadingIndicatorManager.d.ts.map +1 -0
- package/dist/src/genomeSpy/loadingIndicatorManager.js +92 -0
- package/dist/src/genomeSpy/renderCoordinator.d.ts +22 -0
- package/dist/src/genomeSpy/renderCoordinator.d.ts.map +1 -0
- package/dist/src/genomeSpy/renderCoordinator.js +118 -0
- package/dist/src/genomeSpy/viewContextFactory.d.ts +18 -0
- package/dist/src/genomeSpy/viewContextFactory.d.ts.map +1 -0
- package/dist/src/genomeSpy/viewContextFactory.js +79 -0
- package/dist/src/genomeSpy/viewDataInit.d.ts +12 -0
- package/dist/src/genomeSpy/viewDataInit.d.ts.map +1 -0
- package/dist/src/genomeSpy/viewDataInit.js +41 -0
- package/dist/src/genomeSpy/viewHierarchyConfig.d.ts +14 -0
- package/dist/src/genomeSpy/viewHierarchyConfig.d.ts.map +1 -0
- package/dist/src/genomeSpy/viewHierarchyConfig.js +24 -0
- package/dist/src/genomeSpy/viewHighlight.d.ts +5 -0
- package/dist/src/genomeSpy/viewHighlight.d.ts.map +1 -0
- package/dist/src/genomeSpy/viewHighlight.js +30 -0
- package/dist/src/genomeSpy.d.ts +17 -72
- package/dist/src/genomeSpy.d.ts.map +1 -1
- package/dist/src/genomeSpy.js +180 -789
- package/dist/src/gl/glslScaleGenerator.d.ts +1 -1
- package/dist/src/gl/webGLHelper.d.ts +2 -2
- package/dist/src/gl/webGLHelper.d.ts.map +1 -1
- package/dist/src/gl/webGLHelper.js +4 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -12
- package/dist/src/marks/mark.d.ts +1 -0
- package/dist/src/marks/mark.d.ts.map +1 -1
- package/dist/src/marks/mark.js +26 -3
- package/dist/src/{view → scales}/axisResolution.d.ts +12 -14
- package/dist/src/scales/axisResolution.d.ts.map +1 -0
- package/dist/src/{view → scales}/axisResolution.js +38 -12
- package/dist/src/scales/axisResolution.test.d.ts.map +1 -0
- package/dist/src/scales/scaleDomainAggregator.d.ts +57 -0
- package/dist/src/scales/scaleDomainAggregator.d.ts.map +1 -0
- package/dist/src/scales/scaleDomainAggregator.js +162 -0
- package/dist/src/scales/scaleDomainAggregator.test.d.ts +2 -0
- package/dist/src/scales/scaleDomainAggregator.test.d.ts.map +1 -0
- package/dist/src/scales/scaleInstanceManager.d.ts +40 -0
- package/dist/src/scales/scaleInstanceManager.d.ts.map +1 -0
- package/dist/src/scales/scaleInstanceManager.js +313 -0
- package/dist/src/scales/scaleInstanceManager.test.d.ts +2 -0
- package/dist/src/scales/scaleInstanceManager.test.d.ts.map +1 -0
- package/dist/src/scales/scaleInteractionController.d.ts +73 -0
- package/dist/src/scales/scaleInteractionController.d.ts.map +1 -0
- package/dist/src/scales/scaleInteractionController.js +336 -0
- package/dist/src/scales/scaleInteractionController.test.d.ts +2 -0
- package/dist/src/scales/scaleInteractionController.test.d.ts.map +1 -0
- package/dist/src/scales/scalePropsResolver.d.ts +23 -0
- package/dist/src/scales/scalePropsResolver.d.ts.map +1 -0
- package/dist/src/scales/scalePropsResolver.js +74 -0
- package/dist/src/{view → scales}/scaleResolution.d.ts +53 -31
- package/dist/src/scales/scaleResolution.d.ts.map +1 -0
- package/dist/src/scales/scaleResolution.js +658 -0
- package/dist/src/scales/scaleResolution.test.d.ts.map +1 -0
- package/dist/src/scales/scaleResolutionConstants.d.ts +6 -0
- package/dist/src/scales/scaleResolutionConstants.d.ts.map +1 -0
- package/dist/src/scales/scaleResolutionConstants.js +5 -0
- package/dist/src/scales/scaleRules.d.ts +16 -0
- package/dist/src/scales/scaleRules.d.ts.map +1 -0
- package/dist/src/scales/scaleRules.js +103 -0
- package/dist/src/scales/scaleRules.test.d.ts +2 -0
- package/dist/src/scales/scaleRules.test.d.ts.map +1 -0
- package/dist/src/spec/channel.d.ts +13 -18
- package/dist/src/spec/sampleView.d.ts +3 -2
- package/dist/src/spec/scale.d.ts +6 -0
- package/dist/src/types/embedApi.d.ts +5 -0
- package/dist/src/types/scaleResolutionApi.d.ts +1 -1
- package/dist/src/types/viewContext.d.ts +1 -1
- package/dist/src/view/concatView.d.ts +18 -0
- package/dist/src/view/concatView.d.ts.map +1 -1
- package/dist/src/view/concatView.js +73 -0
- package/dist/src/view/concatView.test.d.ts +2 -0
- package/dist/src/view/concatView.test.d.ts.map +1 -0
- package/dist/src/view/containerMutationHelper.d.ts +74 -0
- package/dist/src/view/containerMutationHelper.d.ts.map +1 -0
- package/dist/src/view/containerMutationHelper.js +114 -0
- package/dist/src/view/containerView.d.ts +0 -7
- package/dist/src/view/containerView.d.ts.map +1 -1
- package/dist/src/view/containerView.js +0 -10
- package/dist/src/view/facetView.d.ts.map +1 -1
- package/dist/src/view/facetView.js +0 -14
- package/dist/src/view/flowBuilder.d.ts +2 -2
- package/dist/src/view/flowBuilder.d.ts.map +1 -1
- package/dist/src/view/flowBuilder.js +21 -4
- package/dist/src/view/gridView/gridChild.d.ts +11 -0
- package/dist/src/view/gridView/gridChild.d.ts.map +1 -1
- package/dist/src/view/gridView/gridChild.js +32 -6
- package/dist/src/view/gridView/gridView.d.ts +39 -1
- package/dist/src/view/gridView/gridView.d.ts.map +1 -1
- package/dist/src/view/gridView/gridView.js +113 -42
- package/dist/src/view/gridView/gridView.test.d.ts +2 -0
- package/dist/src/view/gridView/gridView.test.d.ts.map +1 -0
- package/dist/src/view/gridView/scrollbar.d.ts +39 -8
- package/dist/src/view/gridView/scrollbar.d.ts.map +1 -1
- package/dist/src/view/gridView/scrollbar.js +184 -69
- package/dist/src/view/gridView/selectionRect.d.ts +8 -4
- package/dist/src/view/gridView/selectionRect.d.ts.map +1 -1
- package/dist/src/view/gridView/selectionRect.js +28 -3
- package/dist/src/view/gridView/selectionRect.test.d.ts +2 -0
- package/dist/src/view/gridView/selectionRect.test.d.ts.map +1 -0
- package/dist/src/view/layerView.d.ts +14 -0
- package/dist/src/view/layerView.d.ts.map +1 -1
- package/dist/src/view/layerView.js +66 -0
- package/dist/src/view/layerView.test.d.ts +2 -0
- package/dist/src/view/layerView.test.d.ts.map +1 -0
- package/dist/src/view/paramMediator.d.ts +2 -1
- package/dist/src/view/paramMediator.d.ts.map +1 -1
- package/dist/src/view/paramMediator.js +13 -1
- package/dist/src/view/testUtils.d.ts.map +1 -1
- package/dist/src/view/testUtils.js +18 -5
- package/dist/src/view/unitView.d.ts.map +1 -1
- package/dist/src/view/unitView.js +52 -12
- package/dist/src/view/view.d.ts +23 -7
- package/dist/src/view/view.d.ts.map +1 -1
- package/dist/src/view/view.js +61 -5
- package/dist/src/view/viewDispose.test.d.ts +2 -0
- package/dist/src/view/viewDispose.test.d.ts.map +1 -0
- package/dist/src/view/viewUtils.d.ts +4 -4
- package/dist/src/view/viewUtils.d.ts.map +1 -1
- package/dist/src/view/viewUtils.js +19 -15
- package/dist/src/view/viewUtils.test.d.ts +2 -0
- package/dist/src/view/viewUtils.test.d.ts.map +1 -0
- package/package.json +10 -10
- package/dist/bundle/__vite-browser-external-C--ziKoh.js +0 -8
- package/dist/bundle/_commonjsHelpers-DjF3Plf2.js +0 -26
- package/dist/bundle/index-5ajWdKly.js +0 -1319
- package/dist/bundle/index-B03-Om4z.js +0 -274
- package/dist/bundle/index-BftNdA0O.js +0 -27
- package/dist/bundle/index-Bg7C4Xat.js +0 -2750
- package/dist/bundle/index-C3QR8Lv6.js +0 -2131
- package/dist/bundle/index-DTcHjAHp.js +0 -505
- package/dist/bundle/index-DnIkxb0L.js +0 -1025
- package/dist/bundle/index-Ww3TAo6_.js +0 -71
- package/dist/bundle/index-g8iXgW0W.js +0 -651
- package/dist/bundle/long-B-FASCSo.js +0 -2387
- package/dist/bundle/remoteFile-BuaqFGWk.js +0 -94
- package/dist/src/data/collector.test.js +0 -138
- package/dist/src/data/dataFlow.test.js +0 -5
- package/dist/src/data/flow.test.js +0 -81
- package/dist/src/data/flowNode.test.js +0 -50
- package/dist/src/data/flowOptimizer.test.js +0 -204
- package/dist/src/data/formats/fasta.test.js +0 -27
- package/dist/src/data/sources/inlineSource.test.js +0 -63
- package/dist/src/data/sources/sequenceSource.test.js +0 -81
- package/dist/src/data/transforms/aggregate.test.js +0 -134
- package/dist/src/data/transforms/clone.test.js +0 -11
- package/dist/src/data/transforms/coverage.test.js +0 -238
- package/dist/src/data/transforms/filter.test.js +0 -20
- package/dist/src/data/transforms/flatten.test.js +0 -96
- package/dist/src/data/transforms/flattenDelimited.test.js +0 -90
- package/dist/src/data/transforms/flattenSequence.test.js +0 -34
- package/dist/src/data/transforms/formula.test.js +0 -25
- package/dist/src/data/transforms/identifier.test.js +0 -92
- package/dist/src/data/transforms/pileup.test.js +0 -70
- package/dist/src/data/transforms/project.test.js +0 -32
- package/dist/src/data/transforms/regexExtract.test.js +0 -70
- package/dist/src/data/transforms/regexFold.test.js +0 -201
- package/dist/src/data/transforms/sample.test.js +0 -38
- package/dist/src/data/transforms/stack.test.js +0 -91
- package/dist/src/encoder/accessor.test.js +0 -162
- package/dist/src/encoder/encoder.test.js +0 -105
- package/dist/src/genome/genome.test.js +0 -268
- package/dist/src/genome/genomes.test.js +0 -8
- package/dist/src/genome/scaleIndex.test.js +0 -78
- package/dist/src/genome/scaleLocus.test.js +0 -4
- package/dist/src/scale/scale.test.js +0 -326
- package/dist/src/scale/ticks.test.js +0 -46
- package/dist/src/selection/selection.test.js +0 -14
- package/dist/src/utils/addBaseUrl.test.js +0 -30
- package/dist/src/utils/binnedIndex.test.js +0 -201
- package/dist/src/utils/cloner.test.js +0 -35
- package/dist/src/utils/coalesce.test.js +0 -16
- package/dist/src/utils/concatIterables.test.js +0 -8
- package/dist/src/utils/domainArray.test.js +0 -130
- package/dist/src/utils/indexer.test.js +0 -49
- package/dist/src/utils/interactionEvent.test.js +0 -35
- package/dist/src/utils/iterateNestedMaps.test.js +0 -33
- package/dist/src/utils/kWayMerge.test.js +0 -30
- package/dist/src/utils/mergeObjects.test.js +0 -42
- package/dist/src/utils/numberExtractor.test.js +0 -6
- package/dist/src/utils/propertyCacher.test.js +0 -89
- package/dist/src/utils/propertyCoalescer.test.js +0 -25
- package/dist/src/utils/radixSort.test.js +0 -51
- package/dist/src/utils/reservationMap.test.js +0 -20
- package/dist/src/utils/ringBuffer.test.js +0 -39
- package/dist/src/utils/topK.test.js +0 -54
- package/dist/src/utils/trees.test.js +0 -135
- package/dist/src/utils/url.test.js +0 -28
- package/dist/src/utils/variableTools.test.js +0 -13
- package/dist/src/view/axisResolution.d.ts.map +0 -1
- package/dist/src/view/axisResolution.test.d.ts.map +0 -1
- package/dist/src/view/axisResolution.test.js +0 -206
- package/dist/src/view/flowBuilder.test.js +0 -125
- package/dist/src/view/layout/flexLayout.test.js +0 -323
- package/dist/src/view/layout/grid.test.js +0 -71
- package/dist/src/view/layout/rectangle.test.js +0 -192
- package/dist/src/view/paramMediator.test.js +0 -260
- package/dist/src/view/scaleResolution.d.ts.map +0 -1
- package/dist/src/view/scaleResolution.js +0 -1049
- package/dist/src/view/scaleResolution.test.d.ts.map +0 -1
- package/dist/src/view/scaleResolution.test.js +0 -645
- package/dist/src/view/view.test.js +0 -245
- package/dist/src/view/viewFactory.test.js +0 -25
- /package/dist/src/{view → scales}/axisResolution.test.d.ts +0 -0
- /package/dist/src/{view → scales}/scaleResolution.test.d.ts +0 -0
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "vitest";
|
|
2
|
-
import createDomain, {
|
|
3
|
-
toRegularArray as r,
|
|
4
|
-
PiecewiseDomain,
|
|
5
|
-
} from "./domainArray.js";
|
|
6
|
-
|
|
7
|
-
describe("Build quantitative domains", () => {
|
|
8
|
-
test("Empty domain", () => {
|
|
9
|
-
const b = createDomain("quantitative");
|
|
10
|
-
expect(r(b)).toEqual([]);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test("Extends by one value at a time", () => {
|
|
14
|
-
const b = createDomain("quantitative");
|
|
15
|
-
b.extend(2);
|
|
16
|
-
b.extend(1);
|
|
17
|
-
b.extend(null);
|
|
18
|
-
b.extend(undefined);
|
|
19
|
-
b.extend(NaN);
|
|
20
|
-
b.extend(5);
|
|
21
|
-
b.extend(4);
|
|
22
|
-
expect(r(b)).toEqual([1, 5]);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test("Extends with an iterable", () => {
|
|
26
|
-
const b = createDomain("quantitative");
|
|
27
|
-
b.extendAll([2, 1, null, undefined, NaN, 5, 4]);
|
|
28
|
-
expect(r(b)).toEqual([1, 5]);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test("Extends with an iterable and an accessor", () => {
|
|
32
|
-
const b = createDomain("quantitative");
|
|
33
|
-
b.extendAllWithAccessor(
|
|
34
|
-
[
|
|
35
|
-
{ x: 2 },
|
|
36
|
-
{ x: 1 },
|
|
37
|
-
{ x: null },
|
|
38
|
-
{ x: undefined },
|
|
39
|
-
{ x: NaN },
|
|
40
|
-
{ x: 5 },
|
|
41
|
-
{ x: 4 },
|
|
42
|
-
],
|
|
43
|
-
(d) => d.x
|
|
44
|
-
);
|
|
45
|
-
expect(r(b)).toEqual([1, 5]);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test("Coerces to number", () => {
|
|
49
|
-
const b = createDomain("quantitative");
|
|
50
|
-
expect(r(b.extend("123"))).toEqual([123, 123]);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe("Build ordinal domains", () => {
|
|
55
|
-
// Note: nominal is an unordered abstraction of ordinal. Testing just ordinal is enough.
|
|
56
|
-
|
|
57
|
-
test("Empty domain", () => {
|
|
58
|
-
const b = createDomain("ordinal");
|
|
59
|
-
expect(r(b)).toEqual([]);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test("Extends by one value at a time, preserves order", () => {
|
|
63
|
-
const b = createDomain("ordinal");
|
|
64
|
-
b.extend("a");
|
|
65
|
-
b.extend("b");
|
|
66
|
-
b.extend("c");
|
|
67
|
-
b.extend("b");
|
|
68
|
-
b.extend(null);
|
|
69
|
-
b.extend(undefined);
|
|
70
|
-
b.extend(NaN);
|
|
71
|
-
b.extend("d");
|
|
72
|
-
expect(r(b)).toEqual(["a", "b", "c", "d"]);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
describe("Build piecewise domains", () => {
|
|
77
|
-
test("Creates a piecewise domain", () => {
|
|
78
|
-
expect(createDomain("quantitative", [1])).toBeInstanceOf(
|
|
79
|
-
PiecewiseDomain
|
|
80
|
-
);
|
|
81
|
-
expect(createDomain("quantitative", [1, 2, 3])).toBeInstanceOf(
|
|
82
|
-
PiecewiseDomain
|
|
83
|
-
);
|
|
84
|
-
expect(createDomain("quantitative", [1, 2, 3, 4])).toBeInstanceOf(
|
|
85
|
-
PiecewiseDomain
|
|
86
|
-
);
|
|
87
|
-
expect(createDomain("quantitative", [3, 2, 1])).toBeInstanceOf(
|
|
88
|
-
PiecewiseDomain
|
|
89
|
-
);
|
|
90
|
-
expect(r(createDomain("quantitative", [3, 2, 1]))).toEqual([3, 2, 1]);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test("Throws on domain that is not stricly increasing or decreasing", () => {
|
|
94
|
-
expect(() => createDomain("quantitative", [2, 1, 3])).toThrow();
|
|
95
|
-
expect(() => createDomain("quantitative", [2, 3, 1])).toThrow();
|
|
96
|
-
expect(() => createDomain("quantitative", [3, 0, 2])).toThrow();
|
|
97
|
-
expect(() => createDomain("quantitative", [0, 3, 2])).toThrow();
|
|
98
|
-
expect(() => createDomain("quantitative", [1, 2, 2, 3])).toThrow();
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test("Throws on mutation attempts", () => {
|
|
102
|
-
expect(() =>
|
|
103
|
-
createDomain("quantitative", [1, 2, 3]).extend(4)
|
|
104
|
-
).toThrow();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test("Does not throw when extending with existing value", () => {
|
|
108
|
-
expect(r(createDomain("quantitative", [1, 2, 3]).extend(2))).toEqual([
|
|
109
|
-
1, 2, 3,
|
|
110
|
-
]);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
describe("Annotations", () => {
|
|
115
|
-
test("Quantitative domain is annotated", () =>
|
|
116
|
-
expect(createDomain("quantitative").type).toEqual("quantitative"));
|
|
117
|
-
|
|
118
|
-
test("Ordinal domain is annotated", () =>
|
|
119
|
-
expect(createDomain("ordinal").type).toEqual("ordinal"));
|
|
120
|
-
|
|
121
|
-
test("Nominal domain is annotated", () =>
|
|
122
|
-
expect(createDomain("nominal").type).toEqual("nominal"));
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
describe("Other stuff", () => {
|
|
126
|
-
test("Throws on extending by other type of domain array", () =>
|
|
127
|
-
expect(() =>
|
|
128
|
-
createDomain("quantitative").extendAll(createDomain("nominal"))
|
|
129
|
-
).toThrow());
|
|
130
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "vitest";
|
|
2
|
-
import createIndexer from "./indexer.js";
|
|
3
|
-
|
|
4
|
-
test("Index values one by one", () => {
|
|
5
|
-
const indexer = createIndexer();
|
|
6
|
-
|
|
7
|
-
expect(indexer("a")).toEqual(0);
|
|
8
|
-
expect(indexer("b")).toEqual(1);
|
|
9
|
-
expect(indexer("c")).toEqual(2);
|
|
10
|
-
expect(indexer("a")).toEqual(0);
|
|
11
|
-
expect(indexer("a")).toEqual(0);
|
|
12
|
-
expect(indexer("c")).toEqual(2);
|
|
13
|
-
expect(indexer("c")).toEqual(2);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test("Index multiple values (predefined domain)", () => {
|
|
17
|
-
const indexer = createIndexer();
|
|
18
|
-
|
|
19
|
-
indexer.addAll(["a", "b", "c"]);
|
|
20
|
-
|
|
21
|
-
expect(indexer("d")).toEqual(3);
|
|
22
|
-
expect(indexer("a")).toEqual(0);
|
|
23
|
-
expect(indexer("b")).toEqual(1);
|
|
24
|
-
expect(indexer("c")).toEqual(2);
|
|
25
|
-
expect(indexer("d")).toEqual(3);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test("Indexer inverts index numbers", () => {
|
|
29
|
-
const indexer = createIndexer();
|
|
30
|
-
|
|
31
|
-
indexer.addAll(["a", "b", "c"]);
|
|
32
|
-
|
|
33
|
-
expect(indexer.invert(0)).toEqual("a");
|
|
34
|
-
expect(indexer.invert(1)).toEqual("b");
|
|
35
|
-
expect(indexer.invert(2)).toEqual("c");
|
|
36
|
-
expect(indexer.invert(3)).toBeUndefined();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test("Indexer return correct domain", () => {
|
|
40
|
-
const indexer = createIndexer();
|
|
41
|
-
|
|
42
|
-
expect(indexer("a")).toEqual(0);
|
|
43
|
-
expect(indexer("b")).toEqual(1);
|
|
44
|
-
expect(indexer("c")).toEqual(2);
|
|
45
|
-
expect(indexer("a")).toEqual(0);
|
|
46
|
-
expect(indexer("c")).toEqual(2);
|
|
47
|
-
|
|
48
|
-
expect(indexer.domain()).toEqual(["a", "b", "c"]);
|
|
49
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { createPrimitiveEventProxy } from "./interactionEvent.js";
|
|
3
|
-
|
|
4
|
-
describe("createPrimitiveEventProxy", () => {
|
|
5
|
-
it("exposes primitive properties and hides non-primitives", () => {
|
|
6
|
-
const mock = {
|
|
7
|
-
type: "click",
|
|
8
|
-
clientX: 42,
|
|
9
|
-
meta: { foo: "bar" },
|
|
10
|
-
nested: { a: 1 },
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/** @type {any} */
|
|
14
|
-
const proxy = createPrimitiveEventProxy(mock);
|
|
15
|
-
|
|
16
|
-
// allowed primitives
|
|
17
|
-
expect(proxy.type).toBe("click");
|
|
18
|
-
expect(proxy.clientX).toBe(42);
|
|
19
|
-
|
|
20
|
-
// non-primitive access throws
|
|
21
|
-
expect(() => proxy.meta).toThrow(/non-primitive/);
|
|
22
|
-
|
|
23
|
-
// keys enumeration hides non-primitives
|
|
24
|
-
const keys = Object.keys(proxy);
|
|
25
|
-
expect(keys).toContain("type");
|
|
26
|
-
expect(keys).not.toContain("meta");
|
|
27
|
-
|
|
28
|
-
// `in` operator respects the policy
|
|
29
|
-
expect("type" in proxy).toBe(true);
|
|
30
|
-
expect("meta" in proxy).toBe(false);
|
|
31
|
-
|
|
32
|
-
// prototype is hidden
|
|
33
|
-
expect(Object.getPrototypeOf(proxy)).toBeNull();
|
|
34
|
-
});
|
|
35
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "vitest";
|
|
2
|
-
import { group } from "d3-array";
|
|
3
|
-
import iterateNestedMaps from "./iterateNestedMaps.js";
|
|
4
|
-
|
|
5
|
-
const data = [
|
|
6
|
-
{ name: "jim", amount: "34.0", date: "11/12/2015" },
|
|
7
|
-
{ name: "carl", amount: "120.11", date: "11/12/2015" },
|
|
8
|
-
{ name: "stacy", amount: "12.01", date: "01/04/2016" },
|
|
9
|
-
{ name: "stacy", amount: "34.05", date: "01/04/2016" },
|
|
10
|
-
{ name: "stacy", amount: "1.5", date: "02/04/2016" },
|
|
11
|
-
];
|
|
12
|
-
|
|
13
|
-
const groups = group(
|
|
14
|
-
data,
|
|
15
|
-
(d) => d.name,
|
|
16
|
-
(d) => d.date
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
test("iterateNestedMaps iterates correctly", () => {
|
|
20
|
-
const expected = [
|
|
21
|
-
[["jim", "11/12/2015"], [data[0]]],
|
|
22
|
-
[["carl", "11/12/2015"], [data[1]]],
|
|
23
|
-
[
|
|
24
|
-
["stacy", "01/04/2016"],
|
|
25
|
-
[data[2], data[3]],
|
|
26
|
-
],
|
|
27
|
-
[["stacy", "02/04/2016"], [data[4]]],
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
const result = [...iterateNestedMaps(groups)];
|
|
31
|
-
|
|
32
|
-
expect(result).toEqual(expected);
|
|
33
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "vitest";
|
|
2
|
-
import kWayMerge from "./kWayMerge.js";
|
|
3
|
-
|
|
4
|
-
test("k-way merge merges multiple sorted arrays", () => {
|
|
5
|
-
/** @type {{a: number}[][]} */
|
|
6
|
-
const arrays = [];
|
|
7
|
-
|
|
8
|
-
for (let a = 0; a < 20; a++) {
|
|
9
|
-
/** @type {{a: number}[]} */
|
|
10
|
-
const array = [];
|
|
11
|
-
arrays.push(array);
|
|
12
|
-
|
|
13
|
-
let x = 0;
|
|
14
|
-
for (let i = 0; i < a; i++) {
|
|
15
|
-
x += Math.floor(Math.random() * 10);
|
|
16
|
-
array.push({ a: x });
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const sorted = arrays.flat().sort((a, b) => a.a - b.a);
|
|
21
|
-
|
|
22
|
-
/** @type {function(any):number} */
|
|
23
|
-
const accessor = (d) => d.a;
|
|
24
|
-
|
|
25
|
-
/** @type {{a: number}[]} */
|
|
26
|
-
const result = [];
|
|
27
|
-
kWayMerge(arrays, (d) => result.push(d), accessor);
|
|
28
|
-
|
|
29
|
-
expect(result).toEqual(sorted);
|
|
30
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "vitest";
|
|
2
|
-
import mergeObjects from "./mergeObjects.js";
|
|
3
|
-
|
|
4
|
-
test("Merges non-conflicting properties", () => {
|
|
5
|
-
expect(mergeObjects([{ a: 1 }, { b: 2 }], "test")).toEqual({ a: 1, b: 2 });
|
|
6
|
-
|
|
7
|
-
expect(mergeObjects([{ a: [0, 1] }, { b: [2, 3] }], "test")).toEqual({
|
|
8
|
-
a: [0, 1],
|
|
9
|
-
b: [2, 3],
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test("Skips conflicting properties", () => {
|
|
14
|
-
expect(
|
|
15
|
-
mergeObjects(
|
|
16
|
-
[
|
|
17
|
-
{ a: 1, b: 2, c: 3 },
|
|
18
|
-
{ b: 5, d: 4 },
|
|
19
|
-
],
|
|
20
|
-
"test"
|
|
21
|
-
)
|
|
22
|
-
).toEqual({ a: 1, b: 2, c: 3, d: 4 });
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test("Null is handled correctly", () => {
|
|
26
|
-
expect(mergeObjects([null, null, null], "test")).toBeNull();
|
|
27
|
-
expect(() => mergeObjects([{ a: 1 }, null, { b: 2 }], "test")).toThrow();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test("Nested objects are merged", () => {
|
|
31
|
-
expect(
|
|
32
|
-
mergeObjects([{ nested: { a: 1 } }, { nested: { b: 2 } }], "test")
|
|
33
|
-
).toEqual({ nested: { a: 1, b: 2 } });
|
|
34
|
-
|
|
35
|
-
expect(
|
|
36
|
-
mergeObjects([{ nested: { a: 1 } }, { nested: true }], "test")
|
|
37
|
-
).toEqual({ nested: { a: 1 } });
|
|
38
|
-
|
|
39
|
-
expect(
|
|
40
|
-
mergeObjects([{ nested: true }, { nested: { a: 1 } }], "test")
|
|
41
|
-
).toEqual({ nested: { a: 1 } });
|
|
42
|
-
});
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
getCachedOrCall,
|
|
4
|
-
invalidate,
|
|
5
|
-
invalidateAll,
|
|
6
|
-
} from "./propertyCacher.js";
|
|
7
|
-
|
|
8
|
-
class TestClass {
|
|
9
|
-
constructor() {
|
|
10
|
-
/** @type {number} */
|
|
11
|
-
this._x;
|
|
12
|
-
/** @type {number} */
|
|
13
|
-
this._y;
|
|
14
|
-
|
|
15
|
-
this._xCalls = 0;
|
|
16
|
-
this._yCalls = 0;
|
|
17
|
-
|
|
18
|
-
this.resetAll();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
get x() {
|
|
22
|
-
return getCachedOrCall(this, "x", () => {
|
|
23
|
-
this._xCalls++;
|
|
24
|
-
return this._x;
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
set x(x) {
|
|
29
|
-
this._x = x;
|
|
30
|
-
invalidate(this, "x");
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
get y() {
|
|
34
|
-
return getCachedOrCall(this, "y", () => {
|
|
35
|
-
this._yCalls++;
|
|
36
|
-
return this._y;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
set y(y) {
|
|
41
|
-
this._y = y;
|
|
42
|
-
invalidate(this, "y");
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
resetAll() {
|
|
46
|
-
this._x = 10;
|
|
47
|
-
this._y = 20;
|
|
48
|
-
invalidateAll(this);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
test("Initial cached get returns correct values and calls callable only once", () => {
|
|
53
|
-
const instance = new TestClass();
|
|
54
|
-
|
|
55
|
-
expect(instance._xCalls).toEqual(0);
|
|
56
|
-
expect(instance.x).toEqual(10);
|
|
57
|
-
expect(instance._xCalls).toEqual(1);
|
|
58
|
-
expect(instance.x).toEqual(10);
|
|
59
|
-
expect(instance._xCalls).toEqual(1);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test("Invalidate invalidates", () => {
|
|
63
|
-
const instance = new TestClass();
|
|
64
|
-
|
|
65
|
-
expect(instance._xCalls).toEqual(0);
|
|
66
|
-
expect(instance.x).toEqual(10);
|
|
67
|
-
expect(instance._xCalls).toEqual(1);
|
|
68
|
-
|
|
69
|
-
instance.x = 123;
|
|
70
|
-
expect(instance._xCalls).toEqual(1);
|
|
71
|
-
|
|
72
|
-
expect(instance.x).toEqual(123);
|
|
73
|
-
expect(instance._xCalls).toEqual(2);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test("InvalidateAll invalidates everything", () => {
|
|
77
|
-
const instance = new TestClass();
|
|
78
|
-
|
|
79
|
-
instance.x = 123;
|
|
80
|
-
instance.y = 321;
|
|
81
|
-
|
|
82
|
-
expect(instance.x).toEqual(123);
|
|
83
|
-
expect(instance.y).toEqual(321);
|
|
84
|
-
|
|
85
|
-
instance.resetAll();
|
|
86
|
-
|
|
87
|
-
expect(instance.x).toEqual(10);
|
|
88
|
-
expect(instance.y).toEqual(20);
|
|
89
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "vitest";
|
|
2
|
-
import coalesceProperties from "./propertyCoalescer.js";
|
|
3
|
-
|
|
4
|
-
test("CoalesceProperties works as expected", () => {
|
|
5
|
-
const defaults = { a: 10, b: 11 };
|
|
6
|
-
const props = { a: 1, c: 2 };
|
|
7
|
-
|
|
8
|
-
const coalesced = coalesceProperties(
|
|
9
|
-
() => props,
|
|
10
|
-
// @ts-expect-error
|
|
11
|
-
() => defaults
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
expect(coalesced.a).toEqual(1);
|
|
15
|
-
// @ts-expect-error
|
|
16
|
-
expect(coalesced.b).toEqual(11);
|
|
17
|
-
expect(coalesced.c).toEqual(2);
|
|
18
|
-
// @ts-expect-error
|
|
19
|
-
expect(coalesced.undef).toBeUndefined();
|
|
20
|
-
|
|
21
|
-
expect("a" in coalesced).toBeTruthy();
|
|
22
|
-
expect("b" in coalesced).toBeTruthy();
|
|
23
|
-
expect("c" in coalesced).toBeTruthy();
|
|
24
|
-
expect("undef" in coalesced).toBeFalsy();
|
|
25
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "vitest";
|
|
2
|
-
import radixSort, { radixSortIntoLookupArray } from "./radixSort.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Checks that numbers in an array are in ascending order.
|
|
6
|
-
|
|
7
|
-
* @param {number[]} arr An array of unsigned integers
|
|
8
|
-
*/
|
|
9
|
-
function isSorted(arr) {
|
|
10
|
-
for (let i = 1; i < arr.length; i++) {
|
|
11
|
-
if (arr[i - 1] > arr[i]) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Generates a random array of unsigned integers.
|
|
21
|
-
*
|
|
22
|
-
* @param {number} length
|
|
23
|
-
*/
|
|
24
|
-
function generateArray(length) {
|
|
25
|
-
const arr = new Array(length);
|
|
26
|
-
|
|
27
|
-
for (let i = 0; i < length; i++) {
|
|
28
|
-
arr[i] = Math.floor(Math.random() * 10_000_000_000);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return arr;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
test("Radix Sort correctly sorts numbers", () => {
|
|
35
|
-
expect(isSorted(radixSort([1, 2, 3]))).toBeTruthy();
|
|
36
|
-
expect(isSorted(radixSort([3, 2, 1]))).toBeTruthy();
|
|
37
|
-
expect(isSorted(radixSort([123, 1234567, 12, 1, 1234]))).toBeTruthy();
|
|
38
|
-
expect(isSorted(radixSort(generateArray(1_000_000)))).toBeTruthy();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test("Lookup", () => {
|
|
42
|
-
expect(radixSortIntoLookupArray([1, 2, 3])).toEqual([0, 1, 2]);
|
|
43
|
-
expect(radixSortIntoLookupArray([3, 2, 1])).toEqual([2, 1, 0]);
|
|
44
|
-
expect(radixSortIntoLookupArray([10000, 100, 1000, 10, 1])).toEqual([
|
|
45
|
-
4, 3, 1, 2, 0,
|
|
46
|
-
]);
|
|
47
|
-
|
|
48
|
-
const arr = generateArray(1_000_000);
|
|
49
|
-
const lookup = radixSortIntoLookupArray(arr);
|
|
50
|
-
expect(isSorted(arr.map((_, i) => arr[lookup[i]]))).toBeTruthy();
|
|
51
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "vitest";
|
|
2
|
-
import ReservationMap from "./reservationMap.js";
|
|
3
|
-
|
|
4
|
-
test("ReservationMap works correctly", () => {
|
|
5
|
-
const m = new ReservationMap(20);
|
|
6
|
-
|
|
7
|
-
expect(m.reserve(0, 3)).toBeTruthy();
|
|
8
|
-
expect(m.reserve(15, 17)).toBeTruthy();
|
|
9
|
-
expect(m.reserve(5, 11)).toBeTruthy();
|
|
10
|
-
expect(m.reserve(19, 22)).toBeTruthy();
|
|
11
|
-
expect(m.reserve(23, 26)).toBeTruthy();
|
|
12
|
-
expect(m.reserve(12, 13)).toBeTruthy();
|
|
13
|
-
expect(m.reserve(13, 14)).toBeTruthy();
|
|
14
|
-
expect(m.reserve(4, 5)).toBeTruthy();
|
|
15
|
-
|
|
16
|
-
expect(m.reserve(6, 8)).toBeFalsy();
|
|
17
|
-
expect(m.reserve(10, 13)).toBeFalsy();
|
|
18
|
-
expect(m.reserve(-2, 1)).toBeFalsy();
|
|
19
|
-
expect(m.reserve(25, 28)).toBeFalsy();
|
|
20
|
-
});
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "vitest";
|
|
2
|
-
import RingBuffer from "./ringBuffer.js";
|
|
3
|
-
|
|
4
|
-
describe("ringBuffer", () => {
|
|
5
|
-
test("Empty buffer", () => {
|
|
6
|
-
const buffer = new RingBuffer(10);
|
|
7
|
-
expect(buffer.length).toBe(0);
|
|
8
|
-
expect(buffer.get()).toEqual([]);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test("Partially filled buffer", () => {
|
|
12
|
-
const buffer = new RingBuffer(10);
|
|
13
|
-
buffer.push(1);
|
|
14
|
-
buffer.push(2);
|
|
15
|
-
buffer.push(3);
|
|
16
|
-
expect(buffer.length).toBe(3);
|
|
17
|
-
expect(buffer.get()).toEqual([1, 2, 3]);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test("Full buffer", () => {
|
|
21
|
-
const buffer = new RingBuffer(3);
|
|
22
|
-
buffer.push(1);
|
|
23
|
-
buffer.push(2);
|
|
24
|
-
buffer.push(3);
|
|
25
|
-
expect(buffer.length).toBe(3);
|
|
26
|
-
expect(buffer.get()).toEqual([1, 2, 3]);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test("Overfilled buffer", () => {
|
|
30
|
-
const buffer = new RingBuffer(3);
|
|
31
|
-
buffer.push(1);
|
|
32
|
-
buffer.push(2);
|
|
33
|
-
buffer.push(3);
|
|
34
|
-
buffer.push(4);
|
|
35
|
-
buffer.push(5);
|
|
36
|
-
expect(buffer.length).toBe(3);
|
|
37
|
-
expect(buffer.get()).toEqual([3, 4, 5]);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "vitest";
|
|
2
|
-
import { topK } from "./topK.js";
|
|
3
|
-
|
|
4
|
-
test("topK returns top k numbers in priority order", () => {
|
|
5
|
-
/** @param {number} x */
|
|
6
|
-
const priorityAccessor = (x) => x;
|
|
7
|
-
|
|
8
|
-
expect(topK([1, 2, 3], 3, priorityAccessor)).toEqual([3, 2, 1]);
|
|
9
|
-
expect(topK([1, 2, 3], 1, priorityAccessor)).toEqual([3]);
|
|
10
|
-
expect(topK([1, 2, 3], 6, priorityAccessor)).toEqual([3, 2, 1]);
|
|
11
|
-
expect(topK([1, 2, 3, 4, 5, 6], 3, priorityAccessor)).toEqual([6, 5, 4]);
|
|
12
|
-
expect(topK([0, 9, 1, 8, 2, 7, 3, 6, 4, 5], 3, priorityAccessor)).toEqual([
|
|
13
|
-
9, 8, 7,
|
|
14
|
-
]);
|
|
15
|
-
expect(topK([1, 1, 1], 3, priorityAccessor)).toEqual([1, 1, 1]);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test("topK returns top k objects in priority order within a start-end range", () => {
|
|
19
|
-
const arr = [0, 9, 1, 8, 2, 7, 3, 6, 4, 5].map((x) => ({ priority: x }));
|
|
20
|
-
const priorityAccessor = (/** @type {{priority: number}} */ d) =>
|
|
21
|
-
d.priority;
|
|
22
|
-
|
|
23
|
-
// Range: indices 2 to 8 (1,8,2,7,3,6)
|
|
24
|
-
expect(topK(arr, 2, priorityAccessor, 2, 8)).toEqual([
|
|
25
|
-
{ priority: 8 },
|
|
26
|
-
{ priority: 7 },
|
|
27
|
-
]);
|
|
28
|
-
|
|
29
|
-
// Range: indices 4 to 10 (2,7,3,6,4,5)
|
|
30
|
-
expect(topK(arr, 3, priorityAccessor, 4, 10)).toEqual([
|
|
31
|
-
{ priority: 7 },
|
|
32
|
-
{ priority: 6 },
|
|
33
|
-
{ priority: 5 },
|
|
34
|
-
]);
|
|
35
|
-
|
|
36
|
-
// Range: indices 0 to 3 (0,9,1)
|
|
37
|
-
expect(topK(arr, 2, priorityAccessor, 0, 3)).toEqual([
|
|
38
|
-
{ priority: 9 },
|
|
39
|
-
{ priority: 1 },
|
|
40
|
-
]);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test("topK returns empty array if start >= end", () => {
|
|
44
|
-
const arr = [1, 2, 3, 4, 5];
|
|
45
|
-
expect(topK(arr, 3, (x) => x, 4, 4)).toEqual([]);
|
|
46
|
-
expect(topK(arr, 3, (x) => x, 5, 5)).toEqual([]);
|
|
47
|
-
expect(topK(arr, 3, (x) => x, 6, 6)).toEqual([]);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test("topK works with negative and zero priorities in a range", () => {
|
|
51
|
-
const arr = [-10, 0, 5, -2, 3, 0, -1];
|
|
52
|
-
expect(topK(arr, 2, (x) => x, 1, 6)).toEqual([5, 3]);
|
|
53
|
-
expect(topK(arr, 3, (x) => x, 0, 4)).toEqual([5, 0, -2]);
|
|
54
|
-
});
|