Files
vimx/training/tests/pricing.test.ts
T
fukunee 715ddb958a Rebuild training around a modular TS app
Replace the old exercise files (challenges, maze, sandbox, etc.)
with a runnable order/inventory TypeScript app under training/
that ships with unit tests, typecheck, lint, and format scripts.

Merge the full task checklist from TRAINING.md into README.md and
drop the obsolete docs and challenge files.

Add a root .gitignore for .zed, .reasonix, and build artifacts,
untrack the previously committed local configs, and fix the root
tsconfig to point at the new training sources.
2026-09-09 23:34:48 +08:00

24 lines
721 B
TypeScript

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);
});
});