mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-05 00:58:12 +08:00
Improved summary counts of annotation values (#478)
* convert annotation summary to a Map * add 2d annotation count summary * add memoization on 2D annotation counting * add tests for annotation summarization * fix import/exports * rename WorldOps to WorldUtil * rename WorldOps to WorldUtil * add comment
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import {
|
||||
countCategoryValues2D,
|
||||
clearCaches
|
||||
} from "../../../src/util/stateManager/worldUtil";
|
||||
|
||||
describe("WorldUtil cache management", () => {
|
||||
test("empty", () => {
|
||||
const count = countCategoryValues2D("a", "b", []);
|
||||
expect(count).toMatchObject(new Map());
|
||||
});
|
||||
|
||||
test("simple couts", () => {
|
||||
const rows = [{ a: 0, b: false }, { a: 0, b: true }, { a: 1, b: false }];
|
||||
const count = countCategoryValues2D("a", "b", rows);
|
||||
expect(count).toMatchObject(
|
||||
new Map([
|
||||
[0, new Map([[true, 1], [false, 1]])],
|
||||
[1, new Map([[false, 1]])]
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
test("memo cache clear", () => {
|
||||
clearCaches();
|
||||
const row1 = [];
|
||||
const row2 = [{ a: 0, b: false }, { a: 0, b: true }, { a: 1, b: false }];
|
||||
const count1 = countCategoryValues2D("a", "b", row1);
|
||||
const count2 = countCategoryValues2D("a", "b", row1);
|
||||
const count3 = countCategoryValues2D("a", "b", []);
|
||||
const count4 = countCategoryValues2D("a", "b", row2);
|
||||
|
||||
clearCaches();
|
||||
const count10 = countCategoryValues2D("a", "b", row1);
|
||||
const count11 = countCategoryValues2D("a", "b", row2);
|
||||
|
||||
expect(count1).toEqual(count2);
|
||||
expect(count1).toEqual(count3);
|
||||
expect(count1).toEqual(count10);
|
||||
expect(count1).not.toBe(count3);
|
||||
expect(count1).not.toBe(count10);
|
||||
|
||||
expect(count4).toEqual(count11);
|
||||
expect(count4).not.toBe(count11);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user