import { describe, expect, it } from 'vitest'; import { allocateProcessingCostByWeight } from '../src/services/processingDemandSheetService'; describe('allocateProcessingCostByWeight (加工分摊)', () => { it('keeps total = material cost with tail on last order', () => { const { allocations, unitCost } = allocateProcessingCostByWeight(100, [ { orderCode: 'A', inspectedQty: 1 }, { orderCode: 'B', inspectedQty: 1 }, { orderCode: 'C', inspectedQty: 1 }, ]); expect(unitCost).toBeCloseTo(33.33, 2); const sum = allocations.reduce((s, a) => s + a.amount, 0); expect(sum).toBe(100); }); });