import { describe, expect, test } from "vitest"; import { compareRateValues, normalizeFractionRateDisplay, normalizeRateDisplay, parseRateLowerBound } from "../src/shared/rate-normalizer"; describe("rate-normalizer", () => { test("normalizes compact ranges", () => { expect(normalizeRateDisplay("0.5%-1%")).toBe("0.5% - 1%"); }); test("normalizes ranges with missing percent on the lower bound", () => { expect(normalizeRateDisplay("0.02 - 0.1%")).toBe("0.02% - 0.1%"); }); test("parses the lower bound of a range", () => { expect(parseRateLowerBound("0.02% - 0.1%")).toBe(0.02); }); test("treats less-than values as smaller than the boundary range", () => { expect(compareRateValues("<0.02%", "0.02% - 0.1%")).toBeLessThan(0); }); test("orders missing values after real values", () => { expect(compareRateValues(null, "0.02% - 0.1%")).toBeGreaterThan(0); }); test("normalizes fraction rate values into percentage display", () => { expect(normalizeFractionRateDisplay("0.0002")).toBe("0.02%"); expect(normalizeFractionRateDisplay("0.0044")).toBe("0.44%"); expect(normalizeFractionRateDisplay("0")).toBe("0%"); }); });