package main import "testing" // TestAxisMap checks centering when content fits and clamped scrolling when it // does not. func TestAxisMap(t *testing.T) { cases := []struct { name string pane, content, focus int wantBlank, wantScroll int }{ {"fits centered", 100, 40, 0, 30, 0}, {"exact fit", 40, 40, 0, 0, 0}, {"scroll centered on focus", 40, 100, 50, 0, 30}, {"scroll clamped low", 40, 100, 0, 0, 0}, {"scroll clamped high", 40, 100, 999, 0, 60}, } for _, c := range cases { blank, scroll := axisMap(c.pane, c.content, c.focus) if blank != c.wantBlank || scroll != c.wantScroll { t.Errorf("%s: axisMap(%d,%d,%d) = (%d,%d), want (%d,%d)", c.name, c.pane, c.content, c.focus, blank, scroll, c.wantBlank, c.wantScroll) } } } // TestPtToCell checks the point->cell mapping and that moving a point by one // stepPt lands exactly one cell away (the property the cursor/stamp nudges // rely on). func TestPtToCell(t *testing.T) { // Page 600x800 pt rendered to a 120x80 px image (scaleX=0.2, scaleY=0.1), // fitting within the pane (no scroll), centered with a 4-cell/2-px margin. v := &view{ cols: 128, rows: 41, scaleX: 0.2, scaleY: 0.1, blankX: 4, blankY: 2, scrollX: 0, scrollY: 0, pageH: 800, } // Bottom-left of the page maps to the bottom-left of the image area. col, row := v.ptToCell(0, 0) if col != 4 || row != 41 { t.Errorf("ptToCell(0,0) = (%d,%d), want (4,41)", col, row) } // One horizontal step moves exactly one column; one vertical step one row. sx, sy := v.stepPt() x, y := 300.0, 400.0 c0, r0 := v.ptToCell(x, y) c1, _ := v.ptToCell(x+sx, y) if c1-c0 != 1 { t.Errorf("one stepPt in x moved %d cols, want 1", c1-c0) } _, r1 := v.ptToCell(x, y+sy) if r0-r1 != 1 { // +y is up, which is a smaller row number t.Errorf("one stepPt in y moved %d rows, want 1", r0-r1) } }