import { amountsMatchToTheCent } from "./cbe-bill.service"; describe("amountsMatchToTheCent (CBE payment amount gate)", () => { it("accepts the exact amount", () => { expect(amountsMatchToTheCent(1234.34, 1234.34)).toBe(true); }); it("rejects a cents-only difference (the 1234.89 vs 1234.34 bug)", () => { expect(amountsMatchToTheCent(1234.89, 1234.34)).toBe(false); expect(amountsMatchToTheCent(1234.35, 1234.34)).toBe(false); }); it("rejects whole-unit differences", () => { expect(amountsMatchToTheCent(1235.34, 1234.34)).toBe(false); }); it("absorbs double-precision storage noise", () => { expect(amountsMatchToTheCent(1234.34, 1234.3399999999999)).toBe(true); // classic float artifact: 0.1 + 0.2 !== 0.3 expect(amountsMatchToTheCent(0.1 + 0.2, 0.3)).toBe(true); }); });