import { formatNumberToCompactString, bigIntMax, normalizePrecision, } from "./numbers" describe("formatNumberToCompactString", () => { it("formats number less than 1000 with decimals", () => { expect(formatNumberToCompactString(123.456789, 2)).toBe("123.46") }) it("formats thousands with K", () => { expect(formatNumberToCompactString(12_345, 2)).toBe("12.35K") }) it("formats millions with M", () => { expect(formatNumberToCompactString(12_345_678, 2)).toBe("12.35M") }) it("formats billions with B", () => { expect(formatNumberToCompactString(12_345_678_901, 2)).toBe("12.35B") }) it("formats trillions with T", () => { expect(formatNumberToCompactString(12_345_678_901_234, 2)).toBe("12.35T") }) it("formats bigint as readable number", () => { expect(formatNumberToCompactString(1234567890123456789n, 2)).toBe( "1,234,567.89T", ) }) it("caps at > 1000T for huge numbers", () => { const hugeNumber = 10 ** 18 // 1e18 expect(formatNumberToCompactString(hugeNumber, 2)).toBe("1,000,000T") }) it("formats numbers with trailing zeros correctly", () => { expect(formatNumberToCompactString(1_000, 2)).toBe("1K") }) }) describe("bigIntMax", () => { it("returns the maximum of positive bigint values", () => { expect(bigIntMax(1n, 2n, 3n)).toBe(3n) }) it("returns the maximum of negative bigint values", () => { expect(bigIntMax(-10n, -5n, -20n)).toBe(-5n) }) it("returns the only element if array has one bigint", () => { expect(bigIntMax(42n)).toBe(42n) }) it("works with a mix of positive and negative bigints", () => { expect(bigIntMax(-100n, 0n, 50n, -10n)).toBe(50n) }) it("throws an error if called with no arguments", () => { expect(() => bigIntMax()).toThrow() }) it("returns the correct value when all values are equal", () => { expect(bigIntMax(5n, 5n, 5n)).toBe(5n) }) }) describe("normalizePrecision", () => { it("reduces precision correctly (scale down)", () => { const result = normalizePrecision(1234500n, 6, 3) expect(result).toBe(1234n) }) it("increases precision correctly (scale up)", () => { const result = normalizePrecision(1234n, 3, 6) expect(result).toBe(1234000n) }) it("returns the same value when precision is equal", () => { const result = normalizePrecision(987654321n, 5, 5) expect(result).toBe(987654321n) }) it("handles zero value correctly", () => { const result = normalizePrecision(0n, 4, 8) expect(result).toBe(0n) }) it("handles large numbers without precision loss", () => { const value = 123456789012345678901234567890n const result = normalizePrecision(value, 18, 20) expect(result).toBe(value * 100n) }) })