task(B0): regression tests for known bugs (red)
This commit is contained in:
@@ -0,0 +1,71 @@
|
|||||||
|
/**
|
||||||
|
* Regressions-Tests für bekannte Bugs BUG-1, BUG-1b, BUG-2.
|
||||||
|
* Diese Tests sind VOR dem jeweiligen Fix ROT (dokumentiertes Fehlverhalten)
|
||||||
|
* und müssen danach GRÜN sein.
|
||||||
|
*/
|
||||||
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import { SeatingService } from '../src/services/seatingService';
|
||||||
|
import { trimElement } from '../src/tools/modification/geometry';
|
||||||
|
import type { CADElement } from '../src/types/cad.types';
|
||||||
|
|
||||||
|
// ── Helfer (Muster aus tests/geometry.test.ts) ─────────────
|
||||||
|
function makeLine(id: string, x1: number, y1: number, x2: number, y2: number): CADElement {
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
type: 'line',
|
||||||
|
layerId: 'layer-1',
|
||||||
|
x: (x1 + x2) / 2,
|
||||||
|
y: (y1 + y2) / 2,
|
||||||
|
width: Math.abs(x2 - x1),
|
||||||
|
height: Math.abs(y2 - y1),
|
||||||
|
properties: { x1, y1, x2, y2 },
|
||||||
|
} as unknown as CADElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeCircle(id: string, cx: number, cy: number, r: number): CADElement {
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
type: 'circle',
|
||||||
|
layerId: 'layer-1',
|
||||||
|
x: cx,
|
||||||
|
y: cy,
|
||||||
|
width: r * 2,
|
||||||
|
height: r * 2,
|
||||||
|
properties: { radius: r },
|
||||||
|
} as unknown as CADElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── BUG-1: rowId-Kollision bei schnellem Erzeugen ───────────
|
||||||
|
describe('BUG-1: seating row ids', () => {
|
||||||
|
it('zwei direkt hintereinander erzeugte Reihen haben unterschiedliche rowIds', () => {
|
||||||
|
const svc = new SeatingService();
|
||||||
|
const a = svc.createSeatingRow(0, 0, 'layer-1');
|
||||||
|
const b = svc.createSeatingRow(0, 100, 'layer-1');
|
||||||
|
const ids = new Set([a[0].properties.rowId, b[0].properties.rowId]);
|
||||||
|
expect(ids.size).toBe(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── BUG-1b: Block-Reihen ohne eigene rowId ──────────────────
|
||||||
|
describe('BUG-1b: seating block row ids', () => {
|
||||||
|
it('jede Reihe eines Blocks hat eine eigene, definierte rowId', () => {
|
||||||
|
const svc = new SeatingService();
|
||||||
|
const els = svc.createSeatingBlock(0, 0, 'layer-1', { rows: 3, cols: 2 });
|
||||||
|
expect(els.length).toBe(6);
|
||||||
|
const rowIds = new Set(els.map((e) => e.properties.rowId));
|
||||||
|
expect(rowIds.size).toBe(3);
|
||||||
|
for (const rid of rowIds) expect(rid).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── BUG-2: Trim an Kreis scheitert (findIntersection nur Gerade×Gerade) ──
|
||||||
|
describe('BUG-2: trim line at circle', () => {
|
||||||
|
it('trimElement(Linie, Kreis) liefert ein Ergebnis statt null', () => {
|
||||||
|
// Linie von (0,0) nach (200,0) schneidet Kreis (Zentrum 100,0, Radius 40)
|
||||||
|
// an x=60 und x=140 → Schnitt existiert eindeutig.
|
||||||
|
const line = makeLine('l1', 0, 0, 200, 0);
|
||||||
|
const circle = makeCircle('c1', 100, 0, 40);
|
||||||
|
const result = trimElement(line, circle);
|
||||||
|
expect(result).not.toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user