72 lines
2.1 KiB
Go
72 lines
2.1 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{WidthMM: 80, HeightMM: 80, BleedMM: 2, MarginMM: 5}
|
||
// canvas 106mm (80+2*13), cell 108, printable 280×380 → cols=2, rows=3
|
||
preview := Pack(plate, spec, 2)
|
||
if preview.Columns != 2 {
|
||
t.Fatalf("columns: got %d want 2", preview.Columns)
|
||
}
|
||
if preview.Rows != 3 {
|
||
t.Fatalf("rows: got %d want 3", preview.Rows)
|
||
}
|
||
if preview.Count != 6 {
|
||
t.Fatalf("count: got %d want 6", preview.Count)
|
||
}
|
||
if preview.FootprintWMM != 80 {
|
||
t.Fatalf("footprint width: got %v want 80", preview.FootprintWMM)
|
||
}
|
||
if preview.CanvasWidthMM != 106 {
|
||
t.Fatalf("canvas width: got %v want 106", preview.CanvasWidthMM)
|
||
}
|
||
if len(preview.Positions) != 6 {
|
||
t.Fatalf("positions: got %d want 6", 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 TestPackRectangle(t *testing.T) {
|
||
plate := model.Plate{
|
||
WidthMM: 300,
|
||
HeightMM: 400,
|
||
MarginTop: 10,
|
||
MarginRight: 10,
|
||
MarginBottom: 10,
|
||
MarginLeft: 10,
|
||
}
|
||
// 100×50 mm, trim 6 → canvas 112×62, cell 114×64, printable 280×380 → cols=2, rows=5
|
||
spec := model.ItemSpec{WidthMM: 100, HeightMM: 50, BleedMM: 0, MarginMM: 0}
|
||
preview := Pack(plate, spec, 2)
|
||
if preview.Columns != 2 || preview.Rows != 5 || preview.Count != 10 {
|
||
t.Fatalf("got %d cols, %d rows, %d count; want 2, 5, 10", preview.Columns, preview.Rows, preview.Count)
|
||
}
|
||
if preview.FootprintWMM != 100 || preview.FootprintHMM != 50 {
|
||
t.Fatalf("footprint: got %.0f×%.0f want 100×50", preview.FootprintWMM, preview.FootprintHMM)
|
||
}
|
||
}
|
||
|
||
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)
|
||
}
|
||
}
|