import { describe, expect, it } from 'vitest'; import { aggregateQuantities } from '../src/core/quantity-total'; import type { Quantity } from '../src/core/rebar/quantity'; /** A 재료표 with one 강종·직경 line; only the fields the aggregate reads are filled. */ function quantity(grade: number, size: string, count: number, totalM: number, kg: number, extra: Partial = {}): Quantity { return { groups: [{ grade, kg, diameters: [{ size, dMm: 19, lines: [{ count } as never], totalM, kg }] }], couplers: [], missing: [], kg, wastePercent: 0, kgWithWaste: kg, ton: kg / 1000, ...extra, }; } describe('aggregateQuantities (교량 전체 집계)', () => { it('sums the same 강종·직경 over the piers', () => { const total = aggregateQuantities([quantity(400, 'H19', 10, 100, 225), quantity(400, 'H19', 5, 50, 112.5)]); expect(total.rows).toEqual([{ grade: 400, size: 'H19', count: 15, totalM: 150, kg: 337.5 }]); expect(total.kg).toBe(337.5); }); it('keeps different 강종 and 직경 apart and orders them by 강종 then 직경', () => { const total = aggregateQuantities([quantity(500, 'S19', 4, 40, 90), quantity(400, 'H25', 2, 20, 50), quantity(400, 'H19', 1, 10, 22.5)]); expect(total.rows.map((r) => `${r.grade}|${r.size}`)).toEqual(['400|H19', '400|H25', '500|S19']); expect(total.gradeKg).toEqual([{ grade: 400, kg: 72.5 }, { grade: 500, kg: 90 }]); }); it('adds the 할증 total and the couplers across the piers', () => { const total = aggregateQuantities([ { ...quantity(400, 'H19', 1, 1, 100, { kgWithWaste: 110, couplers: [{ name: '커플러 H19', count: 3 }] }) }, { ...quantity(400, 'H19', 1, 1, 200, { kgWithWaste: 220, couplers: [{ name: '커플러 H19', count: 2 }] }) }, ]); expect(total.kgWithWaste).toBe(330); expect(total.ton).toBeCloseTo(0.33, 6); expect(total.couplers).toEqual([{ name: '커플러 H19', count: 5 }]); }); });