2026-05-26 17:11:09 +02:00

49 lines
1.3 KiB
Go

package layout
import (
"testing"
"printer.backend/internal/model"
)
func TestPack(t *testing.T) {
plate := model.Plate{
WidthMM: 300,
HeightMM: 400,
MarginTop: 10,
MarginRight: 10,
MarginBottom: 10,
MarginLeft: 10,
}
spec := model.ItemSpec{SizeMM: 80, BleedMM: 2, MarginMM: 5}
// viewport 80mm, cell = 80+2 = 82, printable 280x380 -> cols=3, rows=4 -> 12
preview := Pack(plate, spec, 2)
if preview.Columns != 3 {
t.Fatalf("columns: got %d want 3", preview.Columns)
}
if preview.Rows != 4 {
t.Fatalf("rows: got %d want 4", preview.Rows)
}
if preview.Count != 12 {
t.Fatalf("count: got %d want 12", preview.Count)
}
if preview.FootprintWMM != 80 {
t.Fatalf("footprint width: got %v want 80", preview.FootprintWMM)
}
if len(preview.Positions) != 12 {
t.Fatalf("positions: got %d want 12", len(preview.Positions))
}
if preview.Positions[0].XMM != 10 || preview.Positions[0].YMM != 10 {
t.Fatalf("first position: got (%v,%v)", preview.Positions[0].XMM, preview.Positions[0].YMM)
}
}
func TestPackZeroCell(t *testing.T) {
plate := model.Plate{WidthMM: 10, HeightMM: 10}
spec := model.ItemSpec{SizeMM: 100}
preview := Pack(plate, spec, 0)
if preview.Count != 0 {
t.Fatalf("expected 0 items, got %d", preview.Count)
}
}