@clickup/pg-microsharding
Version:
Microshards support for PostgreSQL
46 lines (40 loc) • 1.48 kB
text/typescript
import { normalizeCellNumbers } from "../normalizeCellNumbers";
test("normalizes if numbers are within the same tenth magnitude", () => {
expect(normalizeCellNumbers([{ a: "123456" }, { a: "456789" }])).toEqual([
{ a: "123K" },
{ a: "457K" },
]);
});
test("does not normalize if the value is too close to the magnitude boundary", () => {
expect(normalizeCellNumbers([{ a: "1234" }, { a: "4567" }])).toEqual([
{ a: "1234" },
{ a: "4567" },
]);
});
test("normalizes if numbers are within the same suffix magnitude", () => {
expect(normalizeCellNumbers([{ a: "12345" }, { a: "456789" }])).toEqual([
{ a: "12K" },
{ a: "457K" },
]);
expect(normalizeCellNumbers([{ a: "12345" }, { a: "4567890" }])).toEqual([
{ a: "12K" },
{ a: "4568K" },
]);
});
test("normalizes if there are short numbers, keeps short numbers short", () => {
expect(
normalizeCellNumbers([{ a: "1" }, { a: "12345" }, { a: "456789" }]),
).toEqual([{ a: "1" }, { a: "12K" }, { a: "457K" }]);
expect(
normalizeCellNumbers([{ a: "" }, { a: "12345" }, { a: "456789" }]),
).toEqual([{ a: "" }, { a: "12K" }, { a: "457K" }]);
});
test("normalizes large number with small suffix if needed", () => {
expect(normalizeCellNumbers([{ a: "12345" }, { a: "123456789" }])).toEqual([
{ a: "12K" },
{ a: "123457K" },
]);
expect(
normalizeCellNumbers([{ a: "123456789" }, { a: "123456789012" }]),
).toEqual([{ a: "123M" }, { a: "123457M" }]);
});