import { describe, expect, it } from "vitest"; import { round2, lineTotal, shippingCost } from "../src/pricing"; import { findProduct } from "../src/catalog"; describe("pricing", () => { it("round2 保留两位小数", () => { expect(round2(1.156)).toBe(1.16); expect(round2(2.5)).toBe(2.5); }); it("lineTotal 按数量计价(未税)", () => { expect(lineTotal(findProduct("apple"), 3)).toBeCloseTo(4.5); }); it("lineTotal 满 10 件打 95 折", () => { expect(lineTotal(findProduct("apple"), 10)).toBeCloseTo(14.25); }); it("shippingCost 满 50 免运费,否则收运费", () => { expect(shippingCost(60)).toBe(0); expect(shippingCost(49.99)).toBeCloseTo(4.99); }); });