refactor(shopping): redundanten kg-Check in consolidate() entfernt + Boundary-Test
Some checks failed
Build & Publish Docker Image / build-and-push (push) Has been cancelled
Some checks failed
Build & Publish Docker Image / build-and-push (push) Has been cancelled
Weight-Branch prueft nicht mehr doppelt auf unitFamily; stil-parity mit Volume-Branch. Boundary-Test fuer exakt 1000 g ergaenzt (15/15 Tests gruen). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -43,7 +43,7 @@ export function consolidate(rows: QuantityInUnit[]): QuantityInUnit {
|
|||||||
if (allNull) return { quantity: null, unit: firstUnit };
|
if (allNull) return { quantity: null, unit: firstUnit };
|
||||||
const grams = rows.reduce((sum, r) => {
|
const grams = rows.reduce((sum, r) => {
|
||||||
const q = r.quantity ?? 0;
|
const q = r.quantity ?? 0;
|
||||||
return sum + (unitFamily(r.unit) === 'weight' && r.unit?.toLowerCase().trim() === 'kg' ? q * 1000 : q);
|
return sum + (r.unit?.toLowerCase().trim() === 'kg' ? q * 1000 : q);
|
||||||
}, 0);
|
}, 0);
|
||||||
if (grams >= 1000) return { quantity: round2(grams / 1000), unit: 'kg' };
|
if (grams >= 1000) return { quantity: round2(grams / 1000), unit: 'kg' };
|
||||||
return { quantity: round2(grams), unit: 'g' };
|
return { quantity: round2(grams), unit: 'g' };
|
||||||
|
|||||||
@@ -44,6 +44,13 @@ describe('consolidate', () => {
|
|||||||
expect(out).toEqual({ quantity: 500, unit: 'g' });
|
expect(out).toEqual({ quantity: 500, unit: 'g' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('promoted bei exakt 1000 g (Boundary)', () => {
|
||||||
|
const out = consolidate([
|
||||||
|
{ quantity: 1000, unit: 'g' }
|
||||||
|
]);
|
||||||
|
expect(out).toEqual({ quantity: 1, unit: 'kg' });
|
||||||
|
});
|
||||||
|
|
||||||
it('kombiniert ml + l analog (400 ml + 0,5 l → 900 ml)', () => {
|
it('kombiniert ml + l analog (400 ml + 0,5 l → 900 ml)', () => {
|
||||||
const out = consolidate([
|
const out = consolidate([
|
||||||
{ quantity: 400, unit: 'ml' },
|
{ quantity: 400, unit: 'ml' },
|
||||||
|
|||||||
Reference in New Issue
Block a user