import { describe, expect, it } from "vitest";
import { formatPercentDisplay, roundHalfUp } from "@/lib/math";

describe("roundHalfUp", () => {
  it("0.105×2 → 0.21（不是 0.20）", () => {
    expect(roundHalfUp(0.105 * 2, 2)).toBe(0.21);
  });

  it("32.005 → 32.01", () => {
    expect(roundHalfUp(32.005, 2)).toBe(32.01);
  });

  it("负数边界", () => {
    expect(roundHalfUp(-1.005, 2)).toBe(-1.0);
    expect(roundHalfUp(-1.006, 2)).toBe(-1.01);
  });

  it("整数精度", () => {
    expect(roundHalfUp(100, 2)).toBe(100);
    expect(roundHalfUp(100.004, 2)).toBe(100);
  });
});

describe("formatPercentDisplay", () => {
  it("支持 0.01% 展示", () => {
    expect(formatPercentDisplay(0.01)).toBe("0.01%");
    expect(formatPercentDisplay(10)).toBe("10%");
    expect(formatPercentDisplay(10.5)).toBe("10.5%");
  });
});
